Skip to content

fix(orchestration): keep a wrongly-stopped worker's dispatch capability - #21713

Closed
lattenee wants to merge 2 commits into
stablyai:mainfrom
lattenee:fix/worker-stop-capability-revocation
Closed

lattenee wants to merge 2 commits into
stablyai:mainfrom
lattenee:fix/worker-stop-capability-revocation

Conversation

@lattenee

Copy link
Copy Markdown
Contributor

ELI5

When you ask Orca to stop a supervised worker whose terminal it does not own (for example a terminal the worker was attached to rather than one Orca created), Orca cannot actually close anything, so it records the honest outcome stop_unknown. But the stop had already taken away the worker's messaging capability up front — before knowing whether the stop worked. The worker is still alive, you can still send it messages, but everything it sends back (worker_done, heartbeats, questions) is rejected with "capability is revoked". The worker is effectively muted forever even though nothing was stopped.

What Changed

An unproven stop no longer takes away a worker's authority, on both sides of the fence:

Local (home) side

Remote (federated attachment) side — the mirror bug, where capability_hash was nulled on intent and cannot be restored (the token lives only with the worker):

  • The hash now survives the stop intent and is cleared only by proven outcomes: settleRemoteAttachmentStop and the relay settle.
  • verifyRemoteAttachmentAuthority gains a stopping-state guard, keeping the in-flight stop fence the nulled hash used to provide.
  • Both relay settle paths admit stop_unknown: the modern ack-driven settle and the legacy-protocol settleRemoteOutcome enqueue gate (without the second one, workers on older-protocol peers would stay muted).
  • reconcileFederatedWorkerStop re-asserts revocation when a late remote report proves the stop after all, so a restored capability cannot still verify on a failed dispatch.

Why

The alternative — not revoking until the stop is proven — would drop the in-flight fence: during stopping, inbound worker reports would pass the authority gate and race the settle path. Revoking on intent and restoring only on the unproven outcome keeps the fence exactly as strong during the window that matters, while making stop_unknown mean "unverifiable" rather than "dead to me", matching the vocabulary in docs/reference/ssh-execution-boundary.md.

Not changed, deliberately: retry-of and task-update --status ready on a stop_unknown row still refuse (retrying could duplicate a live worker — the clean exit remains worker-abandon first), and a remote attachment that reached stop_unknown via start_unknown stays muted (its hash was cleared earlier by failRemoteAttachment — the remote twin of #16095, a separate fix).

Linked Issue

Fixes #21688

Visual Proof

N/A — orchestration state-machine change, no UI or interaction change.

Testing

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

New db-worker-stop-capability-restore.test.ts (13 cases): capability revoked during in-flight stop and restored on stop_unknown; kept on proven stop; not restored onto an already-settled dispatch; worker_done succeeded/failed reports settling the blocked dispatch; remote hash surviving intent / fenced by state / cleared on proven settle; relay settle accepting stop_unknown; the legacy-protocol enqueue path; revocation re-asserted on a late-proven federated stop.

Also ran: lifecycle-caller-edges (updated with the new edges), db-stopping-worker-task-guard, orchestration-worker-dispatch-db, db-task-dispatch-lifecycle-guards, worker-start-unobserved-prompt-settlement, db-task-dispatch-invariant, db-task-dispatch-races, lifecycle-reconciliation, mailbox-consumer-lifecycle-fencing, dispatch-capability, federation-lifecycle-settlement, federation-liveness-verdict, worker-stop-liveness-verdict, worker-stop-exit-race, worker-stop-capability, structured-worker-stop-receipt, send, federated-dispatch-observation-fence, remote-dispatch-attachment-release — all green. Typecheck and the changed-file code-quality gate pass.

Review

Agent skill upstream boundary

  • Not applicable

Notes

The remote/federated half was changed symmetrically and unit-tested at the DB layer; it was not exercised against a live relay. Cross-platform impact is nil (pure state machine). SSH/remote impact is the point of the remote half.

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)

beginWorkerStop revokes the dispatch capability on intent, before the
stop outcome is known. When the stop closes nothing — an external or
otherwise unreachable terminal — it settles as stop_unknown, but the
revocation stays: sends to the dispatch are still accepted while the
worker's own reports are rejected, muting a worker that is still
running.

An unproven stop now takes nobody's authority. markWorkerStopUnknown
hands the capability back while the dispatch is still pending or
dispatched, the same principle as failWorkerStart's retainCapability
(stablyai#16095): a worker that may still be running keeps the way to report.
settleWorkerReport accepts a report from a stop_unknown worker the way
it already accepts start_unknown — first-hand evidence outranks the
unproven inference — gaining a stop_unknown -> ready edge and clearing
the stale stop reason on re-entry.

The remote attachment mirror cannot restore a nulled capability_hash
(the token lives only with the worker), so the hash now survives the
stop intent and is cleared only by proven outcomes: settleRemoteAttachmentStop
and the relay settle. verifyRemoteAttachmentAuthority gains a stopping-state
guard to keep the in-flight fence the nulled hash used to provide, and
both relay settle paths — the modern ack settle and the legacy-protocol
enqueue — admit stop_unknown.

reconcileFederatedWorkerStop re-asserts revocation when a late remote
report proves the stop after all, so a restored capability cannot still
verify on a failed dispatch.
@coderabbitai

coderabbitai Bot commented Sep 19, 2026 •

Copy link
Copy Markdown
Contributor

Review Change StackReview Change Stack

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: d681122a-f259-472c-ab86-30f6fbb6c3f3

📥 Commits

Reviewing files that changed from the base of the PR and between 25ca0c9 and e92e5ca.

📒 Files selected for processing (2)
  • src/main/runtime/orchestration/db-worker-stop-capability-restore.test.ts
  • src/main/runtime/orchestration/db/dispatch-context/worker-report-settlement.ts

Included review availability: Your plan provides up to 10 included reviews per hour; 8 remain after this review.


📝 Walkthrough

Walkthrough

The change restores capability state after unproven local worker stops and preserves revocation after confirmed stops. Worker reports from stop_unknown can now settle dispatches and clear stale worker errors. Remote attachments preserve capability hashes during stop intent, reject authority while stopping, and clear hashes after settlement. Relay settlement accepts stop_unknown. New tests cover local, remote, relay, lifecycle, and reconciliation paths.

Priority: ➖ Normal

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 12 functions across 9 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main fix: preserving dispatch capability for workers that were stopped incorrectly.
Description check ✅ Passed The description includes all required sections, explains the user impact and implementation, links issue #21688, documents testing, and addresses UI, remote, SSH, cross-platform, and compatibility con…
Linked Issues check ✅ Passed The PR meets the coding objectives in #21688. markWorkerStopUnknown restores local capability only for pending and dispatched dispatches. Proven stops retain revocation. Worker reports from `sto…
Out of Scope Changes check ✅ Passed The production changes and tests stay within #21688. They modify local stop capability restoration and report settlement, worker lifecycle transitions, remote attachment authority and hash handling, r…
  • Fix all pre-merge checks with AI

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.

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

ℹ️ No critical issues — one narrow edge case inline.

Reviewed changes

  • Home-side capability restore on stop_unknown — markWorkerStopUnknown clears capability_revoked_at while the dispatch is still pending/dispatched, guarded so a concurrently-settled dispatch keeps its revocation; reconcileFederatedWorkerStop re-asserts it when a late remote report proves the stop.
  • stop_unknown → ready worker edge — settleWorkerReportInTransaction now treats a stop_unknown report like start_unknown: it settles a blocked dispatch, reopens the task, and clears the stale stop reason.
  • Remote attachment hash survives the intent — beginRemoteAttachmentStop no longer nulls capability_hash; verifyRemoteAttachmentAuthority fences an in-flight stop by state === 'stopping', and the hash is cleared only by proven settles.
  • Relay settle admits stop_unknown — both the ack-driven settleRemoteAttachmentInRelayTransaction and the legacy settleRemoteAttachmentOutcome enqueue gate.
  • Tests — new 13-case db-worker-stop-capability-restore.test.ts plus two lifecycle-caller-edges entries.

Pullfrog  | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

…a dispatched task

The stop_unknown/start_unknown reconnect routed a succeeded report
through ready only when the task was blocked. A legacy or context-only
sibling dispatch can hold the task at dispatched through the unproven
stop, so the report fell through to the ready-only fallback and threw
lifecycle_conflict, losing first-hand evidence the worker never
stopped.

Key the worker-level ready -> succeeded reconnect on the worker's own
unproven state instead of the task marker; the blocked -> dispatched
task transition stays gated on the blocked shape.

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

✅ No new issues found.

Reviewed changes

  • Unproven-worker success reports reconnect through ready regardless of task status — extracted unprovenWorker (start_unknown/stop_unknown) and added it to the succeeded-report branch gate, so a stop_unknown worker reporting success while a context-only sibling holds the Task at dispatched no longer falls through to the from: 'ready' fallback and loses the report to a lifecycle_conflict. The blocked-task reconnect (reconnectingWorker) is unchanged.
  • Regression coverage — the new case constructs the legacy sibling shape (raw dispatch_contexts insert) and asserts the report settles the dispatch and completes the Task; I verified it throws worker ... is stop_unknown; expected ready when the branch gate is reverted, then passes at head. The rest of the related lifecycle suites stay green (8 files, 107 tests).

Pullfrog  | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

@Jinwoo-H

Copy link
Copy Markdown
Contributor

FYI: #23982 removes the per-dispatch capability from authorization and includes the settlement half of this PR (a stop_unknown worker's report settles through a new stop_unknown -> ready edge; the remote relay settle accepts stop_unknown and start_unknown). With the host no longer checking the capability, the capability-restore half is not needed there. #23994 then stops minting the capability.

@nwparker

nwparker commented Nov 5, 2026

Copy link
Copy Markdown
Contributor

Closing as superseded — the linked issue (#21688) has been resolved on main by #23982 (e03870403e). Thanks for the contribution!

@nwparker nwparker closed this Nov 5, 2026
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.

[Bug]: a worker-stop that closed nothing still revokes the capability, muting a worker that is still running

3 participants