Skip to content

fix(orchestration): worker-abandon settles a stuck worker and records who did it - #23983

Merged
Jinwoo-H merged 8 commits into
mainfrom
worker-abandon-always-settles
Sep 30, 2026
Merged

Jinwoo-H merged 8 commits into
mainfrom
worker-abandon-always-settles

Conversation

@Jinwoo-H

@Jinwoo-H Jinwoo-H commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 10 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​304 $\color{#cf222e}{\Huge{\mathbf{−}}}$​17 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​287
Prod 7 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​122 $\color{#cf222e}{\Huge{\mathbf{−}}}$​61 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​61

ELI5

worker-abandon is 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>:

Situation What happened
A stop that a crashed/restarted Orca left half-done (worker row stuck in stopping) Error: "is stopping; wait for worker-stop to settle" — it never would
The attempt is still active but is not the task's newest attempt Returned stale: true, "no state changed" — the attempt stayed active forever
The worker already failed/succeeded, but its terminal cleanup got stuck (release_unknown or release_pending in worker-list) Returned stale / threw for succeeded; worker-list kept demanding worker-release, which kept answering release_unknown
Nobody could tell afterwards who abandoned an attempt Nothing was recorded

After:

  • Every worker that has not already ended (starting, ready, start_unknown, stop_unknown, and a stopping row left by another runtime) moves to abandoned; its dispatch becomes failed with reason abandoned (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.
  • The worker row records who did it: 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 (the start_unknown / stop_unknown cause) is kept in front of the attribution. Shown by worker-show.
  • When abandon settles a worker, its Orca-owned terminal is retained through the same code and rule as worker-retain (one shared helper): a terminal whose release was not committed (not_requested, requested) becomes retained (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, or unknown after 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 is worker-retain's existing release_committed rule. Terminals Orca doesn't own (external, transferred, user-owned) are untouched.
  • Abandoning a worker that already failed/succeeded changes nothing, as before: no outcome change and no terminal retain; it says alreadySettled: true.
  • Cancellation convention (decision 7 of the design, moved here from fix(orchestration): stop minting and printing the dispatch capability #23994 because it is recovery guidance): a cancelled Task is recorded as failed with --result cancelled after stopping or abandoning its worker. No new status: tasks.status has a CHECK constraint that would need a table rebuild, and old clients would see an unknown value; failed already keeps dependents blocked and the host already stores the reason. task-update help and the recovery guide document the convention.
  • Still refused: a stop that this runtime has in flight right now. That stop always finishes on its own as stopped or stop_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 predicate worker-stop already uses for re-issuing a stranded stop, now shared as isStopStrandedByAnotherRuntime.

Mechanism: abandonWorkerDispatch (worker-dispatch-abandon.ts) now takes the caller's runtime epoch and identity. The stale early return and the blanket stopping refusal are gone; one WORKER_SETTLED_STATES check decides whether the lifecycle moves, and retainTerminalResourceInTransaction (extracted from retainWorkerTerminalResource, now used by both) retains the owned terminal, all in the existing transaction. The RPC handler (worker-control.ts) passes runtime.getRuntimeId() and the caller identity already on the request context (display only: worker-abandon sends no --from, so the terminal handle is unverified env). The worker-path receipt keeps its published stale field, now meaning "this attempt was not the Task's current one", as the context-only path does.

Why

  • Retain, not release: abandon is an operator decision, not evidence the process exited (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 later worker-release is still possible where release allows it.
  • Reuse over new state: no new columns, statuses or retained reasons. "Who" goes into the worker's existing last_error, which already carries non-error reasons such as a stop_unknown cause; the machine-read reason goes into the dispatch's existing last_failure using the abandoned value the context-only path already writes and reads (context-only-dispatch-release.ts), so a reader sees one vocabulary. A dedicated abandoned_by column would need a schema bump for a diagnostic string.
  • Keeping the in-flight-stop refusal: the alternative (abandon anything, let the stop fail with "not stopping") breaks the stop/exit-event handshake documented in beginWorkerStop for 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:

Visual Proof

N/A — orchestration state-machine and CLI receipt change; no UI.

Testing

  • I manually tested these changes locally
  • Automated tests added/updated, or explained why not below

New worker-dispatch-abandon.test.ts (10 cases): stranded stopping settles; stop_unknown and start_unknown settle, keeping their cause and recording who; unidentified caller wording; a non-latest active attempt settles without touching the newer one; a settled worker's requested/not_requested terminal 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 reports already_abandoned. New worker-abandon-caller.test.ts: the RPC names a resolved Orca session and never an unverified terminal handle. Existing tests that asserted the old stale disposition now assert already_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 skipped
  • pnpm tc — pass
  • oxlint on changed files — pass
  • pnpm run check:code-quality:changed — 0 new findings (base a0abcb6818b)

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

  • Not applicable, or this change follows docs/reference/agent-skill-sharing-upstream-boundary.md and copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Notes

  • Mixed versions: no wire change. The request is unchanged; the receipt keeps its fields. stale stays 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 a dispatch_inactive error, 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.
  • SSH / connected servers: abandon still acts on the Run home's rows only and never touches the remote process, as before. A terminal on an SSH host is retained, not closed.
  • Folder workspaces: unaffected; nothing here depends on git.
  • The bundled orchestration skill text is unchanged; it already describes abandon as "fences orchestration while accepting that resources may remain live".

Checklist

  • This PR is small and focused
  • I explained what changed and why (ELI5, the user-facing before/after, the mechanism, and why over the alternatives)
  • 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 (or N/A)
  • pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (or CI will cover; local preferred)

… 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.
@greptile-apps

greptile-apps Bot commented Sep 30, 2026 •

Copy link
Copy Markdown

RetriggerConfidence Score: 3/5

[High risk] Changes worker abandonment to record who initiated it.

The PR does not appear safe to merge while abandon can treat another live runtime’s in-flight stop as stranded and misreport an uncertain terminal release.

Findings

  1. P1 Live stop treated as stranded ▶
  2. P1 Uncertain release reported retained ▶
  3. P2 Receipt misstates terminal state ▶

Summary

The PR makes worker-abandon settle active and stranded worker attempts, records the abandoner when verified, and applies the existing terminal-retention rule. It also documents cancelled Tasks and, since the previous review, removes Dispatch capabilities from worker recipes and adds bounded worker_done retries.

  • Already-settled workers retain their outcome; abandon does not close terminals.
  • The remaining concerns are in existing review threads, not new comments.
Diagram
%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[worker-abandon] --> B{Worker already settled?}
  B -- Yes --> C[Return alreadySettled; leave state unchanged]
  B -- No --> D{Stop in flight in this runtime?}
  D -- Yes --> E[Refuse; await stop settlement]
  D -- No --> F[Mark worker abandoned and active Dispatch failed]
  F --> G[Reconcile Task and close questions]
  G --> H{Owned terminal; release not committed?}
  H -- Yes --> I[Retain terminal without closing it]
  H -- No --> J[Leave terminal release state unchanged]
Loading

Reviews (8) · Last reviewed commit: "Merge remote-tracking branch 'origin/mai..."

@coderabbitai

coderabbitai Bot commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

Note

Reviews paused

It 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 reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: c2289e1c-89b1-46e0-b26e-e248ce7e0629

📥 Commits

Reviewing files that changed from the base of the PR and between e914819 and eccd0f1.

📒 Files selected for processing (2)
  • src/main/runtime/rpc/methods/orchestration/worker/worker-abandon-caller.test.ts
  • src/main/runtime/rpc/methods/orchestration/worker/worker-control.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.


📝 Walkthrough

Walkthrough

Worker-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 eccd0

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 Review

Security architecture risk: 🔵 Low · up to eccd0

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
No architecture-level concerns identified.

Security review details

Security Blast Radius

  • inferred — A caller already able to invoke this RPC and name a dispatch can now settle additional classes of unsettled attempts. The inspected effects reach the addressed dispatch, its task reconciliation, questions, and eligible owned terminal resource in the runtime's orchestration database. The handler issues no process-stop or remote-server operation; transport access and cross-workspace exposure were not established.

Trust Boundaries and Controls

  • observed — The session resolver rejects claimed session identity from paired clients or SSH/WSL host contexts, validates the session record and live lease, and binds resolved identity into the handler context. Its documented same-host, same-user model explicitly treats session IDs as identity, not credentials. These checks support attribution but do not establish dispatch-specific authorization.
  • observed — New abandonment retains a terminal only when the dispatch-owned resource has ownership_state=owned. The retention update accepts not_requested, retained, or requested states and deletes an archive only after a successful update. Releasing, unknown, and released resources are not converted into retained resources, avoiding an unsupported assertion that cleanup has been undone.

Resilience and Maintainability Implications

  • observed — Eligible settlement revokes dispatch capability while retaining possibly-live resources, and the public receipt explicitly states that no process was stopped or deleted. This separates logical authority retirement from proof of process termination.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning 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 17 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title clearly and concisely identifies the main change: worker-abandon now settles stuck workers and records the abandoning caller.
Description check ✅ Passed The description follows the required template and provides a clear ELI5 summary, detailed changes, rationale, issue references, visual-proof status, testing results, review notes, compatibility consid…
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Commit to this branch
  • Create a new PR

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.

…; 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)) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Live stop treated as stranded

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.

Comment on lines +81 to +82
if (terminal?.ownership_state === 'owned') {
retainTerminalResourceInTransaction(this, terminal.id, dispatchId)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 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.

Jinwoo-H added a commit that referenced this pull request Sep 30, 2026
…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.`,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 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.

Suggested change
: `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!

Jinwoo-H added a commit that referenced this pull request Sep 30, 2026
…#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
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