Skip to content

feat(orchestration): supervise an adopted dispatch with --supervise - #13681

Closed
artile wants to merge 2 commits into
stablyai:mainfrom
tao-io:feat/adopted-dispatch-is-supervised
Closed

artile wants to merge 2 commits into
stablyai:mainfrom
tao-io:feat/adopted-dispatch-is-supervised

Conversation

@artile

@artile artile commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

orca orchestration dispatch --to <handle> --inject --supervise records the same supervised worker that worker-start --terminal records, so the whole worker-* set works on an adopted pane. Without --supervise, nothing changes.

Fixes part of #13678.

Evidence

Reproduced against the real RPC handlers on upstream/main (fe0ab305c4), with an in-memory orchestration DB, a run bound to term_coord, a ready task, and term_worker reporting a running agent plus a stable pane and process incarnation:

dispatch result: {"dispatch":{"id":"ctx_91e699f56ccc","assignee_handle":"term_worker",
  "assignee_pane_key":"tab_worker:term_worker",
  "process_incarnation":"runtime_test:term_worker:1","status":"dispatched",...},
  "injected":true}

worker_dispatches row: null
worker-list rows: []

worker-show error: dispatch_not_found: Worker Dispatch ctx_91e699f56ccc was not found.
worker-read error: dispatch_not_found: Worker Dispatch ctx_91e699f56ccc has no agent terminal.

worker-start --terminal on an injected lane:
  task_not_startable: Task task_4fdf9292ede7 is dispatched; only a ready Task can start.
worker-start --retry-of on an injected lane:
  task_not_startable: Task task_4fdf9292ede7 cannot retry from Dispatch ctx_91e699f56ccc.

workerStart writes a dispatch_contexts row and a worker_dispatches row; dispatch writes only the first. Every verb that fails above keys on the second: worker-show and worker-read at orchestration-worker-control.ts:35 and :170, worker-retain at orchestration-worker-release.ts:78, and worker-list through a JOIN worker_dispatches at db.ts:6147. worker-stop and worker-abandon already have a context_only branch for the same case, so two of six verbs handled it and four did not.

The lane could not be repaired after the fact. --retry-of fails for a second reason on top of the task status: the retry guard requires a prior worker row, and an injected lane has none.

This is the composition it breaks. On a machine where worker-start's launch path is unreliable, you start the agent by hand in a pane you have proven is alive, then hand it the task with dispatch --inject. We ran a wave that way on 2026-08-10 (v1.4.176). It delivers the task and gives the Run a mailbox, and it leaves the coordinator recomputing every lane's state from artifacts on disk.

Why the flag is opt-in

Making it unconditional would be a behavior change for existing callers, not a fix. worker-stop on a supervised worker closes the agent terminal (orchestration-worker-stop.ts:113-123), while worker-stop on an injected lane deliberately leaves the process alone. Flipping that silently would start closing hand-started panes for anyone following the documented low-level recipe in skill-guides/orchestration.md. #13678 discusses two further options — degrading the worker-show/worker-read read path, and unconditional supervision — that are still open. This PR only adds the choice.

What it does, and does not, touch

Supervision runs after injection has already proven an agent is present and the pane has stable identity, and it is a record write alone. The agent terminal is never created, closed, waited on, or written to a second time — the tests assert sendTerminalAgentPrompt was called once and createTerminal/closeTerminal not at all.

The adopted terminal is recorded with external ownership, the same as worker-start --terminal, so worker-release reports retained with reason external_terminal and never closes a pane the operator started.

--supervise requires --inject; without it there is no proven agent to supervise.

If the record write fails, the dispatch downgrades to unsupervised and reports superviseError rather than failing. The preamble is already in the worker's input by then and cannot be recalled, so failing the call would report a delivered task as undelivered.

Compatibility

Remote wire. Rule 1 of docs/reference/remote-wire-compatibility.md: supervise is a new optional param and supervised a new optional response field. An old client ignores the extra field; an old host ignores the param. Because the dispatch params schema is permissive, an old host would drop --supervise silently, so the handler reports supervised unconditionally and the CLI prints a warning when a --supervise request comes back unsupervised. No new opcode, no protocol bump.

Git providers, SSH, folder workspaces. No provider, path, or platform behavior is involved. The worktree id comes from showTerminal and is nullable, so a folder workspace or a terminal without one records null — the same column worker-start already leaves nullable. Host scope is carried through from the dispatch authority, so an SSH-hosted pane records the scope its authority reports.

Existing behavior. Plain --inject is byte-for-byte unchanged apart from the added supervised: false field.

Test plan

New: src/main/runtime/rpc/methods/orchestration-adopted-dispatch-supervision.test.ts, 8 cases — worker-show and worker-list report the adopted lane; the pane is not restarted or re-prompted; release retains the external terminal; worker_done settles the adopted worker through the ordinary report path; plain --inject stays unsupervised; --supervise without --inject is rejected; a failed injection supervises nothing; a failed record write downgrades instead of throwing.

npx vitest run src/main/runtime/rpc/methods/orchestration-adopted-dispatch-supervision.test.ts
  Test Files  1 passed (1)       Tests  8 passed (8)

npx vitest run src/main/runtime            # regression
  Test Files  259 passed | 1 skipped (260) Tests  3865 passed | 6 skipped (3871)

npx vitest run src/cli
  Test Files  59 passed (59)      Tests  761 passed (761)

pnpm lint                                   # clean
npx tsc --noEmit -p tsconfig.node.json      # No errors found

pnpm typecheck fails identically on an unmodified upstream/main in this environment (tsconfig.json(9,5): error TS5102: Option 'baseUrl' has been removed), so the per-project check above is the one that covers this diff.

Bundled skill guides were regenerated with config/scripts/generate-bundled-skill-guides.mjs --write after the skill-guides/orchestration.md edit.

`dispatch --to <terminal> --inject` delivers a task into an already-running
agent but records only a dispatch context, so `worker-show`, `worker-read`,
`worker-list`, and `worker-retain` never see the lane, and an already-dispatched
task cannot be started or retried into supervision afterwards.

`--supervise` writes the same supervised worker record `worker-start --terminal`
writes. It runs only after injection has proven an agent is present and the pane
has stable identity, and it is a record write alone: the terminal is never
created, closed, waited on, or written to a second time. The adopted terminal is
recorded as external ownership, so release retains it instead of closing a pane
the operator started by hand.

The response reports `supervised` unconditionally. The dispatch params schema is
permissive, so an older host would drop the flag without a word; the receipt lets
the CLI say the request was not honored.

Refs stablyai#13678
@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: 0be1c34e-8961-44b2-863a-a71c3105dd4f

📥 Commits

Reviewing files that changed from the base of the PR and between b0417fd and 83c60e3.

📒 Files selected for processing (2)
  • src/main/runtime/orchestration/db.ts
  • src/main/runtime/rpc/methods/orchestration-adopted-dispatch-supervision.test.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/main/runtime/orchestration/db.ts

📝 Walkthrough

Walkthrough

The change adds the --supervise flag to orchestration dispatch. Injected dispatches can record an already-running worker, its terminal metadata, and external terminal ownership. The RPC reports supervision status and persistence errors. Supervision requires --inject, while failed recording does not undo delivered injection. Documentation and tests cover supervised adoption, unsupervised injection, terminal release, worker settlement, validation, and injection failures.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description explains the change and testing, but it omits the required Screenshots, AI Review Report, and Security Audit sections. Add all required template sections, including No visual change, the AI review and cross-platform confirmation, and the security audit summary.
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely identifies the main change: adding --supervise support for adopted orchestration dispatches.
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.

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.

@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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/main/runtime/rpc/methods/orchestration.ts (1)

1232-1245: 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Validate --supervise before the dry-run return.

--dry-run --supervise returns successfully at Line 1245. It bypasses the validation at Lines 1257-1264, although --supervise requires --inject.

Move that validation before the dry-run branch. Add a dry-run regression test.


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 79169be8-02f1-4d7f-ba7a-34e7e2aa441f

📥 Commits

Reviewing files that changed from the base of the PR and between 72184b7 and b0417fd.

📒 Files selected for processing (8)
  • skill-guides/orchestration.md
  • src/cli/args.ts
  • src/cli/bundled-skill-guides.ts
  • src/cli/handlers/orchestration.ts
  • src/cli/specs/orchestration.ts
  • src/main/runtime/orchestration/db.ts
  • src/main/runtime/rpc/methods/orchestration-adopted-dispatch-supervision.test.ts
  • src/main/runtime/rpc/methods/orchestration.ts

Comment thread src/main/runtime/orchestration/db.ts Resolved
The worker can send worker_done between the prompt write and the record
write; settlement updates worker_dispatches WHERE state = 'ready', so a
row that does not exist yet is skipped, and the later insert would publish
a ready worker for a lane nobody is running.

Require status = 'dispatched' inside the attach transaction. The dispatch
handler already downgrades a failed record write to unsupervised, so a
worker that finishes that fast settles its task normally and the
coordinator is told why the lane is unsupervised.

Reported by CodeRabbit on stablyai#13681.
@artile

artile commented Aug 18, 2026

Copy link
Copy Markdown
Contributor Author

Moved to #15270 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 #15270 carries the code.

@artile artile closed this Aug 18, 2026
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.

3 participants