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
Stop listing a worker as retained after its follow-up took its terminal - #36978
When orchestration send starts a follow-up that takes over a finished worker's terminal, worker-list kept showing the original worker as terminalState=retained with the old terminal handle, even after the follow-up released and closed that terminal. A coordinator reading the list could think the original worker was still open, or target a handle it no longer owns.
The rule is now: a Dispatch that owns no terminal resource and has a follow-up running in its exact process (same process incarnation and host scope) handed its terminal to that follow-up. Its row shows no terminal handle, no pane and no terminal state, and the counts no longer include it as retained. The check is an indexed lookup on the follow-up link (follow_up_of_dispatch_id), in the same SQL the listing and counts already run. A follow-up that opened a fresh terminal leaves the original row unchanged, including a legacy Dispatch with no resource of its own.
What the coordinator sees for the original worker, after the follow-up was released:
After: state=succeeded liveness=unverifiable attention=unverifiable,root_completion (no terminal, no terminalState)
Liveness stays unverifiable because nothing proves the original's own process ended. The follow-up row is unchanged. worker-release on the original still returns retained / ownership_transferred, and send to the original still reopens the latest follow-up, as on main. RPC field shapes are the same (agentTerminalHandle and terminalState are already nullable), so older CLIs just show the row without a terminal.
Testing
worker-follow-up.test.ts: after a follow-up takes the terminal, the original row has no handle or state and only the follow-up is counted. Through a chained A to B to C and C's release, A and B still show no terminal, and --terminal-state retained returns nothing. It fails on main.
worker-list-pagination.test.ts: rows fetched for one listed worker are the same next to 0 and 10,000 unrelated handed-on terminals. Both the listing and the counts statements use idx_dispatch_contexts_follow_up_of with no table scan (query plan check). A resource-less worker whose follow-up started fresh in another terminal stays listed as retained. The read-statement budgets are unchanged.
Focused orchestration RPC, db, fleet projection and CLI suites; pnpm tc:node; oxlint, anti-slop, changed-code quality, ratchets and the other pr.yml check scripts.
Real dev app run (background launch, isolated profile, Claude workers): start a worker, send a follow-up, release the follow-up, then list, release the original, and send to the original. Before and after are shown above.
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 1 remain after this review.
Walkthrough
Inventory and listing queries now return null terminal fields for dispatches whose terminal was handed to a follow-up dispatch. Other dispatches retain the existing fallback values. Tests cover terminal ownership across follow-ups and release, listing counts, retained-terminal filtering, SQLite read counts, and query plans.
Merge Risk: Minimal · up to e0252
Same-process follow-ups no longer show the former owner’s terminal. No PR-introduced merge-blocking risk was established; the separate pre-existing transfer misclassification remains.
Pre-merge checks: 3 · 2
Failed checks: 2 warnings
Check name
Status
Explanation
Resolution
Description check
The description explains the behavior change, rationale, implementation, and testing, but it omits most required template sections, including Linked Issue, Visual Proof or an explicit N/A, AI Disclosu…
Add the missing template sections and required information. Include a linked issue, visual proof or an explicit N/A with a reason, AI disclosure when applicable, review and compatibility notes, the agent skill boundary checkbox, and the che…
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 clearly and concisely describes the main change: preventing a worker from appearing retained after its follow-up takes the terminal.
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: Description check
Explanation
The description explains the behavior change, rationale, implementation, and testing, but it omits most required template sections, including Linked Issue, Visual Proof or an explicit N/A, AI Disclosure, Review, Agent skill upstream boundary, Notes, and Checklist.
Resolution
Add the missing template sections and required information. Include a linked issue, visual proof or an explicit N/A with a reason, AI disclosure when applicable, review and compatibility notes, the agent skill boundary checkbox, and the checklist status. Rename or expand Summary into the required ELI5, What Changed, and Why sections.
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 2 functions across 4 files.
Resolution
Write docstrings for the functions missing them to satisfy the coverage threshold.
Finishing Touches
Generate docstrings
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.
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 2 remain after this review.
set -eu
printf'%s\n''--- terminal transfer ---'
nl -ba src/main/runtime/orchestration/db/worker-terminal/worker-terminal-transfer.ts | sed -n '1,190p'printf'%s\n''--- terminal resource store ---'
nl -ba src/main/runtime/orchestration/db/worker-terminal/worker-terminal-resource-store.ts | sed -n '1,180p'printf'%s\n''--- dispatch row writer ---'
nl -ba src/main/runtime/orchestration/db/dispatch-row-writer.ts | sed -n '1,170p'printf'%s\n''--- worker-start mutation and dispatch callers ---'
rg -n -F --glob '*.ts' -e 'transferWorkerTerminal' -e 'transferTerminal' -e 'owner_dispatch_id' -e 'createStartingWorkerDispatch' -e 'followUpOf' -e 'follow_up_of_dispatch_id' src/main/runtime/rpc/methods/orchestration/worker src/main/runtime/orchestration/db/worker-terminal src/main/runtime/orchestration/db/worker-dispatch src/main/runtime/orchestration/db | sed -n '1,280p'printf'%s\n''--- targeted worker-start terminal tests ---'
nl -ba src/main/runtime/structured-chat-worker-start.test.ts | sed -n '80,230p'
nl -ba src/main/runtime/orchestration/coordinator-held-worker-census.test.ts | sed -n '1,180p'
Repository: stablyai/orca
Length of output: 41972
Script executed:
set -eu
printf'%s\n''--- transfer statement ---'
nl -ba src/main/runtime/orchestration/db/worker-terminal/worker-terminal-resource-store.ts | sed -n '168,255p'printf'%s\n''--- worker dispatch authority transfer caller ---'
nl -ba src/main/runtime/orchestration/db/worker-dispatch/worker-dispatch-authority.ts | sed -n '90,175p'printf'%s\n''--- starting worker dispatch ---'
nl -ba src/main/runtime/orchestration/db/worker-dispatch/worker-dispatch-start.ts | sed -n '1,215p'printf'%s\n''--- local worker-start dispatch ---'
nl -ba src/main/runtime/rpc/methods/orchestration/worker/local-worker-start-dispatch.ts | sed -n '1,125p'printf'%s\n''--- worker-start terminal transfer references ---'
rg -n -F --glob '*.ts' -e 'findTransferableWorkerTerminalResource' -e 'transferWorkerTerminalResourceStatement' -e 'terminalOwnership' -e 'terminalOwnership:' -e 'followUpOf:' src/main/runtime/rpc/methods/orchestration/worker src/main/runtime/orchestration/db | sed -n '1,260p'
Repository: stablyai/orca
Length of output: 25965
Script executed:
set -eu
printf'%s\n''--- local worker-start authority call ---'
nl -ba src/main/runtime/rpc/methods/orchestration/worker/local-worker-start.ts | sed -n '205,275p'printf'%s\n''--- terminal list state machine ---'
rg -n -F --glob '*.ts' -e 'function deriveWorkerTerminalListState' -e 'deriveWorkerTerminalListState' src/main/runtime/orchestration | sed -n '1,80p'
nl -ba src/main/runtime/orchestration/worker-terminal-ownership.ts | sed -n '1,220p'printf'%s\n''--- worker-start follow-up resolution ---'
rg -n -F --glob '*.ts' -e 'followUp =' -e 'followUp:' -e 'resolve.*Follow' -e 'terminalOwnership' src/main/runtime/rpc/methods/orchestration/worker/local-worker-start.ts src/main/runtime/rpc/methods/orchestration/worker | sed -n '1,180p'
Repository: stablyai/orca
Length of output: 14453
Account for terminal transfers without a follow-up link.
The external worker-start --terminal path moves the resource to the new dispatch and records the former owner in prior_owner_dispatch_ids. It does not set follow_up_of_dispatch_id unless the start also has follow-up context. The former dispatch therefore has no joined resource, but this predicate does not match it. The scan can classify that row as retained.
Extend this condition to recognize the former owner through the resource's recorded owner history, using the same exact owner relationship as resolveWorkerLineage, without scanning unrelated dispatch history.
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.
Summary
When
orchestration sendstarts a follow-up that takes over a finished worker's terminal,worker-listkept showing the original worker asterminalState=retainedwith the old terminal handle, even after the follow-up released and closed that terminal. A coordinator reading the list could think the original worker was still open, or target a handle it no longer owns.The rule is now: a Dispatch that owns no terminal resource and has a follow-up running in its exact process (same process incarnation and host scope) handed its terminal to that follow-up. Its row shows no terminal handle, no pane and no terminal state, and the counts no longer include it as retained. The check is an indexed lookup on the follow-up link (
follow_up_of_dispatch_id), in the same SQL the listing and counts already run. A follow-up that opened a fresh terminal leaves the original row unchanged, including a legacy Dispatch with no resource of its own.What the coordinator sees for the original worker, after the follow-up was released:
state=succeeded liveness=unverifiable terminal=term_77e9... terminalState=retained attention=unverifiable,root_completionstate=succeeded liveness=unverifiable attention=unverifiable,root_completion(no terminal, no terminalState)Liveness stays unverifiable because nothing proves the original's own process ended. The follow-up row is unchanged.
worker-releaseon the original still returnsretained / ownership_transferred, andsendto the original still reopens the latest follow-up, as on main. RPC field shapes are the same (agentTerminalHandleandterminalStateare already nullable), so older CLIs just show the row without a terminal.Testing
worker-follow-up.test.ts: after a follow-up takes the terminal, the original row has no handle or state and only the follow-up is counted. Through a chained A to B to C and C's release, A and B still show no terminal, and--terminal-state retainedreturns nothing. It fails on main.worker-list-pagination.test.ts: rows fetched for one listed worker are the same next to 0 and 10,000 unrelated handed-on terminals. Both the listing and the counts statements useidx_dispatch_contexts_follow_up_ofwith no table scan (query plan check). A resource-less worker whose follow-up started fresh in another terminal stays listed as retained. The read-statement budgets are unchanged.pnpm tc:node; oxlint, anti-slop, changed-code quality, ratchets and the other pr.yml check scripts.