Repository navigation
fix(desktop): keep a run the Agent queued alive instead of failing it - #1093
Merged
Merged
Conversation
Sending a prompt while the session is already executing a run is accepted by the Agent and queued behind it (`queue_position` ack). The desktop's prompt invoke then returns as soon as the ack lands, before any event exists, with `complete: false` and the `run_queued` termination kind. The send pipeline read that as a truncated stream: it CASed the run `failed` with "[RESPONSE_UNCONFIRMED] response did not complete" and repainted the bubble as "回复意外结束,原因暂未确认". Two consequences, both live for a prompt sent while another client's run (CLI, another agent, a task) still streamed in the same session: - The row is terminal, so nothing corrects it when the Agent does answer the queued run — `update_run_status_if_active` is a compare-and-set from a non-terminal state, and the observer settles through the same writer. The real reply then reloads bound to that failed row. - The user's answer arrived while the view showed it had failed. The backend already treats this kind as liveness (#794: `run_queued` skips the failure settle and hands the projection to the session observer), so the pipeline now does the same and leaves the streaming bubble in place for the re-attach path. Because that handoff happens *after* `activeRunId` is already set, re-attach can no longer be gated on arming alone: it arms as soon as the run is in flight and refuses each write while the send lock is held, so the queued run's first push paints it without a re-render having to re-arm anything. The queued bubble also drops the optimistic "thinking…" hint: waiting for a queue slot is not this run's work.
huichen
enabled auto-merge (squash)
October 15, 2026 10:02
huichen
added a commit
that referenced
this pull request
Oct 15, 2026
…ed it (#1097) Nothing drives a terminal run. The send pipeline settles its own row and never reads the Agent again, so a row it wrote while the Agent was still working on that run stays wrong forever — and the durable writers cannot correct it either: `update_run_status_if_active` and the observer's settle are compare-and-sets **from a non-terminal state**, so once the row is terminal the Agent's own `completed` marker never reaches it. The next reload then binds the real assistant entry to that stale row. That is the shape of the bug fixed on the frontend in #1093: an accepted-but-queued prompt returns its invoke response at the ack, so the row was marked `failed` ("[RESPONSE_UNCONFIRMED] response did not complete") while the Agent queued that very run and answered it twenty minutes later. #1093 stops new rows from being written that way; the rows already written are only repair-able from the outside. The runtime watchdog now does that. Alongside the non-terminal pass, it re-reads the Agent ledger for the rows the GUI settled **without** the Agent's evidence — `failed`, or the startup convergence's `cancelled`+`interrupted` guess — within a recent window, and then: - the ledger still owns the run (executing it, or holding it in `queuedRuns`): CAS the row back to `running` and ensure the session observer, so the existing re-attach path resumes and the active-run watchdog settles it later from the Agent's own terminal marker; - the ledger completed it: settle `completed`, clearing the failure copy, with the Agent's own duration anchored on the row's start time; - anything else: leave the row. A row is never asserted `completed` without the Agent's positive evidence, and this pass never converts one failure flavour into another — nor into a user stop the user never asked for. A user abort (`error_type='abort_requested'`) and a `completed` row are not even candidates. A row confirmed consistent is remembered for the life of the process, so a candidate costs at most one ledger read per launch; a non-answer (the Agent could not resolve the session) is deliberately not remembered, so it is retried. Nothing about the schema or the wire contract changes: the two new writers are compare-and-set over the same predicate the candidate query uses, and the caller owns the UI notifications.
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
A prompt sent while the session is already executing a run is accepted by the Agent and queued behind it (
queue_positionack). The desktop'sagent_promptinvoke then returns as soon as the ack lands — before a single event exists — withcomplete: falseand therun_queuedtermination kind (#794 added that kind on the Rust side).The send pipeline read
complete: falseas a truncated stream: it CASed the runfailedwith[RESPONSE_UNCONFIRMED] response did not completeand repainted the bubble as回复意外结束,原因暂未确认. The Agent went on to answer the queued run, which the UI never showed.That is not just a transient wrong banner. The row is terminal, and
update_run_status_if_active/ the observer settle through a compare-and-set from a non-terminal state, so nothing corrects the row when the real reply lands: on the next reload the genuine assistant entry — which carries that canonical run id — is bound to the failed row (applyRunMetadata) and rendered as a failure forever.Trigger: any prompt sent from the desktop while the session's run was started elsewhere (CLI, another agent, a task) and is still streaming.
How
sendPipelinebranches onisQueuedRunKindbefore the interrupted-stream finalization: no failed status write, no failure presentation, and the streaming bubble is left in place for the re-attach path (matching what the backend already does for this kind). The invocation still reports as delivered, so the composer keeps no draft.activeRunIdis already set, so no dependency changes at the moment it matters — arming can no longer be gated on the send lock alone. The hook now arms as soon as the run is in flight and refuses each write while the lock is held (isLive), so the queued run's first push paints it with no re-render needed to re-arm. While a local send owns the view the extra listener/inspection is suppressed (including the terminal-push reload).ResponseTerminationKindnow mirrors the backend's set instead of two of its values.Tests
desktop/src/features/agent/sendPipeline.test.ts— newrunSendPipeline queued behind a running reply: the queued ack leaves the run un-settled and the bubble streaming with no failure fields (fails before the fix, producing exactlyerrorMessage: "[RESPONSE_UNCONFIRMED] response did not complete"), plus the no-final-render handoff.useRunReattach.events.test.tsx— new case pinning that the preview stays armed through a local send and its write gate opens when the lock drops (fails against the previous hook).Checked in the worktree:
tsc --noEmit,eslinton the touched files, and the full desktop vitest suite (4148 passed).