Repository navigation
fix(flow-chat): repair turns truncated after switching back from a peer device - #3690
Merged
bobleer merged 3 commits intoNov 2, 2026
Merged
Conversation
…ce switch A turn kept running locally while the window rendered a peer device. Surface routing dropped its later chunks and terminal event, and the journal tail could not serve the gap, so the return path fell back to the persisted record. The stream still believed the turn was executing, and the shape-sensitive progress comparison then refused the complete record because live items carry attempt metadata and coalesced newlines that the persisted record does not. The turn stayed truncated for good. A host read that reports a terminal record for a turn the host is not executing now hands that turn to the persisted record, and its content guard compares painted rounds, tools and text without depending on attempt keys, newline coalescing or segment boundaries.
…read A remote controller can start the next turn while the window renders another device. Its live events then change the session during the restore read, and the store skipped the whole persisted merge, so the missed tail of the previous, already settled turn was never repaired. That race only concerns the turn the host is executing; settled turns are still adopted.
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
A local turn that is still running while the Desktop window renders a peer device (Remote Control → another client) can stay truncated after switching back to the local device. Reproduced on 1.0.8;
mainhad the same code path.Root cause
Traced with the reporter's own webview log and persisted session data:
DialogTurnCompleted, and theSessionHistoryChangedfence.restore_session_view. The host reportsIdle, so no runtime projection is offered.SessionStreamnever saw the terminal event, so it still owns the turn as executing.persistedReadMayReplaceTurntherefore fell through toisRunningSnapshotForwardProgress.(type, attemptId, ordinal)and requires a literal prefix. Live items carry attempt metadata the persisted record lacks, and live text coalesces newlines. So the complete record looked lossy and the truncated turn stayed on screen for good.Fix
Processing, so stale local stream ownership no longer vetoes it. The stream hands that turn to the persisted record viaadoptHostSettledTurn.settledReadCoversProjectedTurn). It still refuses a read that is missing a painted round, tool, tool result or text. It ignores attempt metadata, newline or whitespace coalescing, segment boundaries, and superseded attempts.reconcileSettledDialogTurn, and disk hydrate. Hydrate uses the new path only when the restored session reports a host state.docs/architecture/session-projection.mddocuments the ownership handoff.Tests
FlowChatStore.test.ts: new cases for a missed-terminal turn:pnpm --dir src/web-ui exec vitest run src/flow_chat/store src/flow_chat/session-stream src/flow_chat/services/flow-chat-manager src/infrastructure/peer-device: 868 passed. The 3 failures are inPendingQueueModule.test.tsand fail the same way onmain, because Node has nolocalStoragethere.pnpm run type-check:webpasses.Remote scenarios
RelaySessionHistory.