Skip to content

Move a rejected worker_done off ready instead of stranding its Dispatch - #15265

Open
artile wants to merge 3 commits into
stablyai:mainfrom
artile:fix/rejected-worker-done-does-not-strand
Open

artile wants to merge 3 commits into
stablyai:mainfrom
artile:fix/rejected-worker-done-does-not-strand

Conversation

@artile

@artile artile commented Aug 18, 2026

Copy link
Copy Markdown
Contributor

What changes

A worker_done that Orca refuses now takes its worker Dispatch out of ready. A refused report from the assigned pane parks the lane at state = stop_unknown, stage = worker_report_rejected, with the rejection reason in last_error.

Fixes #13364 (point 2 — "never leave the dispatch reading ready").

Evidence

Two traces of the same shape, from waves run against v1.4.176/v1.4.178.

2026-08-09. A supervised worker tried to report twice, twenty seconds apart. Both attempts came back rejected and were stored as Rejected worker_done: … blocked at finish gate with a body beginning "Orca rejected this worker_done". Its escalation went to the Run mailbox. The work itself was fine — the branch merged and the ticket closed three minutes later — but ctx_5781041c767c still read state = ready, stage = input_accepted hours afterwards, which is exactly what a live worker looks like. Two of that wave's nine dispatch contexts were in this state and nothing in Orca would ever have noticed.

2026-08-10. Six workers finished their task and every worker_done came back rejected, because their dispatches had been revoked after a readiness timeout while the agents themselves ran to completion. The coordinator ended up detecting completion by reading files on disk, because the one channel that reports completion had refused all six.

Why this branch and not the other one

The alternative was to leave the dispatch alone and make the rejection loud to the sender. That is already true on main, so there was nothing to add:

  • orchestration.send returns lifecycle: { action: 'rejected', code, reason } (orchestration.ts).
  • The CLI sets a non-zero exit code and prints Rejected <id>: <reason> (src/cli/handlers/orchestration.ts:592), covered by orchestration-lifecycle-rejection.test.ts.
  • The SSH fallback recognises the same shape through hasRemoteLifecycleRejection.

The 2026-08-09 worker did learn — it retried, then escalated. What no one learned was that its lane had ended. So the gap is the dispatch row, not the sender.

How

markWorkerReportRejected on OrchestrationDb is called from the two places a worker_done can be refused after its sender has proved it owns the dispatch:

  1. The capability branch in orchestration.send. This branch returns before reconcileLifecycleMessage, which is why the row was never touched. It is gated on hasLifecycleAuthority, so a terminal that is not the assignee cannot park someone else's lane by naming its dispatch id.
  2. settleWorkerReportInTransaction, for inactive_dispatch and stale_dispatch — the codes that mean this exact dispatch can no longer settle. This path is reached only after the authority check in reconcileWorkerDoneMessage, and it also covers reports that arrive over the federation relay.

Rejections that cannot identify a lane the sender owns — sender_not_assignee, unknown_dispatch, task_dispatch_mismatch, a malformed payload — leave the row alone.

stop_unknown rather than failed: failed is in WORKER_RELEASABLE_STATES, so it would mark the agent's terminal reclaimable while the agent may still be running. stop_unknown keeps the terminal retained and reads as "this ended and I do not know how", which is what a refused report actually tells us. worker-abandon — "fence a worker without claiming its process stopped" — still fences a parked lane in full.

Two consequences handled in the same change, so the fix does not create a new way to strand things:

  • A corrected retry (for instance re-sending with --dispatch-capability) still settles a parked lane, instead of completing the Task while the lane stays at stop_unknown.
  • reconcileMissingWorkerTerminal still requeues the Task for a parked lane. Its stopWasPending test now excludes the report-rejected stage, because such a lane never had a stop requested.

Nothing in readiness, revocation, the dispatch lifecycle, or the mailbox changes.

Test plan

New: src/main/runtime/rpc/methods/orchestration-rejected-worker-report-lane.test.ts — 7 tests over a real supervised worker lane.

  • parks the lane when the assignee reports without its Dispatch capability
  • parks the lane when the report loses to a revoked Dispatch
  • parks the lane when settlement rejects a Task that left the dispatched state
  • leaves the lane alone when a terminal that is not the assignee reports
  • settles the lane when the report is accepted
  • settles a parked lane when the worker retries with its capability
  • still requeues the Task when a parked lane loses its terminal

Results on this branch:

vitest run src/main/runtime/rpc/methods/orchestration-rejected-worker-report-lane.test.ts
  Test Files  1 passed (1)        Tests  7 passed (7)

vitest run src/main/runtime/orchestration src/main/runtime/rpc/methods/orchestration \
           src/cli/handlers/orchestration src/main/ssh/ssh-remote-orca-cli.test.ts
  Test Files  62 passed | 1 skipped (63)     Tests  770 passed | 2 skipped (772)

pnpm typecheck   pass
pnpm lint        pass

The full pnpm test run also passed except for two timing assertions unrelated to this change (terminal-output-frame-chunks-equivalence, ai-vault-session-worktree-map), which the machine's load caused; both pass when re-run on their own.


Moved from #13655, same commits, same head SHA. That pull request was opened from an organisation-owned fork, and GitHub refuses maintainer pushes on org-owned forks even when maintainer_can_modify reports true — so a maintainer could not push a fixup to it, only ask or rewrite. This one is on a personal fork, where a maintainer push works.

The review history stays readable on #13655: #13655

A worker_done that Orca refuses left its worker Dispatch at state=ready,
stage=input_accepted — the same reading as a worker that is still thinking.
Nothing else moved that row, so a lane whose worker had already finished
stayed green for the rest of the wave.

A refused report from the assigned pane now parks the lane at stop_unknown
with stage=worker_report_rejected and the rejection reason in last_error, so
an audit can tell an ended Dispatch from a live one. Reports from a terminal
that is not the assignee leave the lane untouched. A later accepted report
still settles a parked lane, and a parked lane that loses its terminal still
requeues its Task.

Refs stablyai#13364
@coderabbitai

coderabbitai Bot commented Aug 18, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 5e385926-114c-4eaf-886d-ae8fb24c4d5d

📥 Commits

Reviewing files that changed from the base of the PR and between a184ee4 and 67fcaa7.

📒 Files selected for processing (1)
  • src/main/runtime/orchestration/worker-report-identity.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/main/runtime/orchestration/worker-report-identity.ts

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


📝 Walkthrough

Walkthrough

The orchestration runtime validates worker-report identity before recording rejection. Authorized invalid reports can park ready dispatches in stop_unknown with a rejection stage and reason. Valid retries can settle parked dispatches and clear prior errors. Missing-terminal reconciliation distinguishes rejected reports from pending stops. Tests cover reports for another task and reports without a taskId.

Merge Risk: 🟡 Moderate · up to 67fca

An assigned worker report with an invalid capability or malformed or mismatched payload can still move an active dispatch into stop_unknown, leaving valid work in the wrong state; merge should wait for this correctness issue to be fixed or explicitly accepted.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Linked Issues check ⚠️ Warning The PR satisfies the issue's Dispatch-state objective but does not address the separate objective to make rejected reports actionable for workers. Add a documented capability reacquisition or refresh path, or update the issue linkage and scope to show that the actionable-rejection objective is handled separately.
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the primary change to move rejected worker_done Dispatches out of ready.
Description check ✅ Passed The description explains the change, rationale, linked issue, implementation, scope, and test results, but omits several template headings and checklist details.
Out of Scope Changes check ✅ Passed The code and tests remain focused on rejected worker_done handling, Dispatch state reconciliation, identity validation, retries, and missing-terminal behavior.
✨ Finishing Touches 💡 1
⚔️ Resolve merge conflicts 💡
  • Resolve merge conflict in branch fix/rejected-worker-done-does-not-strand

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.

@coderabbitai coderabbitai 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.

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: c23b3789-d59f-4a4a-936d-89d5dfe9f321

📥 Commits

Reviewing files that changed from the base of the PR and between 545b3fb and bfbe9be.

📒 Files selected for processing (5)
  • src/main/runtime/orchestration/db.ts
  • src/main/runtime/orchestration/lifecycle-reconciliation.ts
  • src/main/runtime/orchestration/types.ts
  • src/main/runtime/rpc/methods/orchestration-rejected-worker-report-lane.test.ts
  • src/main/runtime/rpc/methods/orchestration.ts

Included review availability: Your plan includes up to 10 reviews per rolling hour; 5 remain after this review.

The capability-invalid branch parked the Dispatch on pane authority
alone. Pane authority says the sender is the assignee; it says nothing
about what the sender reported. An assigned terminal could therefore
send a worker_done naming another task, or no task at all, and move its
own healthy lane from ready to stop_unknown — the state that exists for
a worker that really finished and could not be settled.

isWorkerReportForDispatch applies the identity checks reconciliation
already makes — right task, right Dispatch, real outcome — before the
park. A report that fails them is still rejected as it was; it just
leaves the lane where it found it, which is what the PR promises for
unknown Dispatches, mismatched tasks and malformed payloads.

The helper lives in its own module: lifecycle-reconciliation.ts is at
the max-lines ceiling, and the identity question is shared by the send
path and the reconciler rather than owned by either.

@coderabbitai coderabbitai 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.

🧹 Nitpick comments (1)
src/main/runtime/orchestration/worker-report-identity.ts (1)

3-10: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Shorten this block comment.

Keep the non-obvious rationale in one concise line. The helper name and predicates already show the behavior.

As per coding guidelines, “Comments must be concise, non-obvious, and brief—prefer one line.”

Source: Coding guidelines


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: fe926958-02f0-4a93-83ac-41988f3971ec

📥 Commits

Reviewing files that changed from the base of the PR and between bfbe9be and a184ee4.

📒 Files selected for processing (3)
  • src/main/runtime/orchestration/worker-report-identity.ts
  • src/main/runtime/rpc/methods/orchestration-rejected-worker-report-lane.test.ts
  • src/main/runtime/rpc/methods/orchestration.ts

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

The repository asks for one concise non-obvious line; the block was
restating what the predicates already show.
@artile

artile commented Aug 20, 2026

Copy link
Copy Markdown
Contributor Author

@coderabbitai nitpick taken — 67fcaa7546.

// Why: parking a lane on a rejected report needs the same identity proof reconciliation applies,
// or a report naming another task would move a lane it never worked.

Eight lines down to two. What is kept is the only part the code cannot say: why a courtesy path needs reconciliation-grade proof. The three predicates already say which task, which Dispatch and which outcomes, so spelling them out in prose was a second copy that could rot away from the first.

@coderabbitai

coderabbitai Bot commented Aug 20, 2026

Copy link
Copy Markdown
Contributor

Tip

For best results, initiate chat on the files or code changes.

@artile The revised comment keeps the required rationale and avoids duplicating the validation logic. Thanks for the update.

🐇 ✓


🧠 Learnings used
Learnt from: artile
Repo: stablyai/orca PR: 15265
File: src/main/runtime/rpc/methods/orchestration.ts:612-621
Timestamp: 2026-08-19T06:37:55.806Z
Learning: In the TypeScript orchestration runtime, `isWorkerReportForDispatch` belongs in `src/main/runtime/orchestration/worker-report-identity.ts` because both `src/main/runtime/rpc/methods/orchestration.ts` and lifecycle reconciliation use the same worker-report identity validation. A rejected `worker_done` may park a Dispatch only when `hasLifecycleAuthority(dispatch, message)` and `isWorkerReportForDispatch(dispatch, message)` both pass.

If you found this review helpful, would you consider giving us a shout-out on X?

Thank you for using CodeRabbit!

You are interacting with an AI system.

This branch has not been deployed

No deployments
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]: rejected worker_done ("Dispatch capability is missing") leaves the dispatch at state=ready forever

1 participant