Repository navigation
fix(agent-prompt): stop reporting delivered prompts as stalled (#16095) - #16590
Conversation
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.
Sequencing with #16548 — land this first, then rebase #16548A 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
Corroborating detail: #16548 retargets its own stall tests from What #16548 fixes that this PR does notFair side, and worth taking: binding authority before readiness monitoring. A worker whose The merge, concretelyOne textual conflict: One break git will not catch: this PR adds
Why this orderThis 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. |
Exercised live against real running codex agents — main vs branchDriven end-to-end through One correction to this PR's own storyFor codex, the plain idle dispatch was never broken. codex writes its own spinner OSC title, which the main process parses with no renderer involved: so What actually reproduces, and is fixedAlready-working follow-up prompt — main FAILS, branch PASSES. codex pane made busy with main, 13.1 s, stalled: The prompt unambiguously landed — from the pane itself: branch, 8.1 s, Capability retention — main FAILS, branch PASSES. codex main — revoked at stall time, late report rejected, task stuck: branch — retained, late report settles: Also confirmed live: Not exercised — stated, not inferred
|
…'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.
|
Caution Review failedThe pull request is closed. ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (12)
📝 WalkthroughWalkthroughPrompt 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 ✨ Finishing Touches 💡 1🛠️ Fix failing CI checks 💡
📝 Generate docstrings
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. Comment |
…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.
…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.
…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)
…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.
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)workingSequence(→workingedge), a hookworkingturn that started after the baseline, or pane output after Enter when the agent was already working (the case where a→workingedge is structurally impossible). An idle agent still owes a real turn start, so a swallowed Enter stays detectable.AgentPromptActivitygainedexplicitWorkingStartedAtandoutputSequence. The freshness anchor isstateStartedAt, notupdatedAt, because same-state tool/prompt pings refreshupdatedAtwhile carryingstateStartedAtover.resolveAgentPromptEffectTimeoutMsreturns 15s for codex/kimi (HOOK_OBSERVED_TURN_START_AGENTS), 5s otherwise.getPtyAgenthelper;createAgentPromptRenderGatenow uses it instead of re-inlininglaunchAgent ?? foregroundAgent.Orchestration
coordinator-task-dispatch.ts: anagent_prompt_stalledthrow returns the newTaskDispatchResultmember'dispatched-unobserved'and logs, instead of failing the dispatch and re-pasting the preamble.failWorkerStart(…, { retainCapability })makes thecapability_revoked_atwrite conditional;orchestration-worker-start-receipt.tspasses it only foragent_prompt_stalled. Every other cause still revokes.worker-report-settlement.ts: a dispatch leftfailedwithlast_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):settledByUnobservedPromptis now computed before the duplicate short-circuit. Previously a worker that reportedoutcome: '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 keptagent_prompt_stalled. A failed report now writes the reallast_failureandresult; a repeat report is stillduplicate: true.previous = { status, workerState }.RELAY_TO_CLIENT_REQUEST_TIMEOUT_MS(30s,src/relay/dispatcher.ts:115), which was verified to exist.lets a late worker report settle a dispatch whose prompt was unobservednow actually callssettleWorkerReport(it previously calledcompleteDispatch, so its name promised coverage its assertions didn't provide), andworker-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, beforeverifyAgentPromptSubmissionruns at:19811. Soagent_prompt_stalledcan only ever mean "turn start not observed" — never "prompt not delivered". Four defects made that misreading routine:workingSequenceadvances only on a→workingedge (orca-runtime.ts:12475). A follow-up prompt to a still-spinning agent could never satisfy the predicate — guaranteed to throw after 5s, forever.workingSequencefor these agents ran throughsendSyntheticTitle, which returns early whenmainWindowis null or the window is hidden/minimized (index.ts:2102-2130), andworkingframes are sent unforced (:2210). Hidden window, minimized window, or headlessorca servemeantworkingSequencenever advanced.getAgentPromptActivityread fresh hook status intostatusbut hard-codedworkingSequencefrom the lifecycle map — visible to the permission check, invisible to the verifier.'ready'and re-dispatched up to 3×, re-pasting the whole preamble into a worker already executing it; worker-start revokedcapability_revoked_at(worker-dispatch-outcome.ts:53), so the worker's eventualworker_donewas rejected with "Dispatch … capability is revoked" — the symptom in two independent reproductions in the issue thread.The
stateStartedAtanchor is load-bearing and was proven non-vacuous: reverting it toupdatedAtmakesdoes not accept a hook row refreshed without a new working turnfail. 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:
settleWorkerReportInTransactionrejects unless dispatch and task aredispatched, 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:29notes codex emitsworkingOSC titles but can miss the final frame, andrecordAgentPromptLifecycleStateis 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
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; nowcoordinator-task-dispatch.ts:139keeps 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.observedDeliveryEvidenceaccepts 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).failed/dispatch_input/agent_prompt_stalled. Self-healing now: the worker is left alone and its lateworker_doneis accepted, so the receipt is cosmetic rather than destructive.worker_donewas unblocked. During that gap the still-running worker'sorca ask, heartbeats and mailbox routing are still rejected, andcloseQuestionsForDispatchstill 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 editMeasured, and it was partly wrong.failWorkerStartinworker-dispatch-outcome.tsand the same call expression inorchestration-worker-start-receipt.ts. Whoever lands second and resolves the conflict carelessly can silently drop either theretainCapabilityoption 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.worker-dispatch-outcome.tsauto-merges cleanly and the two edits are semantically compatible — fix(orchestration): start argv workers with bound authority #16548 widens thefailWorkerStartguard to['starting','ready'], this adds theretainCapabilityoption; different lines, orthogonal intent. The only textual conflict is the import header oforchestration-worker-start-receipt.ts. Sequencing is decided: this PR lands first, fix(orchestration): start argv workers with bound authority #16548 rebases on top.src/main/runtime/rpc/methods/orchestration-worker-start-outcome-classification.test.ts, which importsisUnknownWorkerStartOutcomefrom./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_atwrite, and a worker's eventualworker_doneis 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→workingpredicate and were guaranteed to throw after 5s forever, now verify. Headlessorca serveand hidden/minimized windows, where the hook→verifier route was window-gated and never advanced, now have a working evidence path.Trade-offs accepted
outputSequence; stronger evidence (marker scan, redraw diffing) has no principled threshold and the render gate runs before Enter and only for claude/codex.RELAY_TO_CLIENT_REQUEST_TIMEOUT_MS. Consequence: the reported receipt can still appear.promptInjectionMode: 'argv'agents removes paste-and-verify entirely and is strictly better for codex; that is orchestration: launch argv-capable worker agents with the dispatch preamble embedded, instead of paste + 5s submission verification #16425 / fix(orchestration): start argv workers with bound authority #16548's half, deliberately not adopted. Nothing from either PR was pulled into this diff. The review round enumerated what the argv fix alone would leave broken and this PR covers: kimi and ~20 otherstdin-after-startagents; a reused or external terminal (a suppliedparams.terminalskips both argv branches, so even codex and claude still paste); follow-up prompts to an already-working agent; hidden-window / headlessorca serve, wheresendSyntheticTitlereturns early soworkingSequencenever increments at all; and the capability revocation that is the actual data loss in [Bug]: agent_prompt_stalled for codex/kimi workers — fixed 5s confirmation window vs ~20s first hook-event latency (root-cause evidence) #16095. Corroborating rather than asserted: fix(orchestration): start argv workers with bound authority #16548 retargets its own stall tests from codex to aider, conceding the paste path stays live for non-argv agents.dispatched-unobserveddispatch instead of trusting it indefinitely.tui-idlewait times out fails at stageagent_readiness, whereisAgentPromptStalledErroris false, so this PR'sretainCapabilitynever applies and the worker is still stripped of its capability. That case needs fix(orchestration): start argv workers with bound authority #16548, which is a further reason to sequence rather than pick one.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 acapability_revoked_atwrite 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:failed/dispatch_input/agent_prompt_stalled— only now non-destructive.promptInjectionMode: 'argv'agents so there is nothing to paste and nothing to verify — is covered by @flosrn's orchestration: launch argv-capable worker agents with the dispatch preamble embedded, instead of paste + 5s submission verification #16425 and @antoniofulg's fix(orchestration): start argv workers with bound authority #16548, not here.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 thelast_failure/resultfields on an existing receipt, neither of which is graphical.Testing
Real output from the fix round (macOS, on the branch head):
Non-vacuity check for the fix-round behaviour change (stashed only
worker-report-settlement.ts, kept the new test):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.tswas confirmed to auto-merge with both edits intact;orchestration-worker-start-receipt.tsconflicts only in its import header; and theisUnknownWorkerStartOutcomeimport in the neworchestration-worker-start-outcome-classification.test.tswas 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 againsttui-agent-config(kimi plus ~20 otherstdin-after-startagents; a suppliedparams.terminalskipping both argv branches; follow-up prompts to a working pane; hidden-window/headlessorca 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/arm64omptrials.Reviewer independently re-ran
pnpm test src/main/runtimeon 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 readingorca-runtime.ts,index.tsandworker-dispatch-outcome.tsat the cited lines. Every new test was verified to fail against pre-fix code (explicitWorkingStartedAt/outputSequencedon't exist on the old type; the coordinator test asserts a'dispatched-unobserved'return the old function could not produce;failWorkerStarthad 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).
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 withomp(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 casecoordinator-task-dispatch.ts:139now 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_donewas 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:
worker-dispatch-outcome.tsauto-merges and the two edits are semantically compatible — fix(orchestration): start argv workers with bound authority #16548 widens thefailWorkerStartguard fromworker.state !== 'starting'to['starting','ready']; this adds theretainCapabilityoption. Different lines, orthogonal intent. The earlier "silently drop one half" worry did not survive inspection.orchestration-worker-start-receipt.ts.orchestration-worker-start-outcome-classification.test.tsimportsisUnknownWorkerStartOutcomefrom./orchestration-worker-topology; fix(orchestration): start argv workers with bound authority #16548 un-exports it and re-declares it locally. New file on this side, so no conflict marker — clean merge, then typecheck fails. The fix belongs to fix(orchestration): start argv workers with bound authority #16548 and is cosmetic: drop that move.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
observedDeliveryEvidenceaccepts any PTY byte from an already-working pane (agent-prompt-submission-verification.ts:110).outputSequenceis bumped bysequenceCharson 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 resolveaccepted: truewhen it did not land. Declined as a deliberate trade, not a non-issue: pre-PR that same case always produced a falseagent_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.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 30sRELAY_TO_CLIENT_REQUEST_TIMEOUT_MS. Consequence: see Linked Issue — the reported receipt can still appear.isAgentPromptStalledErrorwas left in its two-step form. A proposed one-expression collapse was rejected as a correctness regression:RemoteRuntimeClientErrorextendsErrorand carries acode, soerror 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
getFreshExplicitAgentStatusForHandlepicks 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 pinnedstateStartedAtcould accept a turn that started before the prompt.AGENT_STATUS_STALE_AFTER_MS) and then refreshed by a same-state ping re-enters with an old-but-positivestateStartedAtand reads as a new turn.failWorkerStart(stalled)and the corrective report the dispatch isfailed, so the still-running worker'sorca ask(orchestration.ts:1780), heartbeats (lifecycle-reconciliation.ts:151) and mailbox routing (orchestration.ts:1193) are still refused, andcloseQuestionsForDispatchstill runs. Only the finalworker_donewas unblocked.serializeAgentPromptSubmission), so a queue of prompts to a pane whose hook never reports now blocks 15s each.does not treat an unchanged newer working status as submission evidenceasserted 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
Checklist
N/Awith reasonorca serve, which is the SSH/remote casepnpm lint,pnpm typecheck,pnpm testpass locally (pnpm buildleft to CI)