Chat: switching conversation mid-turn puts the reply in the wrong conversation #1729

Closed
opened 2026-11-02 04:12:19 +00:00 by sam · 2 comments
Owner

selectSession in ui/src/chat/state.ts:251-271 does not abort the running turn. The old stream keeps writing: it sets currentSession (:537) and appends its reply to the conversation now open (:572-578). The transcript read at :264 also has no current-session check, so a slow read for an earlier conversation can overwrite the open one.

Done when: switching conversation aborts or detaches the running turn, and no write lands unless its session id is still current (the guard reloadTranscript uses at :305).

`selectSession` in `ui/src/chat/state.ts:251-271` does not abort the running turn. The old stream keeps writing: it sets `currentSession` (`:537`) and appends its reply to the conversation now open (`:572-578`). The transcript read at `:264` also has no current-session check, so a slow read for an earlier conversation can overwrite the open one. Done when: switching conversation aborts or detaches the running turn, and no write lands unless its session id is still current (the guard `reloadTranscript` uses at `:305`).
sam added the highbug labels 2026-11-02 04:12:19 +00:00
sam self-assigned this 2026-11-02 04:12:19 +00:00
Author
Owner

Fixed in bd1acdd0 and pushed. selectSession bumps a module-level sessionEpoch and calls abortActiveTurn() before switching, so the old stream is aborted; its readTranscript result is applied only when isCurrentSession(id) still holds. sendMessage captures the epoch at turn start and checks it on every stream read — a detached turn cancels the reader and returns without writing messages/streamingTurn/currentSession, and the catch path returns early when detached. The finally only clears isSending when the turn still owns activeController, so an aborted turn can't unlock the composer while a new turn runs in the switched-to conversation. Verified: task check exited 0 on the committed tree.

Fixed in bd1acdd0 and pushed. selectSession bumps a module-level sessionEpoch and calls abortActiveTurn() before switching, so the old stream is aborted; its readTranscript result is applied only when isCurrentSession(id) still holds. sendMessage captures the epoch at turn start and checks it on every stream read — a detached turn cancels the reader and returns without writing messages/streamingTurn/currentSession, and the catch path returns early when detached. The finally only clears isSending when the turn still owns activeController, so an aborted turn can't unlock the composer while a new turn runs in the switched-to conversation. Verified: task check exited 0 on the committed tree.
Author
Owner

Fixed in bd1acdd0 and pushed to main. Gate: task check exited 0 on the committed tree.

Fixed in bd1acdd0 and pushed to main. Gate: task check exited 0 on the committed tree.
sam closed this issue 2026-11-07 06:09:24 +00:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: sam/archie#1729