Skip to content

fix(desktop): keep a run the Agent queued alive instead of failing it - #1093

Merged
huichen merged 2 commits into
mainfrom
fix/desktop-queued-run-not-failure
Oct 15, 2026
Merged

huichen merged 2 commits into
mainfrom
fix/desktop-queued-run-not-failure

Conversation

@huichen

@huichen huichen commented Oct 15, 2026

Copy link
Copy Markdown
Collaborator

What

A prompt sent while the session is already executing a run is accepted by the Agent and queued behind it (queue_position ack). The desktop's agent_prompt invoke then returns as soon as the ack lands — before a single event exists — with complete: false and the run_queued termination kind (#794 added that kind on the Rust side).

The send pipeline read complete: false as a truncated stream: it CASed the run failed with [RESPONSE_UNCONFIRMED] response did not complete and 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

  • sendPipeline branches on isQueuedRunKind before 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.
  • Re-attach must therefore be armed when a send hands its run over. That handoff happens after activeRunId is 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).
  • The queued bubble drops the optimistic "thinking…" hint: waiting for a queue slot is not this run's work.
  • ResponseTerminationKind now mirrors the backend's set instead of two of its values.

Tests

desktop/src/features/agent/sendPipeline.test.ts — new runSendPipeline 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 exactly errorMessage: "[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, eslint on the touched files, and the full desktop vitest suite (4148 passed).

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
huichen enabled auto-merge (squash) October 15, 2026 10:02
@huichen
huichen merged commit 742a28d into main Oct 15, 2026
13 checks passed
@huichen
huichen deleted the fix/desktop-queued-run-not-failure branch October 15, 2026 10:08
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant