You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
feat(orchestration): tell the coordinator when a worker stops without worker_done - #35294
A dispatched worker that stops without sending worker_done (the model was at capacity, it errored, it misread the task, or it just stopped) used to leave its Dispatch at "dispatched". The coordinator heard nothing, sometimes for hours. Now Orca tells the coordinator, once per stop, with the worker's last output. The coordinator then decides what to do: answer it, retry it, or stop it.
What Changed
Before: a worker's turn ends and it sits at its prompt. The Dispatch stays open and no mail arrives.
After: the coordinator's Run gets one escalation ("Worker stopped without reporting", "...stopped on an error...", or "Worker is waiting on a prompt"). The message carries:
the worker's last words, or the screen when the turn errored or is stuck at a prompt
the commands to answer, read or stop the worker (quoted output is capability-redacted)
a payload with stopReason
It wakes the coordinator like other worker mail. The Dispatch is never settled or failed automatically.
When it fires:
Signals reused: the turn-end signal Orca already uses for phone alerts and the sidebar. For terminal workers that is TerminalAgentTurnNews over AgentTransitionDetector. For chat workers it is the structured host's turn-completion feed. Only hook-reported finishes, errors and approval prompts count. Silence never does.
One per stop: the message id hashes the Dispatch with the stop. The next turn (for example after the coordinator replies) re-arms it.
Not during deliberate waits: a worker inside ask or check --wait (a live dispatch:<id> waiter) is skipped, and so is a worker waiting on its own open helper Dispatches.
Not for a lead with working children: a new opt-in allClearOnly on TerminalAgentTurnNews waits for the children's all-clear.
Dispatch changes: the stop belongs to the Dispatch that was active when it was seen. A follow-up Dispatch that arrives before delivery drops it.
Chat failures already escalate through the existing chat-error path. User-stopped turns are not news.
Where:
Local and SSH workers: the execution host's runtime observes the pane and calls escalateWorkerFailure, the path terminal-exit escalations already use.
Paired-server workers: the execution host relays the escalation to the Run home through enqueueFederationRelay, the way a worker's own send does, under a stable message id. A queued but unacknowledged worker_done suppresses the relay. Older homes import it as an ordinary escalation, and older execution hosts just never send it.
Fleet state: while a stop report is newer than the last mail to the worker, worker-list/worker-show project the open attempt as finished_unverified, so requiresAction is true and nextAction is recover (worker-read). Mail to the worker, worker_done, or settling the attempt clears it. No new enum values.
Stop keeps output:worker-stop, local and paired-server, archives the worker's output before closing its terminal, bounded at 5 s and best effort. A later release then settles with that archive instead of "unavailable", and worker-retain keeps it for a stopped worker.
Guide: one line in the orchestration guide says what the message means and the usual responses.
Testing
worker-turn-stops.test.ts covers:
an errored stop with screen output, sent once
re-arm on a new turn
an approval prompt
silence for a resumed turn, a settled Dispatch, or an open dispatch: waiter
a lead with children
a Dispatch replaced during the quiet window
chat success vs failure
the remote relay: stable id, string payload, and a pending worker_done suppressing it
capability redaction
fleet projection of a stopped attempt, cleared by coordinator mail
stop, optionally retain, then release keeps captured output
Real app (dev build, background launch, isolated profile, agents on the dev CLI), Claude worker told to reply "hello" and end its turn:
Before (main 40822e2): the turn ended, the Dispatch stayed pending, and check --peek returned 0 messages.
After (this branch): one escalation "Worker stopped without reporting" with stopReason: finished. A second turn gave exactly one more. A turn ending in worker_done gave none (worker_done was the only new message).
The runtime now reports qualifying terminal and chat worker turn stops for local and remote Dispatches. It checks Dispatch and mailbox state before reporting, formats stop details, and routes local reports through failure escalation and remote reports through federation relays. Terminal stop handling validates that the worker and Dispatch remain in the captured state. The orchestration guide documents responses to escalations with a stopReason. The change also updates worker attention and recovery projections and archives worker output before stop operations.
Priority: Normal
Merge Risk: Moderate · up to f353a
Resolve the remote output and worker-recovery visibility issues before merging. Remote workers can also escalate while helpers are active, and a reporting error can go unhandled.
Pre-merge checks: 3 · 2
Failed checks: 2 warnings
Check name
Status
Explanation
Resolution
Description check
The description follows the repository template. It includes the ELI5, What Changed (before/after, mechanism, and trigger conditions), Why-adjacent rationale, Testing with specific test coverage and a…
Add a Linked Issue reference (for example, "Fixes #"); the template requires an actual issue for outside contributors. Fill in Visual Proof with a before/after reference (video or screenshots) or write N/A with a reason, since this …
Docstring Coverage
Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documenta…
Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed checks: 3 passed
Check name
Status
Explanation
Title check
The title "feat(orchestration): tell the coordinator when a worker stops without worker_done" states the main change. The PR adds an escalation to the coordinator when a dispatched worker's turn ends …
Linked Issues check
Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check
Check skipped because no linked issues were found for this pull request.
Full details: Title check
Explanation
The title "feat(orchestration): tell the coordinator when a worker stops without worker_done" states the main change. The PR adds an escalation to the coordinator when a dispatched worker's turn ends without sending worker_done. The title is specific and concise, and it follows a conventional commit format. It does not cover the secondary changes (fleet projection, worker-stop archiving, relay), which is acceptable.
Full details: Description check
Explanation
The description follows the repository template. It includes the ELI5, What Changed (before/after, mechanism, and trigger conditions), Why-adjacent rationale, Testing with specific test coverage and a real-app before/after check, and the LoC summary. Gaps: the Linked Issue section is still the empty template ("Fixes #"), which the template says is required for outside contributors. The Visual Proof section is empty even though the change is a behavior change and the template asks for a BEFORE/AFTER. The Testing checkbox for manual testing is not ticked, though the author describes a manual real-app test. The Why section is not separate; rationale for the approach over alternatives is only partly stated. The AI Disclosure, Review, and Agent skill upstream boundary sections are blank. The Checklist items are not ticked.
Resolution
Add a Linked Issue reference (for example, "Fixes #<number>"); the template requires an actual issue for outside contributors. Fill in Visual Proof with a before/after reference (video or screenshots) or write N/A with a reason, since this is a behavior change. Add an explicit Why section that explains why this approach was chosen over alternatives. Tick the manual-testing checkbox if it applies. Complete or mark the Agent skill upstream boundary section. Tick the checklist items that now hold, such as lint, typecheck, test, and build status.
Full details: Docstring Coverage
Explanation
Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 14 functions across 22 files.
Resolution
Write docstrings for the functions missing them to satisfy the coverage threshold.
Finishing Touches: 💡 2
📝 Generate docstrings: 💡
Commit to this branch
Create a new PR
🛠️ Fix failing CI checks: 💡
Commit to this branch
Create a new PR
Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
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.
chatStop maps a prompt event to needs-input. The only chat test sends completion events, so no test reaches this branch. A regression in the prompt branch would not fail the suite.
Add a case to describe('chat worker turn stops') that:
Sends a prompt event for a chat session that has a pending approval prompt.
Asserts that one escalation is delivered.
Asserts that the escalation's stopReason is needs-input.
Review info
Run configuration
Source mode: Auto
Repository: Unavailable
Branch: Unavailable
File: No configuration file from this repository applied
Commit: Unavailable
Layers: Repository UI
Review profile: CHILL
Plan: Advanced
Run ID: 782aa482-9fc1-4c60-a569-6589cd1eaa5d
Commits
Reviewing files that changed from the base of the PR and between 09bd3b9 and 95b2107.
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 6 remain after this review.
The reason will be displayed to describe this comment to others. Learn more.
Minor · Stability & Availability · Quick win
Catch errors from report; the terminal path can produce an unhandled rejection.
deliver calls void this.report(stop) with no .catch. report calls stillStopped, which calls resolve. That calls getActiveDispatchForTerminal and findActiveRemoteAttachmentForPane. reportWorkerTurnStop also calls hasOpenHelperDispatch and hasPendingFederatedWorkerReport outside any try.
If one of these synchronous database calls throws, for example because the database closed during shutdown, report rejects with no handler. In the Electron main process, an unhandled rejection can surface as a crash dialog.
chatWorkerTurnStopReporter already wraps its body in try/catch and logs a warning. Apply the same guard here.
🛡️ Proposed fix
--- "a/src/main/runtime/orchestration/terminal-worker-turn-stops.ts"+++ "b/src/main/runtime/orchestration/terminal-worker-turn-stops.ts"@@ -36,7 +36,11 @@
const resolved = this.resolve(news.paneKey)
return { ...news, dispatchId: resolved && workerTurnStopDispatchId(resolved.target) }
},
- deliver: (stop) => void this.report(stop),+ deliver: (stop) => {+ this.report(stop).catch((error) => {+ console.warn('[orchestration] terminal worker stop report failed', error)+ })+ },
setTimer: deps.setTimer,
// A lead waiting on its own children is not stopped; their all-clear is.
allClearOnly: true
Committable suggestion
IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
A remote worker can start a helper whose creator_dispatch_id is the remote attachment's dispatch_id. The current guard skips that check for remote targets, so the worker can emit an escalation while its helper remains open.
IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
…and stop keeps its output
worker-list projected a stop-reported attempt as live, in_progress, no action. It now
projects finished_unverified with a worker-read recovery until mail reaches the worker.
worker-stop closed the terminal before anything archived it, so release reported the
archive unavailable; stop now archives the output first.
Adds coordinator mail when a worker ends a turn or needs input without sending worker_done.
Orca alerts the coordinator when a worker stops without reporting.
Worker views flag unreported stops and point recovery to worker-read.
Stopped workers keep their captured output for later release.
Diagram
%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[Worker ends turn or needs input] --> B{Dispatch still open?}
B -->|No| C[Do not report]
B -->|Yes| D{Deliberate wait?}
D -->|Yes| C
D -->|No| E{Worker location}
E -->|Local| F[Insert escalation]
E -->|Paired server| G[Relay to Run home]
G --> F
F --> H[Wake coordinator]
H --> I[Dispatch stays open]
The reason will be displayed to describe this comment to others. Learn more.
Failed stops freeze saved output
archiveWorkerOutputBeforeStop saves output before closeTerminal runs. If closing fails and the worker keeps running, the saved copy remains. When the process later exits, release can treat that old copy as final and report it as captured, losing everything written after the failed stop.
Keep the copy provisional until stop succeeds, or refresh it while the worker is still reachable.
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 7 remain after this review.
The reason will be displayed to describe this comment to others. Learn more.
Minor · Functional Correctness · Quick win
Compare mail with the stop time, not report insertion.
If guidance arrives while the terminal stop report is waiting for delivery, the report can be inserted after the guidance. The worker can still be at rest while its wake is pending, so TerminalWorkerTurnStops can deliver that report. The query then marks the worker finished_unverified until another message or settlement clears it. Capture a mailbox watermark when the stop is observed and use it to reject or project stale reports. (raw.githubusercontent.com)
The reason will be displayed to describe this comment to others. Learn more.
Minor · Functional Correctness · Quick win
Supported by static analysis
Script executed:
sed -n '42,105p' src/shared/orchestration-fleet-worker-projection.ts
sed -n '230,275p' src/shared/orchestration-fleet-worker-projection.ts
sed -n '20,85p' src/main/runtime/orchestration/worker-attention-context.ts
rg -n 'function resolveFleetWorkerOutcome|const resolveFleetWorkerOutcome' src
Repository: stablyai/orca
Length of output: 5516
Script executed:
set -o pipefail
printf'%s\n''--- outcome resolver ---'
sed -n '1,130p' src/shared/orchestration-fleet-outcome-resolution.ts
printf'%s\n''--- attention projection ---'
sed -n '1,125p' src/shared/orchestration-fleet-attention.ts
printf'%s\n''--- changed query and stop SQL ---'
sed -n '1,145p' src/main/runtime/orchestration/db/worker-terminal/worker-terminal-attention-query.ts
printf'%s\n''--- stop-report SQL definition and references ---'
rg -n -F --glob '*.ts' -e 'STOP_REPORT_SINCE_LAST_MAIL_SQL' -e 'stopped_without_report' src/main/runtime/orchestration
printf'%s\n''--- relevant projection callers ---'
rg -n -F --glob '*.ts' -e 'projectWorkerAttentionContext' -e 'getWorkerAttentionFactsForDispatches' -e 'projectOrchestrationFleet(' src/main src/shared
printf'%s\n''--- relevant tests ---'
sed -n '430,510p' src/shared/orchestration-fleet-projection.test.ts
sed -n '1,90p' src/shared/orchestration-fleet-attention.test.ts
Repository: stablyai/orca
Length of output: 23871
Script executed:
set -o pipefail
printf'%s\n''--- shared fleet projection ---'
sed -n '115,180p' src/shared/orchestration-fleet-projection.ts
printf'%s\n''--- worker-list projection ---'
sed -n '1,105p' src/main/runtime/rpc/methods/orchestration/worker/worker-list-projection.ts
printf'%s\n''--- runtime projection ---'
sed -n '35,115p' src/main/runtime/runtime-agent-orchestration-projection.ts
printf'%s\n''--- worker attention query wrapper ---'
sed -n '135,175p' src/main/runtime/orchestration/db/worker-terminal/worker-terminal-attention-query.ts
printf'%s\n''--- next action and attention exact lines ---'
nl -ba src/shared/orchestration-fleet-worker-projection.ts | sed -n '145,175p'
nl -ba src/shared/orchestration-fleet-attention.ts | sed -n '60,90p'
Repository: stablyai/orca
Length of output: 12061
Keep stop-reported exits actionable.
When an unsettled worker has a matching stop report and a certified exit, the outcome remains finished_unverified. projectFleetNextAction returns recover, but projectOrchestrationFleetAttention suppresses unverifiable for exited workers. With no other pending condition, callers receive requiresAction: false and can miss the recovery signal.
Suggested fix
- // Proven exit must not also report absence and tell callers to keep waiting.+ // Stop-reported workers remain actionable even when exit is proven.
if (
- facts.liveness.verdict !== 'exited' &&- (facts.outcome === 'outcome_unknown' || facts.outcome === 'finished_unverified')+ facts.outcome === 'finished_unverified' ||+ (facts.liveness.verdict !== 'exited' && facts.outcome === 'outcome_unknown')
) {
The reason will be displayed to describe this comment to others. Learn more.
Major · Data Integrity & Integration · Quick win
Do not serve a pre-stop archive as final output after an unproven stop.
If remote closeTerminal fails or cannot prove the process stopped, federationStop records an unknown outcome. The archive stored here remains. federationReadOutput then selects that archive before a live read, so later worker output is absent from output reads. When the stop is unproven, invalidate the snapshot or prefer live output until the process is proven stopped. (raw.githubusercontent.com)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
ELI5
A dispatched worker that stops without sending
worker_done(the model was at capacity, it errored, it misread the task, or it just stopped) used to leave its Dispatch at "dispatched". The coordinator heard nothing, sometimes for hours. Now Orca tells the coordinator, once per stop, with the worker's last output. The coordinator then decides what to do: answer it, retry it, or stop it.What Changed
Before: a worker's turn ends and it sits at its prompt. The Dispatch stays open and no mail arrives.
After: the coordinator's Run gets one
escalation("Worker stopped without reporting", "...stopped on an error...", or "Worker is waiting on a prompt"). The message carries:stopReasonIt wakes the coordinator like other worker mail. The Dispatch is never settled or failed automatically.
When it fires:
TerminalAgentTurnNewsoverAgentTransitionDetector. For chat workers it is the structured host's turn-completion feed. Only hook-reported finishes, errors and approval prompts count. Silence never does.askorcheck --wait(a livedispatch:<id>waiter) is skipped, and so is a worker waiting on its own open helper Dispatches.allClearOnlyonTerminalAgentTurnNewswaits for the children's all-clear.Where:
escalateWorkerFailure, the path terminal-exit escalations already use.enqueueFederationRelay, the way a worker's ownsenddoes, under a stable message id. A queued but unacknowledgedworker_donesuppresses the relay. Older homes import it as an ordinary escalation, and older execution hosts just never send it.worker-list/worker-showproject the open attempt asfinished_unverified, sorequiresActionis true andnextActionisrecover(worker-read). Mail to the worker,worker_done, or settling the attempt clears it. No new enum values.worker-stop, local and paired-server, archives the worker's output before closing its terminal, bounded at 5 s and best effort. A later release then settles with that archive instead of "unavailable", andworker-retainkeeps it for a stopped worker.Testing
worker-turn-stops.test.tscovers:dispatch:waiterworker_donesuppressing itpending, andcheck --peekreturned 0 messages.escalation"Worker stopped without reporting" withstopReason: finished. A second turn gave exactly one more. A turn ending inworker_donegave none (worker_donewas the only new message).pnpm check:changed --maxWorkers=2: 20 checks passed.