Skip to content

fix(desktop): treat an agent-queued run as alive, not a model failure - #794

Merged
huichen merged 1 commit into
mainfrom
fix/queued-run-status
Sep 23, 2026
Merged

huichen merged 1 commit into
mainfrom
fix/queued-run-status

Conversation

@huichen

@huichen huichen commented Sep 23, 2026

Copy link
Copy Markdown
Collaborator

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_busy policy and sits in its queuedRuns list until the active run finishes. The desktop misread that queued state as a failure twice:

  1. Attach-time RunGone — a queued run has no execution epoch yet, so the collector's attach is refused (FailedPrecondition: run … is not the active run). reconcile_run_gone found no marker and settled the row failed (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.)
  2. Watchdog orphan-settle — a queued run has no Agent marker at all, so plan_active_run_reconciliation would orphan-settle it as stream_interrupted after WATCHDOG_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_gone checks queuedRuns first: 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 a run_queued termination — not a failure — persisting the queued run's durable user entry at idx 0 so a reload shows the prompt.
  • plan_active_run_reconciliation treats queuedRuns as a liveness marker (Skip instead of orphan-settle).
  • The observer no longer rejects the queued run's 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 as run_queued in run_error.rs (was: matched interrupted → misreported as a user abort).
  • Drive-by: apply clippy 1.97's is_none_or simplification to two pre-existing sites the pinned toolchain flags (queries.rs, headless/mod.rs) so clippy --all-targets -D warnings passes.

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

  • New: agent_prompt_queued_run_attaches_later_and_stays_running (full pipeline: attach refused → reconciled as queued → row stays running, user entry persisted).
  • New: skips_a_run_the_agent_has_queued (watchdog planner).
  • New: queued_user_entry_reanchors_a_stale_session_cursor (observer cursor).
  • Full cargo test --lib: 1283 passed (1 pre-existing flaky instance::tests::excludes_second_owner_and_releases_on_drop, passes in isolation — unrelated).
  • cargo clippy --all-targets -- -D warnings on the pinned 1.97 toolchain: clean.

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
huichen enabled auto-merge (squash) September 23, 2026 06:40
@huichen
huichen merged commit 5cebe31 into main Sep 23, 2026
12 checks passed
@huichen
huichen deleted the fix/queued-run-status branch September 23, 2026 06:48
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.
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