Repository navigation
fix(desktop): treat an agent-queued run as alive, not a model failure - #794
Merged
Merged
Conversation
A prompt sent while the session still streams (e.g. the retry/continue
affordance on an interrupted run) is accepted by the Agent with
enqueue-if-busy and sits in its queuedRuns list until the active run
finishes. Two desktop paths misread that liveness as failure:
- attach-time RunGone: a queued run has no execution epoch yet, so the
collector's attach is refused with "not the active run".
reconcile_run_gone then settled the row failed
("run no longer active") — the run the Agent was actually about to
execute. It now checks queuedRuns first: a queued run stays running,
its durable user entry is persisted into the run-event log, and the
session observer takes over the projection when the run starts.
- the active-run watchdog: a queued run had no marker at all, so after
ten minutes it was orphan-settled as stream_interrupted. queuedRuns
now counts as a liveness marker.
Two supporting fixes: the observer no longer rejects the queued run's
user_message (broadcast with an empty run id and a session idx the
session cursor may already have passed), and the [RUN_QUEUED]
termination kind classifies as run_queued instead of a user abort.
Also applies the clippy 1.97 is_none_or simplification to two
pre-existing sites the pinned toolchain now flags.
huichen
enabled auto-merge (squash)
September 23, 2026 06:40
huichen
added a commit
that referenced
this pull request
Oct 15, 2026
…#1093) 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.
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 prompt sent while the session still streams — most visibly the 重试/继续 affordance on an interrupted run, or a second message typed while a run is in flight — is accepted by the Agent with the default
enqueue_if_busypolicy and sits in itsqueuedRunslist until the active run finishes. The desktop misread that queued state as a failure twice:FailedPrecondition: run … is not the active run).reconcile_run_gonefound no marker and settled the rowfailed(stream_interrupted, "run no longer active"). The UI then showed the generic 模型服务异常 banner on a run the Agent was literally about to execute. (Observed live: agent side running for 10+ minutes while the desktop showed the failed banner.)plan_active_run_reconciliationwould orphan-settle it asstream_interruptedafterWATCHDOG_ORPHAN_SECS(600s).A third, older symptom of the same blind spot: a retry with the same run id while the original prompt pipeline still held the replica lease surfaced "an upstream collector already owns Agent run …" as the run's failure — a local client conflict, again rendered as 模型服务异常.
Fix
reconcile_run_gonechecksqueuedRunsfirst: a confirmed-queued run stays non-terminal, hands its projection to the session observer (which replays from the durable journal the moment the run starts), and the prompt pipeline returns arun_queuedtermination — not a failure — persisting the queued run's durable user entry at idx 0 so a reload shows the prompt.plan_active_run_reconciliationtreatsqueuedRunsas a liveness marker (Skipinstead of orphan-settle).user_message: it is broadcast with an empty run id and a session idx the session cursor may already have passed (the entry was accepted before newer session events). It is now cursor-agnostic and never rewinds the cursor.[RUN_QUEUED]classifies asrun_queuedinrun_error.rs(was: matchedinterrupted→ misreported as a user abort).is_none_orsimplification to two pre-existing sites the pinned toolchain flags (queries.rs,headless/mod.rs) soclippy --all-targets -D warningspasses.Behavior after the fix
The queued run renders as running (sidebar spinner + stop button — both correct: aborting a queued run removes it from the Agent's queue). When the older run finishes, the session observer projects the queued run's stream live and settles it normally. No more false 模型服务异常.
Tests
agent_prompt_queued_run_attaches_later_and_stays_running(full pipeline: attach refused → reconciled as queued → row staysrunning, user entry persisted).skips_a_run_the_agent_has_queued(watchdog planner).queued_user_entry_reanchors_a_stale_session_cursor(observer cursor).cargo test --lib: 1283 passed (1 pre-existing flakyinstance::tests::excludes_second_owner_and_releases_on_drop, passes in isolation — unrelated).cargo clippy --all-targets -- -D warningson the pinned 1.97 toolchain: clean.