fix(coding-agent): single-source the interactive queue state - #1842
Merged
Conversation
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 20ed314. Configure here.
…failed edits - rebindCurrentSession: re-sync sessionActions after resubscribing; a session_action_update fired in the unsubscribed gap was lost forever. - browseQueueSelection: block browsing while a queue move RPC is pending, matching the pendingQueueEdit guard, so the move response cannot reselect the original item under newly browsed editor text. - moveQueueSelection: when the applied move's session_action_update has not landed yet (sessionActions reference unchanged), mirror the swap locally so the moved selection is not dropped against the pre-move snapshot; reconcile the selection in the error path. - applyQueueSelection: reconcile the selection after the pending-edit flag clears, so a rejected/failed edit no longer leaves Enter targeting a row that was removed while events were suppressed.
xeophon
approved these changes
Aug 29, 2026
PR9000
pushed a commit
to PR9000/prime-agent
that referenced
this pull request
Sep 1, 2026
…tellect-ai#1842) * fix(coding-agent): single-source the interactive queue state * fix(coding-agent): close queue-state races around rebind, moves, and failed edits - rebindCurrentSession: re-sync sessionActions after resubscribing; a session_action_update fired in the unsubscribed gap was lost forever. - browseQueueSelection: block browsing while a queue move RPC is pending, matching the pendingQueueEdit guard, so the move response cannot reselect the original item under newly browsed editor text. - moveQueueSelection: when the applied move's session_action_update has not landed yet (sessionActions reference unchanged), mirror the swap locally so the moved selection is not dropped against the pre-move snapshot; reconcile the selection in the error path. - applyQueueSelection: reconcile the selection after the pending-edit flag clears, so a rejected/failed edit no longer leaves Enter targeting a row that was removed while events were suppressed.
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 interactive queue browse/edit/move behavior and session resync timing; fixes a duplicate-text mis-edit bug but regressions in queue UX would be user-visible during streaming sessions.
Overview
The interactive TUI no longer keeps a separate
connectionQueuemirror or callsgetQueueon refresh. Queued steering/follow-up messages are read only fromconnectionState.sessionActionsviagetConnectionQueue(), and the pending-queue UI updates from that snapshot on session events and resyncs (including a post-subscribegetStatere-sync after rebind).Queue browsing/editing now targets the exact (lane, index, text) tuple held in
QueueSelection, instead ofindexOftext matching.QueueSelection.sync()is replaced byrefreshAt(), which resets browse mode when that tuple is no longer at the expected index—fixing mistaken edits when duplicate text appeared in the queue.pendingQueueMoveblocks browse/refresh races while a reorder is in flight;refreshQueueSelectionFromStatekeeps the editor aligned whensession_action_updatearrives.Move/replace/delete still go through the daemon
mutateQueuedMessagechain, with slimmer local patching when the response beats the queue event. Tests and harnesses are updated toconnectionState.sessionActionsand add regressions for event ordering, duplicate text, and stale selection after failed moves/edits.Reviewed by Cursor Bugbot for commit 6e277a8. Bugbot is set up for automated code reviews on this repo. Configure here.
Note
Single-source interactive queue state in
InteractiveModeand fix duplicate-prompt targetingconnectionQueuemirror frominteractive.InteractiveModeand reads queued messages directly fromconnectionState.sessionActionsviagetConnectionQueue(), eliminating desynchronization between the local copy and server stateQueueSelection.sync()withrefreshAt(queue, lane, index, expectedText)andrefreshQueueSelectionFromState(), so selection is reconciled by exact (lane, index, text) tuple and dropped on any mismatch instead of retargeting by textmoveQueueSelectionandapplyQueueSelectionto target the exact selected tuple even when duplicate texts exist, restore editor text on mutation failure, and add apendingQueueMoveflag that blocks browsing during in-flight movesQueueSelection.sync(queue)is removed and replaced byrefreshAt; any out-of-tree callers relying onsyncor theconnectionQueuefield will break. The old text-retargeting selection behavior is gone — selections now drop on mismatch rather than silently retargetingMacroscope summarized 6e277a8.
Linear: ENG-5649