Repository navigation
fix(orchestration): worker-abandon settles a stuck worker and records who did it - #23983
Conversation
… who abandoned it worker-abandon refused or no-oped in the states it exists to escape: a stop stranded by a dead runtime, an active attempt that was no longer the Task's latest, and settled workers whose terminal release was stuck at requested or unknown. It now settles every non-terminal worker except this runtime's own in-flight stop, records who abandoned it, and retains (never closes) an owned terminal whose release is not already in flight. Part of STA-8833.
|
|
Navigate logical layers of code changes, visualize relationships, and explore their blast radius. Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
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 (2)
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review. 📝 WalkthroughWalkthroughWorker-dispatch abandonment now requires a runtime epoch and accepts optional caller details. It handles stranded stops, distinguishes already-settled workers, and retains owned terminal resources based on release state. The worker-abandon RPC passes runtime and caller information and reports the updated outcome. Tests cover abandonment states, caller attribution, and terminal-resource handling. CLI and recovery guidance describe Task cancellation and retry behavior. Priority: ➖ Normal Merge Risk: ⚪ Minimal · up to The abandonment changes have no established merge-blocking issue. Already-settled workers remain unchanged and retain the intended compatibility receipt. Merge after normal checks. Security Architecture ReviewSecurity architecture risk: 🔵 Low · up to Abandonment can now settle more worker attempts, but it preserves active-stop protection, transactional reconciliation, and terminal ownership checks. No introduced security vulnerability was established. External caller permissions and some interrupted recovery behavior remain unconfirmed. Retained concerns Security review detailsSecurity Blast Radius
Trust Boundaries and Controls
Resilience and Maintainability Implications
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ 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 |
…; record cancellations - One retain helper serves worker-retain and worker-abandon. A committed release (releasing, unknown) keeps its state and archive, since the tab may already be closed; a retained terminal drops its stale archive. - worker-abandon keeps the published stale field (this attempt was not the Task's current one) on the worker path. - task-list shows a failed Task's reason, whitespace-collapsed; task-update help and the recovery guide document cancel = failed + --result cancelled.
| } | ||
| if (worker.state === 'stopping') { | ||
| // Only this runtime's own in-flight stop is refused: it always ends in stopped or stop_unknown. | ||
| if (worker.state === 'stopping' && !isStopStrandedByAnotherRuntime(worker, runtimeEpoch)) { |
There was a problem hiding this comment.
If two live runtimes share a profile, a stop started by one has a different epoch from the other. This guard lets the second runtime abandon that worker while the first is still closing its terminal. The first runtime can then no longer settle the stop as stopped; the exit path may report a crash instead, producing a misleading outcome and escalation. A different epoch does not establish that the first runtime has died.
| if (terminal?.ownership_state === 'owned') { | ||
| retainTerminalResourceInTransaction(this, terminal.id, dispatchId) |
There was a problem hiding this comment.
Uncertain release reported retained
When an owned terminal's release is unknown, the retain helper leaves it in release_unknown, but this call discards that result. worker-abandon then says the resources were retained or the terminal was left open. The release may already have closed the terminal and still needs recovery, so the operator receives a misleading account of its state.
…lity retention - dispatch --inject no longer re-points the row createDispatchContext just wrote; worker-show reports every worker-less Dispatch as context_only, since Orca keeps no record of the paste. Tests re-point through a fixture. - failWorkerStart always records when the lifecycle closed; nothing authorizes on it. - Restore the ask resume hint's echo of a passed --dispatch-capability: an old host checks it before --resume. - Move the cancellation convention to #23983.
…output unchanged Cancellation stays documented in task-update help and the recovery guide.
Only the settling path retains an owned terminal.
| : 'Possibly-live resources were retained; no process was stopped or deleted.', | ||
| abandoned.disposition === 'abandoned' | ||
| ? 'Possibly-live resources were retained; no process was stopped or deleted.' | ||
| : `The worker was already ${worker.state}; its terminal was left open and no process changed.`, |
There was a problem hiding this comment.
Receipt misstates terminal state
For an already-settled worker whose terminal release is releasing, unknown, or released, the receipt says the terminal “was left open.” It may already be closed. Because the CLI prints this warning, an operator can get a misleading account of what remains to clean up.
| : `The worker was already ${worker.state}; its terminal was left open and no process changed.`, | |
| : `The worker was already ${worker.state}; its terminal was not changed by abandon and no process changed.`, |
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
…eep the prior diagnostic
…-settles # Conflicts: # src/cli/bundled-skill-guides.ts
…#23994) * fix(orchestration): authorize worker reports without the dispatch capability Worker lifecycle reports and questions no longer depend on the per-dispatch capability token that lives only in the agent's conversation. The host now: - ignores capability_hash/capability_revoked_at for authorization on every row and checks the exact worker process instead (ask gains that check); - refuses a report whose calling terminal is provably another orchestration party (a Run coordinator or another Dispatch's worker), treating env that names no live pane here as absent; - applies one worker-state rule locally and remotely: a stop in flight refuses, while stop_unknown and start_unknown accept and settle. Minting and printing the flag are unchanged, so an older host and older preambles keep working. * fix(orchestration): stop minting the dispatch capability Dispatches no longer mint a per-Dispatch token, and preambles, the bundled skill guide and the ask resume hint stop printing --dispatch-capability. The consumer-generation bump and delivery fence that minting carried stay, now as setDispatchConsumer. Readers that inferred meaning from capability_hash read what they meant instead: worker-show's injected stage comes from the attached consumer, and a failed start copies custody identity only when no authority was ever attached. The CLI keeps accepting and forwarding the flag for older hosts. Cancelling a Task is recorded as failed with a reason; task-list now shows that reason and the guide and task-update notes document the recipe. * fix(orchestration): name the fenced party without implying which Dispatch it owns * refactor(orchestration): one worker report rule, fence only a different party - One module owns the unproven/settleable worker states and the refusal rule; local send records it, ask and remote throw it. A stale process is worker_identity_changed on every path. - The caller fence passes the worker's own terminal when its --from handle went stale. - Document the shared-tmux-server limit; drop the dead dispatch_capability_invalid rejection member; tests assert dispatch state, not the capability column. * refactor(orchestration): drop setDispatchConsumer and the dead capability retention - dispatch --inject no longer re-points the row createDispatchContext just wrote; worker-show reports every worker-less Dispatch as context_only, since Orca keeps no record of the paste. Tests re-point through a fixture. - failWorkerStart always records when the lifecycle closed; nothing authorizes on it. - Restore the ask resume hint's echo of a passed --dispatch-capability: an old host checks it before --resume. - Move the cancellation convention to #23983. * test(orchestration): drop capability-era assertions other tests already cover * refactor(orchestration): drop the host-side capability field and no-op test fixtures - RpcRequest and the SSH bridge stop carrying orchestrationCapability; the CLI's wire field stays for older hosts. - Fixtures pass identity to createRootDispatch instead of re-pointing to the same values; drop absence checks for a flag that can no longer be produced. * test(orchestration): cover a current process whose terminal moved to another pane * chore(orchestration): finish the capability cleanup in test stubs and skill wording * test(orchestration): drop needless response casts; mark the db stub cast safe
…-settles # Conflicts: # src/cli/bundled-skill-guides.ts
ELI5
worker-abandonis the coordinator's "give up on this worker" button. It is supposed to always work: it doesn't kill anything, it just tells Orca "stop waiting on this attempt and stop trying to clean up its terminal". In practice it refused or silently did nothing in exactly the situations where people reached for it. This PR makes it settle the worker every time, and write down who did it.What Changed
Before,
orca orchestration worker-abandon --dispatch <id>:stopping)stale: true, "no state changed" — the attempt stayed active foreverrelease_unknownorrelease_pendinginworker-list)stale/ threw for succeeded;worker-listkept demandingworker-release, which kept answeringrelease_unknownAfter:
starting,ready,start_unknown,stop_unknown, and astoppingrow left by another runtime) moves toabandoned; its dispatch becomesfailedwith reasonabandoned(the same reason the unsupervised-dispatch path already records); the task is reconciled exactly as before (blocked, or left dispatched if a newer attempt is active); open questions are closed.lastError: "Abandoned by session:…". Only a verified caller (a resolved Orca session) is named; a terminal handle from the caller's environment is not verified, so otherwise it says "an unidentified caller". An earlier diagnostic (thestart_unknown/stop_unknowncause) is kept in front of the attribution. Shown byworker-show.worker-retain(one shared helper): a terminal whose release was not committed (not_requested,requested) becomesretained(retained_reason: user_requested) and its stale archive is dropped. The tab is left open — abandon still never closes or kills anything. A release already committed (releasing, orunknownafter one) is left as it is, with its archive, because the tab may already be closed and the archive is the only copy of its output; that isworker-retain's existingrelease_committedrule. Terminals Orca doesn't own (external, transferred, user-owned) are untouched.alreadySettled: true.failedwith--result cancelledafter stopping or abandoning its worker. No new status:tasks.statushas a CHECK constraint that would need a table rebuild, and old clients would see an unknown value;failedalready keeps dependents blocked and the host already stores the reason.task-updatehelp and the recovery guide document the convention.stoppedorstop_unknown(from which abandon works), and letting abandon cut in would make the stop's exit event read as a crash. This is the same predicateworker-stopalready uses for re-issuing a stranded stop, now shared asisStopStrandedByAnotherRuntime.Mechanism:
abandonWorkerDispatch(worker-dispatch-abandon.ts) now takes the caller's runtime epoch and identity. Thestaleearly return and the blanketstoppingrefusal are gone; oneWORKER_SETTLED_STATEScheck decides whether the lifecycle moves, andretainTerminalResourceInTransaction(extracted fromretainWorkerTerminalResource, now used by both) retains the owned terminal, all in the existing transaction. The RPC handler (worker-control.ts) passesruntime.getRuntimeId()and the caller identity already on the request context (display only:worker-abandonsends no--from, so the terminal handle is unverified env). The worker-path receipt keeps its publishedstalefield, now meaning "this attempt was not the Task's current one", as the context-only path does.Why
docs/reference/ssh-execution-boundary.md). Marking the terminal released would claim a close nobody proved; retaining just stops Orca from owing an action. A laterworker-releaseis still possible where release allows it.last_error, which already carries non-error reasons such as astop_unknowncause; the machine-read reason goes into the dispatch's existinglast_failureusing theabandonedvalue the context-only path already writes and reads (context-only-dispatch-release.ts), so a reader sees one vocabulary. A dedicatedabandoned_bycolumn would need a schema bump for a diagnostic string.beginWorkerStopfor no gain, since that state resolves by itself.Linked Issue
Part of STA-8833 (Linear), decision 6 of the dispatch-capability removal design ("worker-abandon always settles a stuck dispatch and records who abandoned it"). Partly addresses, none fully:
release_unknownstays there (same asworker-retain); that loop is aworker-releasedefect, not fixed here.worker-abandon(notworker-release) is the command that settles a stuck active attempt and frees its terminal for a newdispatch --inject; it now also records the reason and who did it.release_unknownloop. The underlyingworker-releasedefects those issues describe are not fixed here.stoppingand non-latest-attempt refusals were found while reproducing these.Visual Proof
N/A — orchestration state-machine and CLI receipt change; no UI.
Testing
New
worker-dispatch-abandon.test.ts(10 cases): strandedstoppingsettles;stop_unknownandstart_unknownsettle, keeping their cause and recording who; unidentified caller wording; a non-latest active attempt settles without touching the newer one; a settled worker'srequested/not_requestedterminal is retained and its stale archive dropped; an already-settled worker's terminal release is untouched;releasing,unknown(archive kept) and external terminals are untouched; repeat abandon reportsalready_abandoned. Newworker-abandon-caller.test.ts: the RPC names a resolved Orca session and never an unverified terminal handle. Existing tests that asserted the oldstaledisposition now assertalready_settled.Ran:
./node_modules/.bin/vitest run --config config/vitest.config.ts src/main/runtime/orchestration src/main/runtime/rpc/methods/orchestration src/main/runtime/rpc/methods/orchestration-structured-worker src/cli/handlers— 264 files, 2344 passed, 10 skippedpnpm tc— passoxlinton changed files — passpnpm run check:code-quality:changed— 0 new findings (basea0abcb6818b)Not tested: no end-to-end run against a live Orca, SSH relay or Windows host; the change is pure SQLite state-machine logic with no platform branches.
Review
Agent skill upstream boundary
docs/reference/agent-skill-sharing-upstream-boundary.mdand copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.Notes
stalestays true when nothing changed because the attempt was superseded or already settled, as before; abandoning an already-succeeded worker now returns that receipt (alreadySettled: true) instead of adispatch_inactiveerror, so its exit code is 0. An old CLI against a new host gets the new behavior; a new CLI against an old host gets the old behavior.Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)