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
Let workers follow up with their own finished helpers - #36663
A worker can start a helper (worker-start) and get its completion report. If the helper's agent was still running after it reported, sending it more work with orca orchestration send --to dispatch:<helper> failed: Orca told the worker to "omit --on and --terminal", though the worker had passed neither. Orca had already picked the helper's pane itself and then checked that pick as if the worker had typed --terminal. The orchestration guide promises that a send to a finished worker continues it, so the worker had no way forward.
The same code had two related holes. A closed helper skipped the ownership check entirely, so any worker could continue (and take over the reporting of) another worker's helper or coordinator work. And Orca could close a helper's leftover shell before deciding whether the sender was allowed to continue it at all.
What this changes for users
A worker can now send its own finished helper more work while the helper's agent still runs. The follow-up goes into the same pane (or the same open chat) and the worker gets the usual follow-up receipt. Sending again later works the same way.
A worker still keeps its helpers after it is itself continued: by a follow-up from its coordinator, or by its coordinator restarting it on its own Orca pane (worker-start --task … --terminal <its pane>). New work for the helper reports to the worker's current Dispatch.
A helper whose start failed before it got an agent still belongs to the worker that asked for it, and a send starts it fresh, as before. A failed coordinator attempt to continue a helper doesn't take the helper away from its worker; a coordinator continuation that actually ran does.
A worker can't continue a helper it didn't start, or coordinator work. It gets task_not_found, with a message that names the Dispatch it addressed, says only the coordinator or the worker that started it can give it more work, and points to worker-start --spec for new helper work. Nothing is changed when this happens. On main this refusal either never came (closed helpers) or came with the misleading "omit --on and --terminal" text (running helpers).
Permission is now checked before Orca touches any pane. A sender that isn't allowed no longer closes a leftover shell, and the nested-worker depth limit is checked before cleanup too.
If Orca has already asked to close a helper's leftover shell and a later check then refuses the follow-up (for example the worker finished in the meantime, or the combined task text is too long), the error now says the shell close was requested. It no longer claims that nothing happened.
Unchanged: coordinators' follow-ups, reopening or freshly starting a worker's closed helper, native chat helpers, and the refusal of --terminal/--on passed by a worker itself.
How it works
The follow-up send now hands worker-start's owner only what the caller actually asked for. Orca's choice of pane is resolved privately, after the caller's permission has been checked. "Is this my helper?" is answered from saved records only. The helper's owner is the creator of the Dispatch that last actually held its agent, or, if no agent ever started, the creator of the original request. The sender qualifies if it is that creator, or reaches it through its own saved follow-up links or exact recorded takeovers of the same pane. Each check reads only the rows on that chain (bounded by tests at 10× sizes), and nothing new is saved: no new fields, schema, settings or protocol changes.
Intended differences
A delegated worker may continue only its own helpers. In the common pattern any agent can send a follow-up to any non-root agent, and the completion stays with the agent that spawned it; one variant re-parents a resumed agent to whoever resumed it, with no ownership check. In Orca a follow-up's new task, and its report, go to the sender. So letting a worker continue another worker's helper would take over that helper's reporting. This keeps the shipped rule that a worker never takes coordinator tasks or another party's pane.
A worker that the coordinator restarts on a terminal Orca didn't create (worker-start --task … --terminal <user's own agent>) doesn't keep the helpers it started before the restart, because Orca saves no link between the two assignments of an external terminal. This only arises with nested workers above the default depth, a restart onto a user-launched terminal, and a later follow-up to a helper from before the restart. The coordinator can still continue that helper, and the restarted worker can start new helper work; the refusal says so. Before Let send talk to a worker in any state, reopening closed workers for follow-ups #36533 every such send was refused; on main, closed ones went through only because the ownership check was missing.
Helper creation and continuation stay local to the creator's host so completion reports can return to it. Remote and mixed-version callers keep their existing path.
Reproduced the original refusal on main through the real CLI command, RPC parsing and SQLite, and showed it fixed on the branch.
Focused integration tests run the real orca CLI command through the RPC handlers into SQLite (only terminal I/O and the agent process are simulated). They cover in-place continuation (twice), coordinator controls, closed reopen/fresh, native chat visible/closed, foreign helper and coordinator-work refusal with no side effects, explicit flag refusal, creator settling before and after shell cleanup, continued and restarted workers, failed and real coordinator takeovers, held mail continued after a helper reports, depth and prompt-size refusals after cleanup, and read-count bounds at N and 10N.
Review path: full (orchestration ownership and re-entry). QA: CLI/orchestration tests row; no app run is needed because no UI, process launch or OS behavior changed.
…closing a leftover shell say so
- A worker's own-helper check now walks back from the caller through follow-ups and through exact pane takeovers recorded in the terminal's ordered owner history, same Run at every hop, so the documented reopen-on-the-same-agent recovery keeps the worker's helpers while a stop in another Run does not.
- The helper's owner is the creator of the Dispatch that last took custody of its agent, so a coordinator attempt that never got an agent no longer takes the helper away; a real coordinator takeover still does. With no custody at all the follow-up is refused.
- The refusal names the Dispatch the sender addressed (and its latest work when that differs) and says what to do instead.
- Follow-ups check nesting depth before placement can close a leftover shell; if a later check refuses after that close was requested, the error keeps its code and cause but says the close was requested instead of claiming no effects.
…in the helper follow-up CLI test
Recovery-flow takeover (live, closed, unreadable history), takeover plus fresh follow-up composition, a stop in another Run, failed coordinator attempts, a real coordinator takeover, depth before and after release, refusals after a leftover-shell close, held-mail follow-through from own and foreign senders, and the ancestry read bound now counting custody-history reads. Error data is asserted, not only text.
When no Dispatch in a helper's lineage ever took custody of an agent, its owner is the creator of the first Dispatch in its follow-up chain (every link read, same Run, no cycles), checked through the same caller continuation as before. A worker can again continue its own helper whose start failed before an agent came up, including after coordinator attempts that also never got one; a real coordinator takeover still blocks it. The round-1 denial for this case is gone. The post-release refusal rewrite names the message convention it relies on.
Tests: terminal-create and native setup-gate failures, failed coordinator attempts before a continued worker's retry through both addresses, takeover then an unplaced attempt, coordinator/foreign/missing/cyclic/cross-Run origins, and held mail on a failed coordinator attempt. The CLI fixture moves to a shared test-support file and ownership cases to their own file, which keeps each under the line limits.
The own-helper ancestry also follows an external pane's previous holder. Each check reads the pane's complete assignment history once, from dispatch_contexts through a new full-history index on pane leaf and host (created on every open, so existing databases get it too), reading the exact-host and unknown-host cohorts and joining each holder's own custody row. Custody rows are inserted at acquisition, so original-acquisition rowids order the holders; timestamps and acceptance order are never used. The immediate predecessor is fixed before any check: if any holder lacks its own orderable row (a direct dispatch to the same agent, a backfilled, transferred or unreadable row, an unknown host), no edge is derived. The predecessor must then be the same process, same host and settled, and the walk keeps same-Run-per-hop and its seen set. The derived order lives only for that check. External rows stay external and gain no cleanup.
Tests: live and closed recovery on the user's terminal with equal timestamps, composition with a follow-up in a new pane and a takeover, another Run's assignment accepted after but acquired before the recovery, a real direct dispatch in between, replaced process, other host, backfilled and unreadable rows, held mail, a restart with the index rebuilt on an existing database, and read/plan contracts for unrelated history, one long pane chain and two panes joined by a follow-up at N and 10N. Ownership and core test files consolidated.
… check
The own-helper walk no longer scans every custody row's owner history for each ancestor. It reads the Dispatch's own row by owner first; for a former holder it reads the custody rows of that Dispatch's exact process and host through the identity index, keeps the one whose ordered owners name it, and takes the owner right before it. Each identity cohort, decoded owner history and pane order is read at most once per check and dropped when the check returns. The shared former-owner reader and target routing are unchanged.
Tests: the call-count contract is replaced by read contracts over the actual SQL: a four-recovery chain reads one identity range visiting one row whether 40 or 400 unrelated Dispatch and custody rows sit beside it, with indexed plans and no former-owner scan; a 3- and 30-step follow-up chain reads one identity range and decodes the same number of histories.
A direct dispatch claims the user's pane in the Dispatch row it inserts, with no worker row and no custody row, so its insertion order bounds where it can sit. The pane history now reads each holder's Dispatch insertion order and whether it has a worker row, treats only that claim shape as a direct claim, and keeps the latest claim's insertion as a floor: an earlier holder is reachable only when it was inserted after every direct claim on the pane. Insertion order is never compared with custody order. Every other holder whose place is unproven still blocks the whole pane, and the floor is computed once per pane per check.
Tests: live and closed recovery after a direct dispatch before the worker (also from another Run), the claim between a worker and its recovery blocking only that edge while the next recovery keeps the reopened worker's own helper, a supervised Dispatch without its own custody row still blocking, and the history read contracts extended with old claims and the worker-row probe.
Drop the coordinator row from the refuse-after-release cases, which takes the same follow-up path as the worker's, and give the three-caller zero-effects case the refusal each caller gets.
…ch former holder once per check
A worker re-placed on a terminal it never held in saved custody no longer
inherits helpers from an earlier start there: the pane-history derivation
and its index are gone. Former custody is found by exact process through
one membership map per identity, so the walk is linear in ancestors and
rows.
…inear identity and probe contracts
The external recovery tests and their pane-history contracts go. One case
pins that a worker re-placed on the user's own terminal is refused its
earlier helper with no effects while the coordinator still continues it.
The follow-up chain contract now grows both ancestors and same-process
rows and bounds field reads and Dispatch probes; the never-placed matrix
bounds the walk to the first request.
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 2 remain after this review.
Walkthrough
Helper follow-ups now validate creator and custody lineage, defer placement to worker start, and track whether shell closure was requested when later errors occur. The change adds cached previous-custodian lookup and updates follow-up planning, placement, and worker-start handling. CLI integration tests cover continuation, ownership checks, delivery behavior, shell-release effects, and database read counts.
Merge Risk: Minimal · up to 41c21
No actionable issue remains identified; the change is ready for normal merge checks.
Pre-merge checks: 4 · 1
Failed checks: 1 warning
Check name
Status
Explanation
Resolution
Docstring Coverage
Docstring coverage is 72.22% 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: 4 passed
Check name
Status
Explanation
Title check
The title clearly describes the main change: allowing workers to send follow-up work to their own finished helpers.
Description check
The description is detailed and covers the problem, user-visible changes, implementation approach, rationale, linked issue, testing, and review scope. It does not use every template heading or include…
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 is detailed and covers the problem, user-visible changes, implementation approach, rationale, linked issue, testing, and review scope. It does not use every template heading or include the checklist and AI disclosure, but the required information is mostly present.
Full details: Docstring Coverage
Explanation
Docstring coverage is 72.22% 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 18 functions across 10 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.
The reason will be displayed to describe this comment to others. Learn more.
Caution
Some comments are outside the diff and can’t be posted inline due to GitHub limitations.
⚠️ Outside diff range comments (2)
Minor · Report cleanup effects when a follow-up loses the claim. · worker-follow-up.ts:128-133
src/main/runtime/rpc/methods/orchestration/messaging/worker-follow-up.ts:128-133 Minor · Data Integrity & Integration · Quick win
Report cleanup effects when a follow-up loses the claim.
When an owned leftover shell is eligible for reuse, placement can request or complete its release before createStartingWorkerDispatch(...) throws follow_up_claimed. This branch returns a bare steer result before afterShellRelease reports releasedShellOf, so the losing caller receives no indication that its helper shell may already have changed state. Preserve that release effect in the steer response, or defer the release until the follow-up claim succeeds.
Minor · Use the helper creator as the follow-up caller… · helper-follow-up-cli.integration.test.ts:316-324
src/main/runtime/rpc/methods/orchestration/worker/helper-follow-up-cli.integration.test.ts:316-324 Minor · Functional Correctness · Quick win
Use the helper creator as the follow-up caller in the foreign case.
The foreign case creates the helper under term_other but sends the follow-up from term_worker. The ownership guard can reject that request with task_not_found, causing the test to stop before it creates or inspects held mail.
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 6 remain after this review.
…rver
The CLI now reaches the test runtime as it reaches the app: through the
metadata the real RPC server publishes, its socket, dispatcher and error
mapping, instead of module mocks of the runtime client and printer.
Recorded SQL rows are parsed into a named row type before their reads
are counted.
The SQL trace spies on each statement method through its own typed
signature and reads plan rows as the rows they are; the Dispatch probe
trace spies on each read separately; the never-placed matrix picks its
requester and corruption by origin.
The reason will be displayed to describe this comment to others. Learn more.
Follow-up Comments
Keep the shell-closure notice for reopen refusals.
153-172: Minor · Functional Correctness · Quick win
Keep the shell-closure notice for reopen refusals.
When release.requested runs before the reopen attempt, the refusals worker_asleep, worker_agent_unavailable, worker_unreachable, and worker_reopen_failed pass through afterShellRelease unchanged. They carry no effectsApplied field, so the CLI does not learn that Orca asked to close the finished agent's shell.
Scope the fix to the reopen refusal path. Do not add "The follow-up did not start" to every error that reaches this catch. The inspected code does not show that for worker_reopen_failed, and it does not cover errors thrown after placement.
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 5 remain after this review.
The problem. A worker that started a helper couldn't send that helper more work once the helper reported done while its agent was still running. orca orchestration send --to dispatch:<helper> failed with "omit --on and --terminal", though the worker passed neither: Orca picked the helper's pane itself and then checked its own pick as if the worker had typed --terminal. The same code also skipped the ownership check for closed helpers, so any worker could take over another worker's helper, and it could close a helper's leftover shell before checking who was asking.
What changes for users. A worker can now continue its own finished helper in the same pane, again and again. It keeps that right after its coordinator continues it, and after a restart on its own Orca pane. A worker that sends to someone else's helper, or to coordinator work, gets a clear refusal, with nothing changed. Permission is checked before any pane is touched. If a later check refuses after Orca already asked to close a leftover shell, the error now says so instead of claiming nothing happened. Full list in the PR description.
What the review changed (5 rounds; each design question went to a three-model panel):
A worker's own helpers now include those of the earlier Dispatches it continued, through saved follow-ups or exact recorded pane takeovers, hop by hop within one Run. This keeps the documented "reuse a proven existing agent" recovery working.
Helper ownership comes from the Dispatch that actually holds the agent. So a coordinator attempt that failed before getting an agent no longer takes the helper away. A helper whose start never got an agent still belongs to the worker that asked for it, as on main.
The nested-depth limit is checked before cleanup. Refusals after a committed shell close report that the close happened.
The refusal text now names the addressed Dispatch and says what to do instead.
Lookups now go through existing indexes: no full-table scan per ancestor. Tests bound the reads at N and 10N.
Removed: an attempt to infer continuity for workers restarted on a terminal Orca didn't create. It kept producing wrong answers (a later direct dispatch, a remote Run's attachment), and Orca saves no link between those two assignments. That narrow case is refused and labelled intended in the PR description. The launcher ruled it acceptable, since no shipped behavior gets worse.
Verified. Real orca CLI argv → the runtime's real RPC socket server and handlers → SQLite integration tests: the original refusal reproduced on main and passes on the branch. The suite covers in-place continuation, coordinator controls, closed reopen/fresh, native chat visible/closed, foreign and coordinator-work refusals with zero effects, explicit-flag refusal, creator races before and after cleanup, continued and restarted workers, failed vs real coordinator takeovers, held mail after a report, post-cleanup refusals, and read bounds. 70/70 named tests pass on the final head. Reference comparison: 9 differences, all labelled intended. Performance pass: every added piece bounded and tested. Readiness checklist: no P0–P2. CI green on 41c214b (34 passed, 17 skipped).
Not verified. No running-app QA: the QA table puts CLI/orchestration on tests, and no UI, process launch or OS behavior changed. No real agent CLI was exercised.
Merge and CI repairs.f73489f merges origin/main (1da1099). There were no conflicts, and main touched none of this PR's files. Four test-only commits followed to satisfy CI's test-quality gates: a fixed timestamp in place of the wall clock; the tests now drive the CLI through the real runtime RPC server instead of a module mock; type assertions removed; and one type annotation fixed. A continued reviewer checked each one: no shipped code changed and no coverage was lost.
Deferred (test-only, P3). There's no CLI-level case for an externally placed worker's follow-up successor continuing its helpers (a scratch run passes). The tests run about 4× the production lines, and a few rows overlap.
Found on main, not changed here (outside this fix):
When a reopen falls back to a fresh agent, the earlier-work text it appends skips the prompt-size check.
Held mail is credited to its first sender. So a non-owner's message can hold up the owner's own mail until a resend.
The "mail did not reach the finished worker" notice ends with a doubled period.
A direct worker-start --task retry still requires the exact current creator. A continued worker can't retry its own earlier helper's Task that way.
A send to an old Dispatch address doesn't follow an external-terminal reassignment.
Direct dispatches (orchestration dispatch --inject, automatic dispatch) save no host scope.
worker_not_restartable and worker_unverifiable aren't passed through the RPC boundary, so CLI callers see runtime_error and lose the error data. For this PR that affects one rare refusal after a shell close: the sentence arrives, but effectsApplied doesn't.
The local socket's message cap (1,048,576 bytes) is below the task-spec cap (1,214,464), so an oversized body gets a misleading "mismatched response id" error instead of the prompt-size refusal.
For Brennan's review:
worker-start-authority.ts:150continuesDispatch: what counts as "the same worker" (saved follow-ups and recorded takeovers only).
workers.ts:120: permission, then depth, then Orca's own placement, in that order.
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.
The problem
A worker can start a helper (
worker-start) and get its completion report. If the helper's agent was still running after it reported, sending it more work withorca orchestration send --to dispatch:<helper>failed: Orca told the worker to "omit --on and --terminal", though the worker had passed neither. Orca had already picked the helper's pane itself and then checked that pick as if the worker had typed--terminal. The orchestration guide promises that a send to a finished worker continues it, so the worker had no way forward.The same code had two related holes. A closed helper skipped the ownership check entirely, so any worker could continue (and take over the reporting of) another worker's helper or coordinator work. And Orca could close a helper's leftover shell before deciding whether the sender was allowed to continue it at all.
What this changes for users
worker-start --task … --terminal <its pane>). New work for the helper reports to the worker's current Dispatch.task_not_found, with a message that names the Dispatch it addressed, says only the coordinator or the worker that started it can give it more work, and points toworker-start --specfor new helper work. Nothing is changed when this happens. On main this refusal either never came (closed helpers) or came with the misleading "omit --on and --terminal" text (running helpers).--terminal/--onpassed by a worker itself.How it works
The follow-up send now hands
worker-start's owner only what the caller actually asked for. Orca's choice of pane is resolved privately, after the caller's permission has been checked. "Is this my helper?" is answered from saved records only. The helper's owner is the creator of the Dispatch that last actually held its agent, or, if no agent ever started, the creator of the original request. The sender qualifies if it is that creator, or reaches it through its own saved follow-up links or exact recorded takeovers of the same pane. Each check reads only the rows on that chain (bounded by tests at 10× sizes), and nothing new is saved: no new fields, schema, settings or protocol changes.Intended differences
worker-start --task … --terminal <user's own agent>) doesn't keep the helpers it started before the restart, because Orca saves no link between the two assignments of an external terminal. This only arises with nested workers above the default depth, a restart onto a user-launched terminal, and a later follow-up to a helper from before the restart. The coordinator can still continue that helper, and the restarted worker can start new helper work; the refusal says so. Before Let send talk to a worker in any state, reopening closed workers for follow-ups #36533 every such send was refused; on main, closed ones went through only because the ownership check was missing.This is tracked in #36533.
Verification
orcaCLI command through the RPC handlers into SQLite (only terminal I/O and the agent process are simulated). They cover in-place continuation (twice), coordinator controls, closed reopen/fresh, native chat visible/closed, foreign helper and coordinator-work refusal with no side effects, explicit flag refusal, creator settling before and after shell cleanup, continued and restarted workers, failed and real coordinator takeovers, held mail continued after a helper reports, depth and prompt-size refusals after cleanup, and read-count bounds at N and 10N.