fix(coding-agent): single-source the interactive queue state - #1705
Closed
snimu wants to merge 13 commits into
Closed
fix(coding-agent): single-source the interactive queue state#1705snimu wants to merge 13 commits into
snimu wants to merge 13 commits into
Conversation
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 2 potential issues.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 384a702. Configure here.
This was referenced Aug 27, 2026
Contributor
Author
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 was wrong
The interactive queue was stored three times: the core session's action store (authoritative), the TUI's connection snapshot, and a second TUI-local mirror that optimistically re-applied every mutation. Keeping the copies aligned required identity guards, a sync() pass, and a text-based indexOf fallback — and that fallback had a real bug: with two identical queued messages, editing the later one could silently edit the first.
The fix
Net −167 lines in the first pass; the review round added the deterministic selection re-derivation (+69/−15).
How it's verified
Reviewer independently simulated server semantics against the real prototype methods: consecutive moves, move-then-edit, rapid unawaited keypresses, duplicate-text edits, selection reset races, and external queue shrink — all correct or safely rejected. New stateful regression asserts a 2→1→0 move/edit chain lands with the right indices. tsgo/biome/focused suites green (86 tests); repo-wide check green. Two-model implement/review loop, approved on second pass.
Stacked on #1702 (test the whole stack at the leaf; merge base-first).
Note: intentionally no Linear ticket for this cleanup stack, so that check stays red.
Note
Medium Risk
Changes core interactive queue mutation and selection logic in the coding-agent TUI; correctness now depends on session action events staying aligned with mutation responses, though server-side tuple validation limits misapplication risk.
Overview
The interactive TUI no longer keeps a second queued-messages mirror or patches it optimistically after move/edit/delete. Queue reads and the pending-message UI now come from
connectionState.sessionActionsviagetConnectionQueue(), andsession_action_updatedrives display refresh and selection reconciliation.Queued-message editing targets the selected (lane, index, text) tuple on the daemon instead of re-resolving position with
indexOf, which fixes mis-edits when duplicate text appears in the queue.QueueSelection.sync()is replaced byrefreshAt, which either reaffirms that exact tuple in the canonical queue or exits browse mode and restores the stashed draft.After moves, selection is updated from the refreshed queue (with
pendingQueueMoveblocking conflicting refreshes) rather than swapping entries locally. Session rebind, resync, and switch paths droprefreshConnectionQueuefailures and callupdatePendingMessagesDisplaydirectly; tests are expanded for event-driven navigation, duplicate-text edits, and resync races.Reviewed by Cursor Bugbot for commit 20c2482. Bugbot is set up for automated code reviews on this repo. Configure here.
Note
Single-source interactive queue state from
connectionStateinInteractiveModeconnectionQueuemirror inInteractiveMode; queue reads now derive fromconnectionState.sessionActionsvia the newgetConnectionQueue()helperQueueSelection.sync()withrefreshAt(), which verifies the exact lane/index/text tuple instead of retargeting by text, so duplicate-text queued items are no longer confused during move or editmoveQueueSelectionandapplyQueueSelectionnow send mutations for the currently selected tuple and refresh selection against authoritative state; failures preserve the user's edit in the editorpendingQueueMoveflag to block selection refresh during in-flight moves;refreshQueueSelectionFromStatekeeps browse position in sync onsession_action_updateand resync eventsQueueSelection.sync()is removed — any out-of-tree callers still using it will break; in-tree tests and callers are migrated torefreshAt()Macroscope summarized 20c2482.
Linear: ENG-5649