Repository navigation
fix(orchestration): worker-start settles readiness on observed turn start, not write acceptance - #19423
Conversation
…tart, not write acceptance A dispatched PTY worker whose agent wedged at startup (six codex workers on 2026-09-07) was reported 'ok: true, state: ready, stage: input_accepted': the preamble write was acknowledged with observationTimeoutMs: 0 and nothing ever verified a turn began. The corpse and the healthy worker produced identical receipts. worker-start now runs the existing second-stage prompt observer (observeTerminalAgentPrompt) after acceptance, inside the 30s window the client RPC grace already budgets for (orchestration-worker-start-prompt-budget): - turn observed (or provider ack for structured sessions) -> ready - permission prompt -> ready; positive liveness, surfaced in the receipt - provider without a turn-start signal -> ready; observation: unsupported - observation supported and nothing started -> worker state start_unknown, response state outcome_unknown with nextCommands. Honest 'unverifiable', never a death claim: the capability and terminal are kept, and worker-report settlement already reconnects a start_unknown worker that recovers and reports. Also fixes the effect-verb lie that misdirected the first diagnosis of this incident: agent-first worktree creation labeled its own brand-new agent terminal 'reused_agent_terminal' (a role test picking a lifecycle verb) on both the local and federation paths. It now says 'created'; readers keep accepting the retired verb for rows persisted before the rename.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (3)
Included review availability: Your plan provides up to 10 included reviews per hour; 7 remain after this review. 📝 WalkthroughWalkthroughThe change adds structured worker turn-start observation and centralizes worker readiness settlement. Early worker reports can settle normally, while unobserved starts preserve dispatch authority and outstanding questions. Unknown-start effects can be persisted. Worker report settlement now accepts starting workers. Terminal creation effects consistently use Priority: ➖ Normal Merge Risk: ⚪ Minimal · up to Worker startup now verifies turn-start evidence and retains recoverable unknown-start state when observation cannot confirm progress. The prior incarnation-replacement readiness concern is covered by the current behavior, with no active merge-blocking risk remaining. 🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
Full details: Description checkExplanation The description gives detailed context, root cause, implementation details, testing results, and scope. However, it omits the required Linked Issue entry, the required Visual Proof section or an explicit N/A explanation, and the template checklist sections. Resolution Add a Linked Issue entry with the issue number, add the Visual Proof section with before/after evidence or exactly N/A plus a reason, and complete the required Testing, AI Disclosure, Review, Agent skill upstream boundary, Notes, and Checklist sections. Full details: Docstring CoverageExplanation Docstring coverage is 13.33% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 15 functions across 15 files. (1 skipped: 1 unsupported.)
✨ Finishing Touches 💡 1📝 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 |
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Team
Run ID: c92b0f88-90b4-468c-8aa1-814bf91012b8
📒 Files selected for processing (12)
src/main/runtime/orchestration/db/worker-dispatch/worker-dispatch-authority.tssrc/main/runtime/orchestration/db/worker-dispatch/worker-dispatch-outcome.tssrc/main/runtime/rpc/methods/orchestration/federation/federation-effects.tssrc/main/runtime/rpc/methods/orchestration/worker/composed-workers.test.tssrc/main/runtime/rpc/methods/orchestration/worker/local-worker-start.tssrc/main/runtime/rpc/methods/orchestration/worker/worker-setup-gate.tssrc/main/runtime/rpc/methods/orchestration/worker/worker-start-prompt-contract.test.tssrc/main/runtime/rpc/methods/orchestration/worker/worker-start-readiness-settlement.tssrc/main/runtime/rpc/methods/orchestration/worker/worker-start-turn-observation.test.tssrc/main/runtime/rpc/methods/orchestration/worker/worker-start-turn-observation.tssrc/main/runtime/rpc/methods/orchestration/worker/worker-topology.tssrc/main/runtime/rpc/methods/orchestration/worker/workers-new-worktree.test.ts
Included review availability: Your plan provides up to 10 included reviews per hour; 6 remain after this review.
| // 'unsupported' (and an old host's missing observation) leaves acceptance as the best receipt. | ||
| return 'unsupported' |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
Classify initial incarnation_replaced deliveries as unobserved.
When an initial delivery has observation: 'incarnation_replaced', classifyPromptDelivery falls through to 'unsupported'. observeWorkerTurnStart then skips observation, and readiness settlement calls markWorkerDispatchReady without evidence from the current PTY incarnation. Handle this observation before the unsupported fallback.
Proposed fix
function classifyPromptDelivery(prompt: RuntimeTerminalPromptDelivery): WorkerTurnStartVerdict {
+ if (prompt.observation === 'incarnation_replaced') {
+ return 'unobserved'
+ }
if (prompt.stages.includes('turn_started')) {
return 'observed'
}There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
- Readiness settles on observed turn start:
deliverAndSettleWorkerStartReadinessreplaces the inline preamble-delivery +markWorkerDispatchReadytail inlocal-worker-start.ts; after the accepted write it runs the second-stage observer and only reportsreadyon a positive turn-start (orpermission/unsupported), otherwisestart_unknownwithstate: 'outcome_unknown'plus recoverynextCommands. - Turn-start observation:
worker-start-turn-observation.tsclassifies the prompt delivery and reusesobserveTerminalAgentPromptinside theAGENT_PROMPT_EFFECT_TIMEOUT_MSwindow already reserved in the client RPC grace. - Unknown-start effects persistence:
markWorkerStartUnknowngains an optionaleffectsparam so theturn_unobservedevidence is durable alongside theacceptedreceipt. - Agent-terminal effect verb correction:
worker-topology.tsandfederation-effects.tsnow emitaction: 'created'for agent-first-created agent terminals; readers retain the retiredreused_agent_terminalfor pre-rename persisted rows. - Tests: the swallowed-Enter contract test now proves the wedge (
outcome_unknown/blocked/start_unknown, capability retained, exactly one submit), and new unit tests cover the full verdict matrix.
I verified the load-bearing claims against the code: the unobserved path leaves dispatch pending + task blocked + worker start_unknown with the capability intact, and the pre-existing reconnectingStart branch in worker-report-settlement.ts already reconnects that exact combination through ready on a later success report; the lifecycle graph permits start_unknown -> ready; and the preamble send's observationTimeoutMs: 0 returns observation: 'supported' for codex/claude so the gate actually runs for them while unsupported providers (grok) skip the wait entirely. The only noteworthy design tradeoff is that the 30s observation window is fixed and not bounded by --timeout, which is consistent with the reserved client grace rather than a defect.
DeepSeek Pro (free via Pullfrog for OSS) | 𝕏
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
- Preserved authority through unobserved starts:
markWorkerStartUnknownno longer callscloseQuestionsForDispatch, so anunverifiableworker's outstanding questions stay answerable until it reports, is abandoned, or fails — consistent with the execution-boundary vocabulary the first commit established. - Settled reports that land mid-observation:
settleWorkerReportgained areportingStartbranch (pending+dispatched+starting) so a worker that finishes during the 30s window transitionsstarting -> ready -> succeeded(orstarting -> failed) instead of being rejected asinactive_dispatch. - Observation failure no longer tears down the worker:
observeWorkerTurnStartcatches a stale terminal binding and returnsunobservedinstead of throwing intostartLocalWorker's teardown path, which would have revoked capability and closed the terminal. - Readiness settlement tolerates a concurrent report:
deliverAndSettleWorkerStartReadinessre-reads the worker after observation and returns an already-settled outcome asready+workerOutcomerather than re-marking it ready or recording a conflictingstart_unknown. - Tests and reliability gate: three new contract tests pin each fix (early
succeeded/failedreport with and without turn evidence, stale binding, answerable questions after timeout), and the invariant/assertions were updated to match.
I traced the load-bearing paths: the lifecycle transitions the new branch reuses are all pre-existing (starting -> ready via markWorkerDispatchReady, starting -> failed via failWorkerStart, pending/dispatched -> completed/failed via the existing report path); worker-abandon/worker-stop/settleWorkerReport all still close questions, so removing the close from markWorkerStartUnknown leaks nothing; and the initial preamble delivery only ever carries supported/unsupported/permission, so incarnation_replaced remains reachable solely in the second-stage result where it is already handled. The new tests are exact and would fail without the corresponding fix.
DeepSeek Pro (free via Pullfrog for OSS) | 𝕏
|
Supplemental real-runtime QA on
These uncropped hidden-renderer screenshots show actual saved CLI JSON filtered with the visible SSH remains unverified: both Docker daemon sockets were absent, Docker Desktop reported not running, and no existing Colima/OrbStack command was available. No production target was used. This local evidence does not establish SSH/federation correctness or a blanket land verdict; new-worktree creation, permission, observation-exception, and incarnation-replacement paths were not exercised in this runtime pass. |
Review status — ba6a5f0Scoped code review: clean after fixes. Landing recommendation: do not land yet; real SSH validation remains blocked and has not been waived. Changes pushedThree same-model/same-effort review rounds produced commit
No unrelated transport rewrite, product expansion, dependency change, or screenshot/report files were committed. Separate judgments
Live evidence and remaining gatesFull-context screenshots and runtime evidence show the exact-SHA hidden Electron app in a disposable folder workspace:
Supplemental Codex performed this QA because the requested Grok worker hit its weekly usage limit; this is not Grok validation. SSH could not run: both Docker daemon endpoints were unavailable, Docker Desktop was stopped, and no existing Colima/Orb alternative was installed. No real SSH/network-drop, Windows/WSL runtime, or mobile journey is claimed. No mobile-facing UI changed. Test-owned app/process/profile/folder resources were cleaned up; evidence was preserved outside the PR diff. Complete real SSH validation (or obtain explicit acceptance of that gap), and resolve the requested Grok QA quota, before treating this review session as fully complete. No merge was performed. |
|
SSH real-runtime QA on
Uncropped hidden-renderer screenshots show the actual saved CLI JSON filtered with the visible Remaining gaps: permission/approval, observation-exception, incarnation-replacement, structured-worker, and known-unsupported-provider paths were not exercised over SSH in this pass; federation excluded per scope; no mobile UI changed or exercised. Full command transcripts and receipts are retained in the QA run directory outside the repo. |
|
SSH QA passed using OpenCode
|
…er-start-wedge-2 # Conflicts: # src/main/runtime/rpc/methods/orchestration/worker/local-worker-start.ts
|
Note GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer. |
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes (since the prior review at ba6a5f0)
- Merged
origin/main:685c428merges main (2ba2c90) into the branch and resolves its one conflict inlocal-worker-start.ts. The reconciliation correctly rails this PR'sdeliverAndSettleWorkerStartReadinesssettlement onto main's custody-at-creation path from #19608. - Adopted custody-at-creation:
recordCreatedWorkerTerminalCustody(imported from the newcreated-worker-terminal-custody.ts) is invoked before the boot wait, owning the agent terminal from creation — closing the same early-window gap the 30s observation window otherwise holds open. - Dropped the residual-terminal teardown path:
tearDownFailedWorkerStartnow takes the post-#19608 three-argvoidsignature, so the obsoleteresidualAgentTerminalbinding and itsfailWorkerStartWithReceiptspread were removed; the deleted residual-terminal mechanism is subsumed by custody-at-creation.
I confirmed the reconciliation compiles and the merge-affected suites pass (worker-start-prompt-contract, worker-start-turn-observation, composed-workers, workers-new-worktree, and #19608's worker-terminal-custody-at-creation — 63 tests). prepareStartingWorkerAuthority still accepts the retired reused_agent_terminal verb, and both custody writers are guarded by getWorkerTerminalResourceByOwner, so the two features coexist without double ownership rows.
DeepSeek Pro (free via Pullfrog for OSS) | 𝕏
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes (since the prior review at 685c428)
- Merged
origin/main(210ac1f):8b0d79ais a merge-up whose only PR-authored delta is the conflict reconciliation. Main extractedcreateWorkerWorktreeout ofworker-topology.tsinto the newworker-worktree-creation.ts(via #19431), which relocated this PR's agent-terminal effect-verb fix. - Verb fix relocated cleanly:
reused_agent_terminal→creatednow lives inworker-worktree-creation.ts, still emittingaction: 'created'for every listed terminal (the agent terminal included), with the misdiagnosis rationale preserved in the comment;worker-start-agent-placement.tsimports it from the new path. - Import surface reconciled:
local-worker-start.tsdropped the symbols main removed (createWorkerWorktree,createExistingWorktreeWorkerTerminal,createStructuredWorkerSessionForWorktree,deliverWorkerDispatchPreamble,monitorWorkerSetup,WorkerSetupReceipt) and now importsrequireWorkerAuthority, type WorkerEffect;monitorWorkerSetupmoved intodeliverAndSettleWorkerStartReadiness, and the reveal warning now readsplaced.warningfromWorkerAgentPlacement.
Verified the reconciliation compiles (pnpm tc:node clean) and the affected suites pass (38 tests across workers-new-worktree, worker-start-prompt-contract, and worker-start-turn-observation). No behavioral change beyond the merge reconciliation.
DeepSeek Pro (free via Pullfrog for OSS) | 𝕏





What happened
Six
orca orchestration worker-startdispatches (2026-09-07, all--worktree new-child --setup run --agent codex --model ...) returnedok: true, state: ready, stage: input_acceptedfor workers that never did any work. The agent terminals held a codex in one of three end states: a network-reconnect loop, MCP startup frozen, or the task spec sitting unsent in the composer as[Pasted Content].Root cause, with the evidence
Why those specific dispatches wedged (environmental trigger, not fixed here). A still-live corpse (
rc-a1-latch-settle, dispatchctx_f5241043314e) was caught in the act: its codex TUI (pid 7528) sat inSYN_SENTto208.111.34.11:2455— a garbage public IP.lsof -i TCP:2455showed 16 codex TUIs in the same state. The codex LB (openclaw.orca-procyon.ts.net:2455) lives on a tailnet reachable on this machine only through the userspace-tailscaled proxy at127.0.0.1:1055or the local bridge at127.0.0.1:2455; system DNS (NordVPN resolver on utun5) resolves*.ts.netto hijack IPs. Healthy codexes (structured app-server sessions) carryHTTP(S)_PROXY/ALL_PROXY=…127.0.0.1:1055inherited from the app process; daemon-spawned PTY terminals carry none. That is machine setup, not an Orca defect — but it exposed two real Orca defects:Defect 1 — readiness was a write receipt, not evidence.
deliverWorkerDispatchPreamblesent the preamble withacceptQueued: true, observationTimeoutMs: 0, sostage: input_acceptedmeant only "bytes written + Enter written". No code ever checked that a turn began, andworker-start-prompt-contract.test.tspinned the lie: its "swallowed Enter" case assertedstate: 'ready'withstartedTurns() === 0. A corpse and a healthy worker were indistinguishable by design. (Thetui-idlegate upstream is banner-based for codex —OpenAI Codex+model:+directory:— which a mid-boot codex prints before MCP/network come up, so it never catches this either.)Defect 2 — the effect verb lied. On the new-worktree path the agent terminal is created by that same call's agent-first worktree creation, but the receipt said
action: 'reused_agent_terminal'(worker-topology.ts, duplicated infederation-effects.ts) — a role test picking a lifecycle verb. This misdirected the first diagnosis of the incident toward terminal reuse.The setup correlation held but was not causal. DB history: codex+
new-child+setup run→ abandoned corpses; codex+new-child+setup skip→ succeeded; claude/opencode+setup run→ succeeded; codex existing-worktree → succeeded (those ran structured —--model/--effortforces terminal mode, and every wedged dispatch passed--model). The path split is PTY-vs-structured (proxy env present only on the structured side), with DNS flakiness explaining occasional PTY successes. Setup rode along; its receipts all saidsucceeded.The fix
Readiness now settles on the strongest available evidence (
worker-start-readiness-settlement.ts,worker-start-turn-observation.ts). After the accepted write, worker-start runs the existing second-stage observer (observeTerminalAgentPrompt— the same oneterminal.sendreceipts replay through), inside the 30s windoworchestration-worker-start-prompt-budget.tsalready reserves in the client RPC grace (that budget's comment says "plus effect settlement"; the server just never used it):ready,turnStart: 'observed'ready,turnStart: 'permission'(positive liveness)ready,turnStart: 'unsupported'— acceptance is the best receipt that can existstart_unknown, responsestate: 'outcome_unknown'+nextCommands(worker-show / terminal read / worker-abandon); CLI exits non-zeroExecution-boundary compliance: the unobserved verdict is
unverifiable, never a death claim. The dispatch capability and terminal are kept, the task goesblocked(the existingstart_unknownconvention), and nothing is torn down —worker-report-settlement.tsalready reconnects astart_unknownworker throughreadyif it recovers and reports. Providers that cannot prove a turn are never punished for it.Verb fix: agent-first-created agent terminals now say
createdon both the local and federation paths; readers keep accepting the retiredreused_agent_terminalfor pre-rename persisted rows.local-worker-start.tscrossed max-lines from the new logic, so the delivery/settlement tail moved verbatim intoworker-start-readiness-settlement.ts(no disable, no ratchet bump).Repro and demonstration
worker-start-prompt-contract.test.tsharness: real prompt pipeline, codex accepts the paste, swallows Enter, never starts a turn. Before this PR that test asserted the shipped behavior (ready); it now proves the fix (outcome_unknown,start_unknown, capability retained, exactly one submit, no blind retry).Out of scope (flagged, not half-done)
--model/--effortsilently downgrading a structured-preferring worker to a PTY terminal agent (mode reasonlaunch_preferences) — that routing put codex on the unproxied path; supporting launch preferences in structured sessions is its own change.tui-idlebanner heuristic accepting a mid-boot codex as idle — the new gate makes its false positive loud instead.worker-stopwas checked for coherence: it already acceptsstart_unknownworkers; no change needed.Verification (verbatim tails)
pnpm test src/main/runtime/rpc/methods/orchestration/→Test Files 67 passed (67) / Tests 614 passed (614)pnpm test src/main/runtime/orchestration/→Test Files 94 passed (94) / Tests 757 passed (757)pnpm tc:node→ clean (tsc --noEmit -p config/tsconfig.node.json);@pnpm/exelockfile drift reverted, lockfiles absent from this diffpnpm run audit:code-quality:native,pnpm run audit:code-quality:type-aware→ cleannpx oxlint --config config/oxlint-react-doctor.json <changed files as explicit argv>→ clean;node config/scripts/check-react-doctor-changed.mjs "$(git merge-base HEAD origin/main)"→ exit 0pnpm run check:max-lines-ratchet→ OK, no new bypassesWire compatibility: response gains optional fields (
turnStart,nextCommands,lastError) and reuses the existingoutcome_unknownstate string already produced byfailWorkerStartWithReceipt; no new stream opcodes, no RPC param changes.