Skip to content

Stop listing a worker as retained after its follow-up took its terminal - #36978

Merged
Jinwoo-H merged 4 commits into
mainfrom
orch-worker-list-transferred-row
Nov 2, 2026
Merged

Jinwoo-H merged 4 commits into
mainfrom
orch-worker-list-transferred-row

Conversation

@Jinwoo-H

@Jinwoo-H Jinwoo-H commented Nov 1, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​192 0 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​192
Prod 2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​14 $\color{#cf222e}{\Huge{\mathbf{−}}}$​4 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​10

Summary

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:

  • Before: state=succeeded liveness=unverifiable terminal=term_77e9... terminalState=retained attention=unverifiable,root_completion
  • 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.

@coderabbitai

coderabbitai Bot commented Nov 1, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review.

Recent 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: 6e54382a-cf73-4cc3-baff-4a822156d2f6
Commits

Reviewing files that changed from the base of the PR and between 8d783dd and e0252f7.

Files selected for processing: 2
  • src/main/runtime/orchestration/db/worker-terminal/worker-terminal-inventory-counts.ts
  • src/main/runtime/rpc/methods/orchestration/worker/worker-list-pagination.test.ts

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: Passed 3 · Failed 2

Failed Failed checks: 2 warnings

Check name Status Explanation Resolution
Description check Warning 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 Warning 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 Passed checks: 3 passed
Check name Status Explanation
Title check Passed 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 Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed 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.

Share

@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
  • 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: 2dbb0214-27b9-41cc-8b2e-8c943c3420a9
Commits

Reviewing files that changed from the base of the PR and between ff8b76e and 8d783dd.

Files selected for processing: 4
  • src/main/runtime/orchestration/db/worker-terminal/worker-terminal-inventory-counts.ts
  • src/main/runtime/orchestration/db/worker-terminal/worker-terminal-listing.ts
  • src/main/runtime/rpc/methods/orchestration/worker/worker-follow-up.test.ts
  • src/main/runtime/rpc/methods/orchestration/worker/worker-list-pagination.test.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 2 remain after this review.

Comment on lines +47 to +48
export const WORKER_TERMINAL_HANDED_ON_SQL = `r.id IS NULL AND EXISTS (
SELECT 1 FROM dispatch_contexts f WHERE f.follow_up_of_dispatch_id = d.id)`

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.

Major · Functional Correctness · Heavy lift

Supported by static analysis

Script executed:

set -eu
printf '%s\n' '--- PR diff ---'
git diff --no-ext-diff --unified=80 30242d175939b01aa8d2b14e91b0d1efe464f4bf 8d783dd3fd710539dd8d48589f0102d20e8d14b5 -- src/main/runtime/orchestration/db/worker-terminal/worker-terminal-inventory-counts.ts src/main/runtime/orchestration/db/dispatch-context/worker-follow-up-lineage.ts src/main/runtime/orchestration | sed -n '1,260p'
printf '%s\n' '--- changed inventory file ---'
nl -ba src/main/runtime/orchestration/db/worker-terminal/worker-terminal-inventory-counts.ts | sed -n '1,220p'
printf '%s\n' '--- lineage resolver ---'
nl -ba src/main/runtime/orchestration/db/dispatch-context/worker-follow-up-lineage.ts | sed -n '1,280p'
printf '%s\n' '--- worker-start terminal references ---'
rg -n -F --glob '*.{ts,tsx}' -e 'worker-start' -e '--terminal' -e 'follow_up_of_dispatch_id' src/main/runtime/orchestration src/main | sed -n '1,320p'

Repository: stablyai/orca

Length of output: 42020


Script executed:

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.

@Jinwoo-H
Jinwoo-H merged commit d7ea02d into main Nov 2, 2026
48 checks passed
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.

1 participant