Skip to content

fix(cli): re-hydrate PTY history when the terminal view is missing it - #129

Merged
edwin-zvs merged 1 commit into
mainfrom
fix-no-pty-history
May 22, 2026
Merged

edwin-zvs merged 1 commit into
mainfrom
fix-no-pty-history

Conversation

@edwin-zvs

Copy link
Copy Markdown
Contributor

Problem

Switching to a session sometimes showed `(no PTY history yet — interact to populate)` even though the session had history. Pressing any key made it appear — because a live PTY event lazily recreates the history entry (`histories.entry().or_default()`), so the entry had been genuinely absent until then.

Root cause

The history entry could go missing after a switch and never get refetched:

  1. Trigger too narrow. Hydration only fired while the transcript was stale (`transcript_session != selected`). Once the transcript hydrated, it never re-fired. So if the history entry was later dropped — e.g. a `SessionEvent::Reset` removes it but leaves `transcript_session` unchanged — the Terminal view stayed stuck on the placeholder.
  2. `needs_history` gated on `has_pty`, read at request-build time. A reconnecting adapter is transiently `has_pty == false`, so the PTY fetch could be skipped while the view was already Terminal — and then never retried (per Add in-app text selection for TUI copy #1).

Fix

Make hydration self-healing: trigger — and fetch the PTY snapshot — whenever the Terminal view has no history for the selected session, driven by the view rather than `has_pty`. The fetch always inserts an entry (empty if the replay is empty), so the condition clears after one pass — no spin loop. This also covers the `has_pty`-flip race at the first hydration, since the fetch no longer depends on `has_pty`.

No behavior change for the common path: a freshly-selected PTY session still fetches history exactly as before (view is Terminal); non-PTY/Transcript sessions never fetch.

Test

  • `terminal_view_rehydrates_after_history_dropped` — drives a real `SessionEvent::Reset` through `on_notification`, asserts the history entry is dropped, that this re-triggers hydration (the old transcript-only trigger would not have), that the request actually fetches the PTY snapshot, and that Transcript view does not spin up fetches.
  • Full suite green: 130 unit + 1 integration.

🤖 Generated with Claude Code

Switching to a session sometimes showed "(no PTY history yet — interact
to populate)" even though the session had history; pressing any key made
it appear (a live PTY event lazily recreates the entry via
`histories.entry().or_default()`).

Two gaps caused the entry to be missing and never refetched:

- The hydration trigger only fired while the *transcript* was stale
  (`transcript_session != selected`). Once the transcript was hydrated it
  never re-fired, so if the history entry was later dropped — e.g. a
  `SessionEvent::Reset` removes it, leaving `transcript_session`
  unchanged — the Terminal view stayed stuck on the placeholder.
- `needs_history` was gated on `has_pty`, read at request-build time. A
  reconnecting adapter is transiently `has_pty == false`, so the fetch
  could be skipped while the view was already Terminal, and (per above)
  never retried.

Make hydration self-healing: trigger (and fetch PTY history) whenever the
Terminal view has no history for the selected session, driven by the view
rather than `has_pty`. The fetch always inserts an entry (empty if the
replay is empty), so the re-trigger settles after one pass — no spin.

Test: `terminal_view_rehydrates_after_history_dropped` drives a real
`SessionEvent::Reset` through `on_notification` and asserts the dropped
history re-triggers hydration (and that Transcript view does not).
@edwin-zvs
edwin-zvs merged commit bcbfbb7 into main May 22, 2026
1 check passed
@edwin-zvs
edwin-zvs deleted the fix-no-pty-history branch May 22, 2026 14:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant