Skip to content

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

Closed
artile wants to merge 1 commit into
stablyai:mainfrom
tao-io:fix/rejected-worker-done-does-not-strand
Closed

artile wants to merge 1 commit into
stablyai:mainfrom
tao-io:fix/rejected-worker-done-does-not-strand

Conversation

@artile

@artile artile commented Aug 10, 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.

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 10, 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: 909a47fc-1715-4e5f-847b-8503a4440334

📥 Commits

Reviewing files that changed from the base of the PR and between c0c893d 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

📝 Walkthrough

Walkthrough

The orchestration runtime now records rejected worker reports with a dedicated stage. Rejected ready workers move to stop_unknown with a rejection reason. Missing-terminal reconciliation can requeue tasks from this state. Corrected reports can settle previously rejected workers. The RPC method records rejection when lifecycle authority is valid. Tests cover invalid reports, revoked dispatches, inactive tasks, non-assignee senders, retries, successful settlement, and missing worker terminals.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description explains the change and tests, but it omits the required Summary, Screenshots, AI Review Report, Security Audit, and Notes sections. Use the repository template headings and add the missing AI review, security audit, screenshots status, notes, and test checklist results.
Linked Issues check ⚠️ Warning The PR fixes the stranded ready state, records rejection details, preserves assignee checks, and adds tests, but it does not make missing capabilities actionable or explicitly unrecoverable. Add recovery or refresh guidance for an assigned worker, or state explicitly that the capability cannot be reacquired and define the required escalation path.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly describes the primary change: rejected worker_done reports no longer leave the Dispatch in ready.
Out of Scope Changes check ✅ Passed The implementation, exported state markers, authority helper, and tests directly support rejected worker_done handling and the linked issue objectives.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

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.

@artile

artile commented Aug 18, 2026

Copy link
Copy Markdown
Contributor Author

Moved to #15265 and closing this one — same branch, same commits, same head SHA, opened from a personal fork instead of an organisation-owned one.

The reason is the one Jinwoo-H hit on #13639: GitHub does not grant maintainer push access on a fork owned by an organisation, even though the API reports maintainer_can_modify: true. A maintainer who wanted to push a fixup here could not, and had to either ask and wait or rewrite the change on main and close ours. That is a poor trade for a reviewer, and it is very likely why these sat.

Nothing about the change moved. This thread keeps the review history, and #15265 carries the code.

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

3 participants