Repository navigation
fix(cli): re-hydrate PTY history when the terminal view is missing it - #129
Merged
Merged
Conversation
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).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:
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
🤖 Generated with Claude Code