Repository navigation
fix(tui): stop a session switch from leaving the old session on screen - #797
Merged
Merged
Conversation
A successful `switch_session` could leave the previous session's display in place, and a superseded one could replace the transcript with a conversation the app is not showing: - A failed `get_messages` left the old transcript on screen under the new session's name while a prompt typed there went to the new session. The switch has already happened on the wire, so the transcript is now cleared and the failure is named instead of being shown as this session's history. - A failed `get_state` (a separate call) left `state.session_id` on the session just left, so that session's saved draft was restored into the new session's input box and later refreshes addressed the wrong session. The identity now follows the switch on its own. - The cleared chat kept the previous session's scroll offset (and its `auto_scroll` off), so the new conversation opened mid-transcript and never followed its own output. - Two picks can overlap (the sessions menu stays open until the first result lands) and the agent has no notion of a "current" session: whichever `switch_session` RPC lands last wins on the wire. Results are now matched against the newest request, so a stale one is dropped and the client is pointed back at the session the app actually shows. - A frame still in flight from the session just left could append to the new transcript (`text_chunk`) or overwrite its last reply (`agent_end`). Broadcast events are session-stamped, so foreign ones are ignored — generalizing the guard that only covered `compaction_*`. - The window title kept the previous session's name; the name now follows the `get_state` snapshot.
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.
What
ctrl-r→ pick a session could leave the previous session on screen. Auditing the switch path (spawn_switch_flow→apply_refresh_state→restore_session_input→apply_messages→hide_overlay) turned up five ways it happens:get_messagesfailed →apply_messagesearly-returned without clearing/statusaddress the wrong sessionget_statefailed (a separate call) →state.session_idstayed on the session just leftclear_messageskept the previousviewport_top/auto_scrolltext_chunkappends,agent_endoverwrites)Plus: the window title kept the previous session's name (
apply_refresh_statenever readsession_name).Fix
UiCmd::SessionSwitchednow carries the request'stargetand whether the switch really happened (RPC ok, notcancelled, client bound to the target). The app keeps the newest request (latest_session_switch); a result that is not the newest — or that arrives after another lifecycle flow (/new, a fork) moved the app — is dropped, and the client is re-pointed at the session the app actually shows. A declined switch keeps the transcript, because nothing changed on the wire.get_stateno longer leaves drafts/refreshes keyed to the session just left.ChatArea::clear_messagesre-anchors to the tail (the old scroll position referred to lines that no longer exist).handle_agent_eventignores session-stamped events from another session (generalizing the guard that only coveredcompaction_*).apply_refresh_stateadopts the snapshot'ssession_nameand refreshes the terminal title.Tests
Nine new tests in
tui/src/app.rscover each path (failedget_messages, failedget_state, view re-anchoring, both superseded orderings, takeover by/new, declined switch, foreign events, title name).cargo test -p future-tui2030 passed;cargo fmt --checkandcargo clippy --all-targets -D warningsclean. (crash::tests::dropping_the_guard_restores_the_hook_that_was_installed_beforeflaked once under parallel load, passes in isolation and on re-run — pre-existing panic-hook global state, untouched here.)