Skip to content

fix(agent-prompt): stop reporting delivered prompts as stalled (#16095) - #16590

Merged
nwparker merged 5 commits into
mainfrom
nwparker/win-16095-prompt-stall-observation
Aug 26, 2026
Merged

nwparker merged 5 commits into
mainfrom
nwparker/win-16095-prompt-stall-observation

Conversation

@nwparker

@nwparker nwparker commented Aug 26, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 6 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​488 $\color{#cf222e}{\Huge{\mathbf{−}}}$​8 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​480
Prod 6 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​158 $\color{#cf222e}{\Huge{\mathbf{−}}}$​26 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​132

ELI5

When Orca hands a task to a background worker, it types the instructions into the agent's terminal and presses Enter, then waits to see the agent start thinking. For codex and kimi it often couldn't see that "started thinking" signal — even though the agent had the instructions and was already working on them. Orca decided the message never arrived, typed the whole thing in again, and then refused the worker's finished result because it had already written the worker off. Now Orca has more ways to tell that the message landed, waits a bit longer for those agents, and — if it still can't tell — leaves the worker alone and accepts the answer it eventually sends back.

What Changed

Verification (agent-prompt-submission-verification.ts, orca-runtime.ts)

  • A prompt counts as submitted if any of these hold: the old workingSequence (→working edge), a hook working turn that started after the baseline, or pane output after Enter when the agent was already working (the case where a →working edge is structurally impossible). An idle agent still owes a real turn start, so a swallowed Enter stays detectable.
  • AgentPromptActivity gained explicitWorkingStartedAt and outputSequence. The freshness anchor is stateStartedAt, not updatedAt, because same-state tool/prompt pings refresh updatedAt while carrying stateStartedAt over.
  • Agent-aware timeout: resolveAgentPromptEffectTimeoutMs returns 15s for codex/kimi (HOOK_OBSERVED_TURN_START_AGENTS), 5s otherwise.
  • getPtyAgent helper; createAgentPromptRenderGate now uses it instead of re-inlining launchAgent ?? foregroundAgent.

Orchestration

  • coordinator-task-dispatch.ts: an agent_prompt_stalled throw returns the new TaskDispatchResult member 'dispatched-unobserved' and logs, instead of failing the dispatch and re-pasting the preamble.
  • failWorkerStart(…, { retainCapability }) makes the capability_revoked_at write conditional; orchestration-worker-start-receipt.ts passes it only for agent_prompt_stalled. Every other cause still revokes.
  • worker-report-settlement.ts: a dispatch left failed with last_failure = 'agent_prompt_stalled' can be re-settled by the worker's own report.

Fix-round changes on top of the original two commits (commit 3a02361fd0a, 5 files, +42/−16):

  • Behaviour fix: settledByUnobservedPrompt is now computed before the duplicate short-circuit. Previously a worker that reported outcome: 'failed' landed on exactly the statuses the short-circuit reads as already-settled, so its real cause and result body were dropped and the record kept agent_prompt_stalled. A failed report now writes the real last_failure and result; a repeat report is still duplicate: true.
  • The two parallel previous-state ternaries collapsed into one previous = { status, workerState }.
  • The comment citing an unsourced "30s paired-client request budget" now cites RELAY_TO_CLIENT_REQUEST_TIMEOUT_MS (30s, src/relay/dispatcher.ts:115), which was verified to exist.
  • Test lets a late worker report settle a dispatch whose prompt was unobserved now actually calls settleWorkerReport (it previously called completeDispatch, so its name promised coverage its assertions didn't provide), and worker-start-unobserved-prompt-settlement.test.ts's third case was rewritten to pin the corrected behaviour.

No wire fields, opcodes, or error codes changed. The receipt shape is deliberately untouched: still state: 'failed', failedStage: 'dispatch_input', lastError: 'agent_prompt_stalled'.

Why

Enter is written at orca-runtime.ts:19807, before verifyAgentPromptSubmission runs at :19811. So agent_prompt_stalled can only ever mean "turn start not observed" — never "prompt not delivered". Four defects made that misreading routine:

  1. Structurally unsatisfiable for an already-working agent. workingSequence advances only on a →working edge (orca-runtime.ts:12475). A follow-up prompt to a still-spinning agent could never satisfy the predicate — guaranteed to throw after 5s, forever.
  2. The hook→verifier route was window-gated. The only path to workingSequence for these agents ran through sendSyntheticTitle, which returns early when mainWindow is null or the window is hidden/minimized (index.ts:2102-2130), and working frames are sent unforced (:2210). Hidden window, minimized window, or headless orca serve meant workingSequence never advanced.
  3. Hook state was read and discarded. getAgentPromptActivity read fresh hook status into status but hard-coded workingSequence from the lifecycle map — visible to the permission check, invisible to the verifier.
  4. The false verdict destroyed real work. The coordinator reset the task to 'ready' and re-dispatched up to 3×, re-pasting the whole preamble into a worker already executing it; worker-start revoked capability_revoked_at (worker-dispatch-outcome.ts:53), so the worker's eventual worker_done was rejected with "Dispatch … capability is revoked" — the symptom in two independent reproductions in the issue thread.

The stateStartedAt anchor is load-bearing and was proven non-vacuous: reverting it to updatedAt makes does not accept a hook row refreshed without a new working turn fail. It is pinned across same-state pings on both carriers (orca-runtime.ts:12418-12422, agent-hooks/server.ts:123-125).

Retaining the capability alone was not enough: settleWorkerReportInTransaction rejects unless dispatch and task are dispatched, so un-revoking would only have changed the worker's error from "capability is revoked" to "already settled" while still discarding the result. Both gates had to move.

One overstatement corrected from the earlier draft of this description: codex is not entirely without native title coverage — tui-agent-config/synthetic-agent-title.ts:29 notes codex emits working OSC titles but can miss the final frame, and recordAgentPromptLifecycleState is also driven by in-band OSC-9999 payloads (orca-runtime.ts:12371), not only synthetic titles. The fix is still correct; the original justification was broader than reality.

Risk & Trade-offs

Merge risk: Medium. It changes the verdict logic on every coordinator prompt dispatch, its central premise — that a stalled verdict never means an undelivered prompt — was falsified in one measured case, and it shares two orchestration expressions with community PR #16548.

Re-graded after the review round and left at Medium: the merge-order worry got both better and worse, and they cancel. Better, because sequencing is now decided (this lands first, #16548 rebases on top) and the only textual conflict is a single import header. Worse, because the review found a merge hazard git will not flag at all (below), and it fails typecheck rather than showing a marker. The blast radius of the core change — every coordinator prompt dispatch — is unchanged, and the falsified-premise case is still real and still unbounded, so nothing here argues the grade down either.

What could go wrong

  • A prompt really doesn't land, and Orca now sits there waiting instead of retrying. @flosrn measured this on macOS/arm64 with omp: on a fresh pane, Enter at pane age 5-7s leaves the preamble sitting unsubmitted in the composer. Pre-PR the coordinator re-pasted; now coordinator-task-dispatch.ts:139 keeps the dispatch active and waits. A user would see a worker that never reports and a task that never advances, with only a coordinator log line to explain it. Likelihood: real but narrow (fresh-pane race). Not self-healing — there is no upper bound on an unobserved dispatch. That bound is the owed follow-up this PR does not do.
  • A modal or nudge swallows Enter and Orca calls it delivered. observedDeliveryEvidence accepts any PTY byte from an already-working pane, so a spinner repaint within the first 50ms poll counts as evidence — including when codex's rate-limit nudge ate the Enter. Same user-visible symptom as above: silent no-op worker. Bounded in the sense that the pre-PR behaviour for this exact case was worse (guaranteed false stall, re-paste, revoked capability).
  • The 15s hook window still expires and the original receipt still appears. [Bug]: agent_prompt_stalled for codex/kimi workers — fixed 5s confirmation window vs ~20s first hook-event latency (root-cause evidence) #16095 measured codex's first hook execution at +19s and +22s after process start. Those panes still land on failed / dispatch_input / agent_prompt_stalled. Self-healing now: the worker is left alone and its late worker_done is accepted, so the receipt is cosmetic rather than destructive.
  • Between the stalled receipt and the corrective report, the worker is half-refused. Only the final worker_done was unblocked. During that gap the still-running worker's orca ask, heartbeats and mailbox routing are still rejected, and closeQuestionsForDispatch still runs. A user would see a worker whose questions vanish mid-flight but whose final answer is accepted.
  • Merge-order collision with fix(orchestration): start argv workers with bound authority #16548. Both PRs edit failWorkerStart in worker-dispatch-outcome.ts and the same call expression in orchestration-worker-start-receipt.ts. Whoever lands second and resolves the conflict carelessly can silently drop either the retainCapability option or fix(orchestration): start argv workers with bound authority #16548's widened ['starting','ready'] guard. Likely if merged blind; surfaced by a conflict marker, not by tests. Measured, and it was partly wrong. worker-dispatch-outcome.ts auto-merges cleanly and the two edits are semantically compatible — fix(orchestration): start argv workers with bound authority #16548 widens the failWorkerStart guard to ['starting','ready'], this adds the retainCapability option; different lines, orthogonal intent. The only textual conflict is the import header of orchestration-worker-start-receipt.ts. Sequencing is decided: this PR lands first, fix(orchestration): start argv workers with bound authority #16548 rebases on top.
  • New: a merge hazard git will not catch. This PR adds src/main/runtime/rpc/methods/orchestration-worker-start-outcome-classification.test.ts, which imports isUnknownWorkerStartOutcome from ./orchestration-worker-topology. fix(orchestration): start argv workers with bound authority #16548 un-exports that symbol and re-declares it locally. Because the test is a new file on this side, git produces no conflict marker — the merge is clean and then typecheck fails. Fix is on fix(orchestration): start argv workers with bound authority #16548's side and is cosmetic: drop the un-export/inline move and keep the symbol exported. Called out here so the rebase does not discover it in CI.

What a user gets in exchange

The destructive half of #16095 stops: no re-pasting the whole preamble into a worker already executing it (previously up to 3 re-dispatches), no premature capability_revoked_at write, and a worker's eventual worker_done is accepted instead of rejected with "Dispatch … capability is revoked" — the symptom reproduced twice independently in the issue thread. Follow-up prompts to an already-working codex or kimi pane, which previously could never satisfy the →working predicate and were guaranteed to throw after 5s forever, now verify. Headless orca serve and hidden/minimized windows, where the hook→verifier route was window-gated and never advanced, now have a working evidence path.

Trade-offs accepted

How to back it out

Clean revert. No schema migration, no wire fields, opcodes or error codes changed, and the receipt shape is untouched (state: 'failed', failedStage: 'dispatch_input', lastError: 'agent_prompt_stalled'). The only persisted difference is that some dispatch rows will have skipped a capability_revoked_at write or been re-settled by a late worker report; reverting restores the old behaviour for new dispatches and leaves those already-settled rows correct.

Linked Issue

Addresses #16095. Deliberately not marked Fixes — this closes the destructive half (no re-paste, no premature revocation, late reports accepted) but does not guarantee the reported receipt disappears in every environment:

Visual Proof

N/A — this is main-process prompt verification and orchestration-DB settlement with no rendered output; the only operator-visible surfaces are a coordinator log line and the last_failure / result fields on an existing receipt, neither of which is graphical.

Testing

Real output from the fix round (macOS, on the branch head):

$ pnpm tc            -> EXIT=0 (no diagnostics)

$ pnpm test src/main/runtime
> vitest run --config config/vitest.config.ts src/main/runtime
 Test Files  456 passed | 1 skipped (457)
      Tests  5365 passed | 9 skipped (5374)
   Duration  30.49s
EXIT=0

$ npx oxlint <5 changed files>  -> EXIT=0 (no findings)

Non-vacuity check for the fix-round behaviour change (stashed only worker-report-settlement.ts, kept the new test):

x lets a failure report replace the unobserved-prompt cause with the real one
AssertionError: -  "duplicate": false,  +  "duplicate": true,
      Tests  1 failed | 2 passed (3)

Review round (merge-interaction verification, no code change — branch head is still 3a02361fd0a): the #16548 overlap was checked file by file rather than assumed. worker-dispatch-outcome.ts was confirmed to auto-merge with both edits intact; orchestration-worker-start-receipt.ts conflicts only in its import header; and the isUnknownWorkerStartOutcome import in the new orchestration-worker-start-outcome-classification.test.ts was confirmed to be the one breakage that produces no conflict marker and a typecheck failure after a clean merge. Coverage that argv-only delivery leaves untouched was enumerated against tui-agent-config (kimi plus ~20 other stdin-after-start agents; a supplied params.terminal skipping both argv branches; follow-up prompts to a working pane; hidden-window/headless orca serve). Still no hardware run — no live codex/kimi worker-start reproduction, no Windows/Linux/SSH exercise, and no new measurements beyond @flosrn's already-credited macOS/arm64 omp trials.

Reviewer independently re-ran pnpm test src/main/runtime on a clean checkout of this branch (456 files / 5365 tests passed, 1 skipped) and re-confirmed all four claimed defects in the pre-fix code by reading orca-runtime.ts, index.ts and worker-dispatch-outcome.ts at the cited lines. Every new test was verified to fail against pre-fix code (explicitWorkingStartedAt/outputSequence don't exist on the old type; the coordinator test asserts a 'dispatched-unobserved' return the old function could not produce; failWorkerStart had no options parameter).

Coverage added: hook-working-after-baseline accepted; a refreshed hook row for the same turn rejected; already-working agent accepted on pane output; idle agent still requiring a real turn start; the agent-aware window; the coordinator never re-pasting a delivered preamble but still failing a genuinely undelivered one; worker-start keeping the capability with an other-cause control that still revokes; and a failed late report replacing the stalled cause.

Not verified end-to-end. No live codex/kimi worker-start reproduction was run against this branch — the fix is verified at the unit level only, and the residual-latency claims below are reasoning, not measurement. Windows, Linux and SSH were not exercised (the change is platform-neutral main-process logic).

  • I manually tested these changes locally — unit-level only; no live agent repro (see above)
  • Automated tests added/updated

Review

Credit

@flosrn (#16425) got here first and independently identified the same root cause. Two things of his are worth more than the code: his promptInjectionMode: 'argv' startup approach removes the paste-and-verify step entirely for argv-capable agents — codex (tui-agent-config.ts:89) is one of the two agents named in #16095, so for that half of the problem his fix is strictly better than widening a timing window. And his measured counter-example on macOS/arm64 with omp (one fresh pane per trial; Enter at pane age 5/6/7s never submits, preamble left sitting unsubmitted in the composer) falsifies the absolute form of this PR's central premise: a stalled verdict can accompany an undelivered preamble on a fresh pane. That is precisely the case coordinator-task-dispatch.ts:139 now swallows into a dispatch that stays active. The comment there is written as a general rule and should be read with his evidence in mind; bounding the unobserved dispatch rather than trusting it forever is a real follow-up this PR does not do. This PR remains necessary and complementary for kimi (stdin-after-start, tui-agent-config.ts:271), for follow-up prompts to an already-working pane, and for the coordinator dispatch path, which #16425 does not touch.

@antoniofulg (#16548), building on #16425 (which it explicitly preserves), reached the same diagnosis from the other side: "Orca revoked the dispatch capability even though the worker had already received its launch brief, so a valid later worker_done was rejected." That is the same conclusion as this PR's second commit, arrived at independently. It also carries a fix this PR does not have at all — binding authority before readiness monitoring, which closes a second window where a healthy worker is stripped of its capability — plus an explicit non-argv fallback ("preserve paste delivery for agents without argv startup support"), which is exactly the surface this PR improves.

Sequenced, not competing — decided in the review round: this PR lands first, then #16548 rebases on top. They are not alternatives. #16548 changes how the preamble is delivered for one agent class on one path; this changes what counts as proof it arrived on every path.

The merge interaction was measured rather than guessed:

Nothing from either PR was adopted into this diff (both were declined as complementary, see below) — the credit stands regardless: being first and being right counts.

Declined during the fix round — reviewer should know

  1. observedDeliveryEvidence accepts any PTY byte from an already-working pane (agent-prompt-submission-verification.ts:110). outputSequence is bumped by sequenceChars on every data chunk with no redraw filtering, so a spinner repaint within the first 50ms poll satisfies it — a follow-up prompt to a pane showing a modal/nudge that swallows Enter (codex's rate-limit nudge, per the issue thread) can resolve accepted: true when it did not land. Declined as a deliberate trade, not a non-issue: pre-PR that same case always produced a false agent_prompt_stalled, which re-pasted the preamble and revoked the capability — strictly worse. Stronger evidence (redraw filtering, or reusing the render gate's marker scan) has no principled threshold and the render gate runs before Enter and only for claude/codex. This is a knowing false-accept in exchange for removing a systematic false-reject.
  2. The 15s hook window was not derived from codex's 20s draftPasteReadyTimeoutMs, as [Bug]: agent_prompt_stalled for codex/kimi workers — fixed 5s confirmation window vs ~20s first hook-event latency (root-cause evidence) #16095 suggested. Declined because the two constants measure different things (composer-ready before pasting vs. hook report after Enter), kimi has no such value so the derivation would silently fall back for half the set, and 8s render gate + 20s wait + chunked paste exceeds the verified 30s RELAY_TO_CLIENT_REQUEST_TIMEOUT_MS. Consequence: see Linked Issue — the reported receipt can still appear.
  3. isAgentPromptStalledError was left in its two-step form. A proposed one-expression collapse was rejected as a correctness regression: RemoteRuntimeClientError extends Error and carries a code, so error instanceof Error ? error.message : … would short-circuit and return false for exactly the relayed-submission case that branch exists for.

Residual risks not filed as findings

  • getFreshExplicitAgentStatusForHandle picks the newest of two independently-pinned carriers (in-band OSC-9999 retained rows vs. out-of-band HTTP hook rows) and the baseline/current comparison is not carrier-scoped; a mid-window winner flip between carriers with different pinned stateStartedAt could accept a turn that started before the prompt.
  • A hook row gone stale (>30 min, AGENT_STATUS_STALE_AFTER_MS) and then refreshed by a same-state ping re-enters with an old-but-positive stateStartedAt and reads as a new turn.
  • Both of the above weaken detection (false accept) rather than destroy work.
  • Between failWorkerStart(stalled) and the corrective report the dispatch is failed, so the still-running worker's orca ask (orchestration.ts:1780), heartbeats (lifecycle-reconciliation.ts:151) and mailbox routing (orchestration.ts:1193) are still refused, and closeQuestionsForDispatch still runs. Only the final worker_done was unblocked.
  • Failure-path latency for codex/kimi triples (5s → 15s) per submission, and submissions are serialized per PTY generation (serializeAgentPromptSubmission), so a queue of prompts to a pane whose hook never reports now blocks 15s each.
  • One pinned expectation was inverted deliberately in the original commits: does not treat an unchanged newer working status as submission evidence asserted defect 1 as intended behaviour. Its real guard is kept (unchanged status alone is still not evidence) and the output case moved to a new sibling test. A second test inversion in the fix round (treats a failure report … as already settled → lets a failure report replace the unobserved-prompt cause with the real one) is called out in that commit body.

Agent skill upstream boundary

  • Not applicable.

Checklist

  • This PR is small and focused
  • I explained what changed and why (including ELI5)
  • Before/after screenshots or videos attached for UI changes, or N/A with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered — platform-neutral main-process logic; the hook route is the one that survives headless orca serve, which is the SSH/remote case
  • pnpm lint, pnpm typecheck, pnpm test pass locally (pnpm build left to CI)

Enter is written before verification runs, so `agent_prompt_stalled` can only
ever mean "turn start not observed" — never "prompt not delivered". Three of the
verifier's blind spots made that misreading routine, and the coordinator then
treated it as non-delivery and pasted the whole preamble a second time into a
worker already running it.

- Accept a hook-reported `working` recorded after the baseline. Hook rows reach
  the runtime through getAgentStatusSnapshot with no window involved, unlike the
  synthetic-title route that feeds workingSequence (suppressed for codex, absent
  for kimi, and gated on window visibility for everyone else).
- Accept pane output after Enter when the agent was already working: a
  `->working` edge is unreachable there, so the old predicate could never be
  satisfied by a follow-up prompt. An idle agent still owes a real turn start,
  so a swallowed Enter stays detectable.
- Give codex/kimi panes a longer effect window; their only turn-start proof is
  an out-of-process hook round-trip, not a TUI repaint.
- Coordinator dispatch no longer fails (and re-dispatches) a task whose prompt
  stalled; the dispatch stays active with its capability intact so the worker's
  own report settles it.
…rompt (#16095)

Follow-up to f9f973c on two review findings.

Anchor the hook signal on a turn, not a refresh: `receivedAt`/`updatedAt` bump on
every same-state hook ping, so an in-progress turn could have passed for a new
one and silently accepted every prompt to a working agent. `stateStartedAt` is
the documented per-turn identity (pinned across same-state pings), so the
verifier now reads that.

Close the worker-start path: a `dispatch_input` stall settled the dispatch as
failed *and* revoked the capability, so a worker that ran the preamble to
completion had its result rejected. Revocation is now skipped for that cause,
and a worker report can re-settle a dispatch whose `last_failure` is
`agent_prompt_stalled` — retaining the capability alone was not enough, because
settlement also gates on dispatch/task status.
…pt record (#16095)

The duplicate short-circuit ran before the unobserved-prompt branch, and for
outcome 'failed' both expected statuses are exactly the state failWorkerStart
leaves behind. A worker that reported a real failure was answered
duplicate:true, so its cause and result body were dropped and the record kept
'agent_prompt_stalled'. Evaluate settledByUnobservedPrompt first so one failure
report can re-settle that dispatch; a repeat report is still a duplicate.

Also derive the previous dispatch/worker states once instead of two parallel
ternaries, reuse getPtyAgent in createAgentPromptRenderGate, cite the real
30s relay request budget the hook window is sized against, and make the
coordinator test settle an actual worker report rather than calling
completeDispatch under a name that promised otherwise.
@nwparker

Copy link
Copy Markdown
Contributor Author

Sequencing with #16548 — land this first, then rebase #16548

A review compared this PR against @antoniofulg's #16548 (which builds on @flosrn's #16425). They are not competing fixes: #16548 changes how the preamble is delivered for one agent class on one code path; this PR changes what counts as proof it arrived on every path. Neither subsumes the other.

What #16548 alone would leave broken

promptInjectionMode is argv for codex but stdin-after-start for kimi (src/shared/tui-agent-config.ts), and #16548's argv branch only fires on the created-worktree / no-supplied-terminal paths. Everything else still calls sendTerminalAgentPrompt and still verifies:

Corroborating detail: #16548 retargets its own stall tests from codex to aider, which is that PR conceding the paste path stays live for non-argv agents.

What #16548 fixes that this PR does not

Fair side, and worth taking: binding authority before readiness monitoring. A worker whose waitForTerminal({condition:'tui-idle'}) times out fails at stage agent_readiness, where isAgentPromptStalledError is false — so this PR's retainCapability does not apply and a live worker is still stripped. Plus durable launch-token commitment, exact pre-allocated-handle matching, and cross-scope CLI resolution for SSH/WSL workers.

The merge, concretely

One textual conflict: orchestration-worker-start-receipt.ts lines 1-5, both rewriting the import header. Bodies do not collide.

One break git will not catch: this PR adds orchestration-worker-start-outcome-classification.test.ts, which imports isUnknownWorkerStartOutcome from ./orchestration-worker-topology. #16548 un-exports it and re-declares it locally — a new file, no conflict marker, fails typecheck after merge. Simplest resolution is for #16548 to drop that move; it is cosmetic and buys nothing.

worker-dispatch-outcome.ts auto-merges and is semantically compatible — #16548 widens the failWorkerStart guard to ['starting','ready'], this PR adds the retainCapability option; different lines, orthogonal intent.

Why this order

This is the smaller change (12 files vs 24) and the broader fix, and it de-risks #16548 — if the argv restructure needs reverting, #16095 stays fixed. The inverse order is actively worse: #16548 landing first masks the symptom for the loudest reporter (codex) while kimi, follow-up dispatches, and every headless user stay broken.

@nwparker

Copy link
Copy Markdown
Contributor Author

Exercised live against real running codex agents — main vs branch

Driven end-to-end through orca orchestration worker-start / orchestration dispatch --inject against a real headless Orca runtime built from source, once at origin/main (96565fe3700) and once at this branch tip (3a02361fd0a), with real codex v0.150.0 doing real API turns. Headless serve = no renderer window, which is the #16095 condition. Temporary console.error instrumentation (logging only, no verdict-logic change) was used to capture the activity snapshots below, then discarded.

One correction to this PR's own story

For codex, the plain idle dispatch was never broken. codex writes its own spinner OSC title, which the main process parses with no renderer involved:

[EX16095] lifecycle src=osc-title:"⠹ ex-a" status=working pty=...

so worker-start on a fresh worktree returned ready / input_accepted in 3.7 s on main. The synthesizeWorkingTitle: false problem only bites agents that emit no such title — i.e. kimi, which is installed on neither test machine. The body should not imply codex's cold worker-start was failing.

What actually reproduces, and is fixed

Already-working follow-up prompt — main FAILS, branch PASSES. codex pane made busy with sleep 120, then a second task injected at that pane.

main, 13.1 s, stalled:

{"ok":false,"error":{"code":"agent_prompt_stalled"}}
VERIFY-START baseline={"generation":5,"workingSequence":2,"status":"working"}
STALL        current ={"generation":5,"workingSequence":2,"status":"working"}

The prompt unambiguously landed — from the pane itself: [Pasted Content 4953 chars], Your task ID is: task_bcafff480eb4 — and 63 s later it executed it (FOLLOWUP-OK ─ Worked for 1m 03s) while Orca had already reset the task to ready.

branch, 8.1 s, "status": "dispatched", "capability_revoked_at": null. The delivery-evidence arm decided it (outputSequence 67682 → 69216), and explicitWorkingStartedAt correctly stayed pinned to the in-progress turn rather than being passed off as a new one.

Capability retention — main FAILS, branch PASSES. codex SIGSTOP'd by explicit PID, worker-start --terminal, genuine live stall, SIGCONT, worker executes, then a real worker_done with the pane's own dcap_… token.

main — revoked at stall time, late report rejected, task stuck:

{"ok":false,"error":{"code":"dispatch_capability_invalid",
 "message":"Dispatch ctx_1ff37957205f capability is revoked."}}
task_4dec35f1f998|failed

branch — retained, late report settles:

ctx_a715715e120f|...|failed|agent_prompt_stalled|   <- capability_revoked_at EMPTY
"lifecycle": {"action":"completed","taskId":"task_e55a93cb7860"}
task_e55a93cb7860|completed|{"provenance":"worker_report","outcome":"succeeded"}

Also confirmed live: timeoutMs=15000, so the codex/kimi budget is active.

Not exercised — stated, not inferred

  • The hook arm (explicitWorkingStartedAt > baseline) never decided a verdict. codex's OSC title or the output-sequence arm always won first, and kimi — the agent that arm exists for — is installed on neither machine. That arm remains unit-tested only.
  • dispatched-unobserved in coordinator-task-dispatch.ts was never reached; that legacy coordinator loop is behind a retired RPC.
  • orchestration dispatch --inject still hard-fails on a stall — this PR does not touch that catch block (orchestration.ts:1699); it still calls db.failDispatch and rethrows. The branch run above passed because verification passed, not because that path was made tolerant. Worth a follow-up.
  • Behavioural note for reviewers: a well-behaved worker still won't self-report on the branch. In the branch run codex ran orca orchestration task-list, saw its own task as failed, concluded it had no active dispatch, and sent a plain status message instead of worker_done. The capability is retained and settlement works when the report is sent — but the worker's own view still says failed, so it has to be told.

…'s fixtures

main added required creator/maxDepth on createStartingWorkerDispatch and
nestedWorkerMaxDepth on dispatchTaskToWorker while this branch was open. The two
fixtures added here predate them, so the merge typechecked clean on each side
and failed once combined. Mechanical; no behaviour asserted here changes.
@nwparker
nwparker marked this pull request as ready for review August 26, 2026 23:44
@nwparker
nwparker merged commit 68d5b92 into main Aug 26, 2026
97 of 99 checks passed
@nwparker
nwparker deleted the nwparker/win-16095-prompt-stall-observation branch August 26, 2026 23:44
@coderabbitai

coderabbitai Bot commented Aug 26, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 22981832-d870-43c6-b073-261fa3b06cb5

📥 Commits

Reviewing files that changed from the base of the PR and between 9135b6f and aa5dc38.

📒 Files selected for processing (12)
  • src/main/runtime/agent-prompt-submission-runtime.test.ts
  • src/main/runtime/agent-prompt-submission-verification.test.ts
  • src/main/runtime/agent-prompt-submission-verification.ts
  • src/main/runtime/orca-runtime.ts
  • src/main/runtime/orchestration/coordinator-dispatch-unobserved-prompt.test.ts
  • src/main/runtime/orchestration/coordinator-task-dispatch.ts
  • src/main/runtime/orchestration/db/dispatch-context/worker-report-settlement.ts
  • src/main/runtime/orchestration/db/worker-dispatch/worker-dispatch-outcome.ts
  • src/main/runtime/orchestration/worker-start-unobserved-prompt-settlement.test.ts
  • src/main/runtime/rpc/methods/orchestration-worker-start-outcome-classification.test.ts
  • src/main/runtime/rpc/methods/orchestration-worker-start-prompt-contract.test.ts
  • src/main/runtime/rpc/methods/orchestration-worker-start-receipt.ts

📝 Walkthrough

Walkthrough

Prompt submission verification now accepts hook-observed working turns and qualifying pane output. Runtime status tracking preserves each state’s start timestamp and exposes output activity. Coordinator dispatch treats unobserved prompt effects as dispatched-unobserved instead of failing the dispatch. Worker-start handling can retain dispatch capability for stalled prompts, and worker reports can later settle those dispatches. Tests cover verification, runtime behavior, dispatch, settlement, capability retention, and outcome classification.

✨ Finishing Touches 💡 1
🛠️ Fix failing CI checks 💡
  • Create stacked PR
  • Commit on current branch
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

dallascrilley pushed a commit to dallascrilley/orca that referenced this pull request Aug 27, 2026
…yai#16095) (stablyai#16590)

* fix(agent-prompt): stop reporting delivered prompts as stalled (stablyai#16095)

Enter is written before verification runs, so `agent_prompt_stalled` can only
ever mean "turn start not observed" — never "prompt not delivered". Three of the
verifier's blind spots made that misreading routine, and the coordinator then
treated it as non-delivery and pasted the whole preamble a second time into a
worker already running it.

- Accept a hook-reported `working` recorded after the baseline. Hook rows reach
  the runtime through getAgentStatusSnapshot with no window involved, unlike the
  synthetic-title route that feeds workingSequence (suppressed for codex, absent
  for kimi, and gated on window visibility for everyone else).
- Accept pane output after Enter when the agent was already working: a
  `->working` edge is unreachable there, so the old predicate could never be
  satisfied by a follow-up prompt. An idle agent still owes a real turn start,
  so a swallowed Enter stays detectable.
- Give codex/kimi panes a longer effect window; their only turn-start proof is
  an out-of-process hook round-trip, not a TUI repaint.
- Coordinator dispatch no longer fails (and re-dispatches) a task whose prompt
  stalled; the dispatch stays active with its capability intact so the worker's
  own report settles it.

* fix(orchestration): let a worker's own report correct an unobserved prompt (stablyai#16095)

Follow-up to f9f973c on two review findings.

Anchor the hook signal on a turn, not a refresh: `receivedAt`/`updatedAt` bump on
every same-state hook ping, so an in-progress turn could have passed for a new
one and silently accepted every prompt to a working agent. `stateStartedAt` is
the documented per-turn identity (pinned across same-state pings), so the
verifier now reads that.

Close the worker-start path: a `dispatch_input` stall settled the dispatch as
failed *and* revoked the capability, so a worker that ran the preamble to
completion had its result rejected. Revocation is now skipped for that cause,
and a worker report can re-settle a dispatch whose `last_failure` is
`agent_prompt_stalled` — retaining the capability alone was not enough, because
settlement also gates on dispatch/task status.

* fix(orchestration): let a failed worker report correct a stalled-prompt record (stablyai#16095)

The duplicate short-circuit ran before the unobserved-prompt branch, and for
outcome 'failed' both expected statuses are exactly the state failWorkerStart
leaves behind. A worker that reported a real failure was answered
duplicate:true, so its cause and result body were dropped and the record kept
'agent_prompt_stalled'. Evaluate settledByUnobservedPrompt first so one failure
report can re-settle that dispatch; a repeat report is still a duplicate.

Also derive the previous dispatch/worker states once instead of two parallel
ternaries, reuse getPtyAgent in createAgentPromptRenderGate, cite the real
30s relay request budget the hook window is sized against, and make the
coordinator test settle an actual worker report rather than calling
completeDispatch under a name that promised otherwise.

* test(orchestration): carry the new dispatch-depth fields into this PR's fixtures

main added required creator/maxDepth on createStartingWorkerDispatch and
nestedWorkerMaxDepth on dispatchTaskToWorker while this branch was open. The two
fixtures added here predate them, so the merge typechecked clean on each side
and failed once combined. Mechanical; no behaviour asserted here changes.
rahuljangirworks pushed a commit to rahuljangirworks/veer that referenced this pull request Aug 27, 2026
…yai#16095) (stablyai#16590)

* fix(agent-prompt): stop reporting delivered prompts as stalled (stablyai#16095)

Enter is written before verification runs, so `agent_prompt_stalled` can only
ever mean "turn start not observed" — never "prompt not delivered". Three of the
verifier's blind spots made that misreading routine, and the coordinator then
treated it as non-delivery and pasted the whole preamble a second time into a
worker already running it.

- Accept a hook-reported `working` recorded after the baseline. Hook rows reach
  the runtime through getAgentStatusSnapshot with no window involved, unlike the
  synthetic-title route that feeds workingSequence (suppressed for codex, absent
  for kimi, and gated on window visibility for everyone else).
- Accept pane output after Enter when the agent was already working: a
  `->working` edge is unreachable there, so the old predicate could never be
  satisfied by a follow-up prompt. An idle agent still owes a real turn start,
  so a swallowed Enter stays detectable.
- Give codex/kimi panes a longer effect window; their only turn-start proof is
  an out-of-process hook round-trip, not a TUI repaint.
- Coordinator dispatch no longer fails (and re-dispatches) a task whose prompt
  stalled; the dispatch stays active with its capability intact so the worker's
  own report settles it.

* fix(orchestration): let a worker's own report correct an unobserved prompt (stablyai#16095)

Follow-up to f9f973c on two review findings.

Anchor the hook signal on a turn, not a refresh: `receivedAt`/`updatedAt` bump on
every same-state hook ping, so an in-progress turn could have passed for a new
one and silently accepted every prompt to a working agent. `stateStartedAt` is
the documented per-turn identity (pinned across same-state pings), so the
verifier now reads that.

Close the worker-start path: a `dispatch_input` stall settled the dispatch as
failed *and* revoked the capability, so a worker that ran the preamble to
completion had its result rejected. Revocation is now skipped for that cause,
and a worker report can re-settle a dispatch whose `last_failure` is
`agent_prompt_stalled` — retaining the capability alone was not enough, because
settlement also gates on dispatch/task status.

* fix(orchestration): let a failed worker report correct a stalled-prompt record (stablyai#16095)

The duplicate short-circuit ran before the unobserved-prompt branch, and for
outcome 'failed' both expected statuses are exactly the state failWorkerStart
leaves behind. A worker that reported a real failure was answered
duplicate:true, so its cause and result body were dropped and the record kept
'agent_prompt_stalled'. Evaluate settledByUnobservedPrompt first so one failure
report can re-settle that dispatch; a repeat report is still a duplicate.

Also derive the previous dispatch/worker states once instead of two parallel
ternaries, reuse getPtyAgent in createAgentPromptRenderGate, cite the real
30s relay request budget the hook window is sized against, and make the
coordinator test settle an actual worker report rather than calling
completeDispatch under a name that promised otherwise.

* test(orchestration): carry the new dispatch-depth fields into this PR's fixtures

main added required creator/maxDepth on createStartingWorkerDispatch and
nestedWorkerMaxDepth on dispatchTaskToWorker while this branch was open. The two
fixtures added here predate them, so the merge typechecked clean on each side
and failed once combined. Mechanical; no behaviour asserted here changes.
paidaxingyo666 pushed a commit to paidaxingyo666/Manta that referenced this pull request Aug 28, 2026
…yai#16095) (stablyai#16590)

* fix(agent-prompt): stop reporting delivered prompts as stalled (stablyai#16095)

Enter is written before verification runs, so `agent_prompt_stalled` can only
ever mean "turn start not observed" — never "prompt not delivered". Three of the
verifier's blind spots made that misreading routine, and the coordinator then
treated it as non-delivery and pasted the whole preamble a second time into a
worker already running it.

- Accept a hook-reported `working` recorded after the baseline. Hook rows reach
  the runtime through getAgentStatusSnapshot with no window involved, unlike the
  synthetic-title route that feeds workingSequence (suppressed for codex, absent
  for kimi, and gated on window visibility for everyone else).
- Accept pane output after Enter when the agent was already working: a
  `->working` edge is unreachable there, so the old predicate could never be
  satisfied by a follow-up prompt. An idle agent still owes a real turn start,
  so a swallowed Enter stays detectable.
- Give codex/kimi panes a longer effect window; their only turn-start proof is
  an out-of-process hook round-trip, not a TUI repaint.
- Coordinator dispatch no longer fails (and re-dispatches) a task whose prompt
  stalled; the dispatch stays active with its capability intact so the worker's
  own report settles it.

* fix(orchestration): let a worker's own report correct an unobserved prompt (stablyai#16095)

Follow-up to f9f973c on two review findings.

Anchor the hook signal on a turn, not a refresh: `receivedAt`/`updatedAt` bump on
every same-state hook ping, so an in-progress turn could have passed for a new
one and silently accepted every prompt to a working agent. `stateStartedAt` is
the documented per-turn identity (pinned across same-state pings), so the
verifier now reads that.

Close the worker-start path: a `dispatch_input` stall settled the dispatch as
failed *and* revoked the capability, so a worker that ran the preamble to
completion had its result rejected. Revocation is now skipped for that cause,
and a worker report can re-settle a dispatch whose `last_failure` is
`agent_prompt_stalled` — retaining the capability alone was not enough, because
settlement also gates on dispatch/task status.

* fix(orchestration): let a failed worker report correct a stalled-prompt record (stablyai#16095)

The duplicate short-circuit ran before the unobserved-prompt branch, and for
outcome 'failed' both expected statuses are exactly the state failWorkerStart
leaves behind. A worker that reported a real failure was answered
duplicate:true, so its cause and result body were dropped and the record kept
'agent_prompt_stalled'. Evaluate settledByUnobservedPrompt first so one failure
report can re-settle that dispatch; a repeat report is still a duplicate.

Also derive the previous dispatch/worker states once instead of two parallel
ternaries, reuse getPtyAgent in createAgentPromptRenderGate, cite the real
30s relay request budget the hook window is sized against, and make the
coordinator test settle an actual worker report rather than calling
completeDispatch under a name that promised otherwise.

* test(orchestration): carry the new dispatch-depth fields into this PR's fixtures

main added required creator/maxDepth on createStartingWorkerDispatch and
nestedWorkerMaxDepth on dispatchTaskToWorker while this branch was open. The two
fixtures added here predate them, so the merge typechecked clean on each side
and failed once combined. Mechanical; no behaviour asserted here changes.

(cherry picked from commit 68d5b92)
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
…yai#16095) (stablyai#16590)

* fix(agent-prompt): stop reporting delivered prompts as stalled (stablyai#16095)

Enter is written before verification runs, so `agent_prompt_stalled` can only
ever mean "turn start not observed" — never "prompt not delivered". Three of the
verifier's blind spots made that misreading routine, and the coordinator then
treated it as non-delivery and pasted the whole preamble a second time into a
worker already running it.

- Accept a hook-reported `working` recorded after the baseline. Hook rows reach
  the runtime through getAgentStatusSnapshot with no window involved, unlike the
  synthetic-title route that feeds workingSequence (suppressed for codex, absent
  for kimi, and gated on window visibility for everyone else).
- Accept pane output after Enter when the agent was already working: a
  `->working` edge is unreachable there, so the old predicate could never be
  satisfied by a follow-up prompt. An idle agent still owes a real turn start,
  so a swallowed Enter stays detectable.
- Give codex/kimi panes a longer effect window; their only turn-start proof is
  an out-of-process hook round-trip, not a TUI repaint.
- Coordinator dispatch no longer fails (and re-dispatches) a task whose prompt
  stalled; the dispatch stays active with its capability intact so the worker's
  own report settles it.

* fix(orchestration): let a worker's own report correct an unobserved prompt (stablyai#16095)

Follow-up to f9f973c on two review findings.

Anchor the hook signal on a turn, not a refresh: `receivedAt`/`updatedAt` bump on
every same-state hook ping, so an in-progress turn could have passed for a new
one and silently accepted every prompt to a working agent. `stateStartedAt` is
the documented per-turn identity (pinned across same-state pings), so the
verifier now reads that.

Close the worker-start path: a `dispatch_input` stall settled the dispatch as
failed *and* revoked the capability, so a worker that ran the preamble to
completion had its result rejected. Revocation is now skipped for that cause,
and a worker report can re-settle a dispatch whose `last_failure` is
`agent_prompt_stalled` — retaining the capability alone was not enough, because
settlement also gates on dispatch/task status.

* fix(orchestration): let a failed worker report correct a stalled-prompt record (stablyai#16095)

The duplicate short-circuit ran before the unobserved-prompt branch, and for
outcome 'failed' both expected statuses are exactly the state failWorkerStart
leaves behind. A worker that reported a real failure was answered
duplicate:true, so its cause and result body were dropped and the record kept
'agent_prompt_stalled'. Evaluate settledByUnobservedPrompt first so one failure
report can re-settle that dispatch; a repeat report is still a duplicate.

Also derive the previous dispatch/worker states once instead of two parallel
ternaries, reuse getPtyAgent in createAgentPromptRenderGate, cite the real
30s relay request budget the hook window is sized against, and make the
coordinator test settle an actual worker report rather than calling
completeDispatch under a name that promised otherwise.

* test(orchestration): carry the new dispatch-depth fields into this PR's fixtures

main added required creator/maxDepth on createStartingWorkerDispatch and
nestedWorkerMaxDepth on dispatchTaskToWorker while this branch was open. The two
fixtures added here predate them, so the merge typechecked clean on each side
and failed once combined. Mechanical; no behaviour asserted here changes.
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