Skip to content

Start orchestration workers and remote workers through the launch executor - #26724

Merged
brennanb2025 merged 7 commits into
mainfrom
brennanb2025/p1b-workers-executor
Oct 9, 2026
Merged

brennanb2025 merged 7 commits into
mainfrom
brennanb2025/p1b-workers-executor

Conversation

@brennanb2025

@brennanb2025 brennanb2025 commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 4 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​590 0 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​590
Prod 7 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​353 $\color{#cf222e}{\Huge{\mathbf{−}}}$​197 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​156

ELI5

Orca has one host operation that starts agents (the launch executor). Orchestration workers (orca orchestration worker-start) and remote workers (a worker placed on another Orca server) still started their agents their own way, beside it. This PR sends them through the executor too. Nothing you see changes.

What Changed

The problem. A fresh worker's agent was started by the worker code itself: it created the worktree, asked the host whether it could run a chat session, and built either a chat session or a terminal. The launch executor does the same sequence for every other launch. Two copies of that sequence have to be kept in step by hand, and the worker copy was the last host producer (with automations) outside the shared one.

What is different for the user: nothing, by design. Same worker records, same tabs, same sidebar:

  • worker-start --worktree new-child with "new agent tabs open as chat" off: a terminal worker titled worker-<task>, the sidebar does not move, the task brief arrives as its first turn.
  • With chat on: a background chat-session worker; the brief arrives in the chat.
  • --worktree <existing> in both modes behaves the same; --terminal <handle> still reuses a running agent without starting anything.
  • A remote worker: the receiving server creates the worktree and starts a background terminal agent, as before.
  • If the host refuses to create a chat-session worker, the start still fails with the same error; it does not quietly become a terminal.
  • worker-show effects, the setup receipt, the stage rows and their order, and residual resources are byte-identical. They are durable dispatch records the coordinator reads.

The mechanism.

  1. placeWorkerAgent (local workers) keeps the --terminal reuse branch and otherwise calls executeAgentLaunch with the worker's own factories: the workspace factory is the existing createWorkerWorktree (agent-first exactly when the worker is a terminal), and the surface factory is the existing background chat session or the worker-<task> terminal with surfaceOwner: false, each recording the terminal_creating stage where it was recorded before.
  2. One new host-internal executor input, decidedMode: a worker decides its mode before its dispatch record exists and stores it there, so it hands that decision in instead of letting the executor decide again. For an existing worktree it already carries the host's answer, so the executor does not ask the host a second time; for a new worktree the executor asks after creating it, as the worker did.
  3. Remote workers: the receiving server's orchestration.federationAttachStart runs the executor terminalOnly (the input Start worktree.create's agent through the launch executor #26709 added) with federation's own factories: the same agent-first worktree create and the same background worker-<task> terminal. The request and reply are unchanged.
  4. The title, background presentation and "don't take the sidebar" choices stay inside each producer's own factory, so the shared factory contract gains no fields for them.

Why

This is phase 1b, step 3 of moving every fresh agent start onto one executor. Workers already shared the mode decision; this moves the sequencing too, so a later change to how launches are sequenced reaches workers without a second edit.

Why hand the decision in rather than let the executor decide: the worker's decision differs on purpose (only Claude and Codex are chat-session workers; other registered chat agents start as terminal workers) and is written to the dispatch record before the launch runs. Re-deciding inside the executor would either change which agents become chat workers or store a receipt that is not the one that ran.

Differences from the common pattern, labeled:

  • Intended: the task brief stays a later turn rather than the launch's first input, because worker reuse, redrive and terminal readiness all use the turn path.
  • Intended: the executor's chat-refused fallback to a terminal never fires for workers: the worker factory reports a refusal with its own error, so a refused chat worker fails as it always has. Tests pin this.
  • Temporary: the caller-decided mode (decidedMode). The type refuses it alongside the inputs the executor's own decision reads. It goes away when one planning step decides every launch (phase 2).
  • Intended for this phase: the tab title and background presentation stay in each producer's own factory instead of on the launch request.

Linked Issue

Maintainer change; part of the launch-unification work (no separate issue). Stacked on #26709.

Visual Proof

No visual change by design. Hidden test app with a stand-in Claude that logs what it receives; before = this PR's base (main's worker code), after = this PR.

worker-start --worktree <existing> with chat off: a new worker-<task> tab next to the workspace's agent, the brief arrives, the sidebar stays where it was.

Before After
w3-before-opened.png w3-after2-opened.png

worker-start --worktree new-child with "new agent tabs open as chat" on, and no real Claude behind the chat: the chat worker fails the same way on both, and neither falls back to a terminal.

Before After
w2-before-opened.png w2-after-opened.png

Testing

  • New: worker-start-launch-executor-parity.test.ts (refused chat worker fails with no terminal, in an existing and a new worktree; host asked once; host refusal in a created worktree gives the worker-<task> terminal with the same stages; exact terminal arguments; --terminal reuse starts nothing), worker-start-agent-placement-teardown.test.ts and federated-worker-agent-launch.test.ts (exact create arguments and effects, setup reported before a no-terminal failure, background worker-<task> terminal, still a terminal with chat on).
  • Existing: the 135 worker, federation, executor and launch test files pass unchanged.
  • Typecheck (tc:node) and CI static checks pass; CI is green on the final head.
  • Manual (hidden test app on macOS, stand-in agents, before vs after): new-child worker with chat off and on, existing-workspace worker with chat off and on, --terminal reuse, wait-for-setup, and a remote worker on a second local Orca server (existing remote workspace and a new top-level worktree). Replies, CLI text and worker-show records were identical after normalizing ids; the only worker-show difference was the captured terminal preview text, which also varies on the unchanged --terminal path.

Notes

  • SSH/remote: remote workers still run on the receiving server, which owns execution. An older receiving server keeps its own path; nothing is negotiated.
  • Folder workspaces: existing-folder workers take the same existing-worktree path as before.
  • Intended, log only: when a worker's chat default starts a terminal (for example, an agent without chat-session workers), the main log now gets the executor's one-line note, as every other launch does.
  • If a launch step after a worker's chat session was created ever throws, the placement now closes that session itself; the failed-start cleanup could not see it. Nothing throws there today; this keeps it that way.

The host's worktree.create handler now starts a requested agent (startupAgent,
or a linked startupDraft) through executeAgentLaunch instead of calling the
create directly. Nothing on the wire changes: the request, the reply and
agentTerminalHandle are the same, the agent is still the workspace's startup
terminal whatever the chat default says, and the create still delivers the
text itself (folded into the command at any length, a follow-up for agents
that read it after start, and the draft pasted unsent).

Adds three host-internal executor inputs: terminalOnly, the legacy-host prompt
policy, and a shared entry (createWorktreeWithStartupAgent) that host
producers can call in place of createManagedWorktree.
Problem: after worktree.create moved onto the launch executor, a create from
a linked issue (phone "create from issue", or a raw worktree.create with
startupDraft) could differ from before in two narrow cases. When the draft's
agent came from the settings default or from detection and its launch command
could not be built (for example unbalanced quotes in the saved agent
arguments), the workspace was recorded as created with that agent even though
it never started, and a background create opened no terminal at all instead
of its plain shell. When no agent was found, detection ran twice (an extra SSH
round trip on remote repos).

User-facing change: none intended; both cases now behave exactly as before
the executor move.

Mechanism:
- The entry hands the draft's chosen agent to the create as a main-internal
  startupDraftAgent, which steers only the draft; createdWithAgent stays what
  the caller sent. A draft that resolves no agent is created without the
  draft, so the create does not detect again.
- AgentLaunchExecution is a discriminated union: every normal launch must
  bring its surface factory, and a legacy-host launch must be terminal-only,
  bring a workspace factory, and cannot bring surfaces. The runtime guards
  the types replace are gone; the target kind is checked before any create.
- Legacy-host receipts follow the delivery module's rule: a blank prompt is
  no prompt, a submit folded into the launch command is handed-to-terminal,
  a post-start send the create does not await is unconfirmed (host-internal),
  a draft is not-delivered.
- The no-agent error lives with the legacy-host policy and is caught only by
  the shared entry.
- Tests: a real-runtime parity test (stored agent, terminal spawns,
  detection count vs the create alone, including the unbuildable plan),
  exact-argument checks over every non-agent startup field, compile-time
  checks for the union, and direct tests of the draft agent resolver.
Two comments stated that headless automations and federation already go
through createWorktreeWithStartupAgent; both still call
createManagedWorktree directly. Reword them as the plan. Comment-only.
…cutor

A fresh worker (new worktree or existing, terminal or structured) and a
federated worker on its receiving host now start their agent through
executeAgentLaunch with the worker's own workspace and surface factories.
The worker hands in the mode it decided before its dispatch record existed
(decidedMode), so the host is asked once and the stored receipt is the one
that ran. Effects, setup receipt, stage rows and their order are unchanged;
a refused structured worker still fails rather than becoming a terminal.
…er launch step strands

- decidedMode is now exclusive with terminalOnly and callerRendersStructured in the type, labelled temporary until one planner settles every launch.
- connectionId's doc says what is true: the executor carries it and nothing reads it yet.
- A worker launch that throws after its structured session exists discards that session itself, since the caller only tears down a returned placement.
- A federated create refuses a launch with no startup agent and narrows repo/name before recording its first stage.
- Tests: exact federated existing-path stages, a created-worktree host refusal that starts a worker terminal, and the stranded-session discard.
@brennanb2025

Copy link
Copy Markdown
Contributor Author

Review and QA summary (final head e551764)

The problem. Orchestration workers (orca orchestration worker-start) and remote workers (a worker placed on another Orca server) started their agents with their own copy of the launch sequence: create the worktree, ask the host whether it can run a chat session, then build a chat session or a terminal. Every other launch goes through the shared launch executor. Two copies of that sequence have to be kept in step by hand.

What changes for the user: nothing, by design. Workers start the same way, with the same tabs (worker-<task>, sidebar left alone), the same background remote-worker terminal, the task brief as the first turn, and the same worker-show records. A refused chat worker still fails instead of becoming a terminal.

Fixed during review (three review rounds; no blocking findings in any round):

  • The caller-decided mode (decidedMode) can no longer be combined, at compile time, with the inputs the executor's own decision reads (terminalOnly, callerRendersStructured). A compile-time test pins this, and the PR body labels the input temporary.
  • If a launch step after a worker's chat session was created ever throws, the placement now closes that session itself. Nothing throws there today.
  • Federation's create step now refuses a launch that did not ask for a terminal, and its unreachable argument check runs before it writes anything.
  • A comment overstated who reads connectionId; it is now accurate.
  • Added tests: a host refusal in a newly created worktree gives the same worker-<task> terminal and stage rows; exact federation stage lists.

Deferred (not blocking):

  • connectionId is carried but read by nothing. Removing it touches the base PR and the RPC factory, so it is left for a follow-up.
  • Make "a refused chat fails" an explicit executor input rather than the worker factory's own error type. Tests pin the behaviour today, and the executor is at 298 of its 300-line limit.
  • Give terminal-only launches a terminal-only factory type instead of federation's unreachable chat stub.
  • One extra mechanical conflict hunk with the open desktop stack in the executor's mode-decision block. Lint the merged tree for the line limit when the siblings land.
  • No end-to-end handler test for "create returned no terminal" or a createTerminal failure. The base had none either.

Verified:

  • 135 existing worker, federation, executor and launch test files pass unchanged, plus 4 new test files. tc:node, the CI static checks and full CI are green.

  • A readiness pass on the final diff found no P0–P2 issues.

  • Manual QA in a hidden macOS test app with stand-in agents, before (this PR's base) vs after. Covered:

    • new-child and existing-workspace workers with chat off and on
    • --terminal reuse
    • wait-for-setup
    • a remote worker on a second local Orca server, both to an existing workspace and to a new top-level worktree

    Replies, CLI text and worker-show records were identical apart from captured terminal preview text, which also varies on the unchanged --terminal path. Screenshots are in the PR body.

Not verified:

  • A real Claude chat-session worker: the stand-in cannot answer the chat handshake, so only identical failure was compared.
  • The remote worker's tab presentation on the server: the server has no window.
  • Windows, Linux and SSH hosts: the change is host-side TypeScript with no platform branches.
  • Rows W2/W4/W5/W6 on the fix heads: they ran on the first head. The later commits changed types, comments, a failure-only teardown and guard order.

@brennanb2025
brennanb2025 marked this pull request as ready for review October 9, 2026 03:29
…ers-executor

# Conflicts:
#	src/main/agent-launch/agent-launch-execution.ts
#	src/main/agent-launch/agent-launch-executor.ts
@brennanb2025
brennanb2025 requested a review from Jinwoo-H as a code owner October 9, 2026 06:37
@brennanb2025
brennanb2025 changed the base branch from brennanb2025/p1b-worktree-create-executor to main October 9, 2026 06:37
@coderabbitai

coderabbitai Bot commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 0685f248-0fb5-4ae1-9507-66d45bcd9eb1
📥 Commits

Reviewing files that changed from the base of the PR and between 46460d4 and f0c0a73.

📒 Files selected for processing (11)
  • src/main/agent-launch/agent-launch-decided-mode-contract.test.ts
  • src/main/agent-launch/agent-launch-execution.ts
  • src/main/agent-launch/agent-launch-executor.ts
  • src/main/agent-launch/agent-launch-surface-factories.ts
  • src/main/runtime/rpc/methods/orchestration-structured-worker-session.ts
  • src/main/runtime/rpc/methods/orchestration/federation/federated-worker-agent-launch.test.ts
  • src/main/runtime/rpc/methods/orchestration/federation/federated-worker-agent-launch.ts
  • src/main/runtime/rpc/methods/orchestration/federation/federation.ts
  • src/main/runtime/rpc/methods/orchestration/worker/worker-start-agent-placement-teardown.test.ts
  • src/main/runtime/rpc/methods/orchestration/worker/worker-start-agent-placement.ts
  • src/main/runtime/rpc/methods/orchestration/worker/worker-start-launch-executor-parity.test.ts

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


📝 Walkthrough

Walkthrough

The launch executor can use a caller-supplied mode receipt or resolve a mode during preflight. Local worker placement and federated attachment launch now use executor-based flows. Local placement handles structured-session teardown after launch failures. Federated launch creates or reuses a worktree and provisions a worker terminal. Added tests cover the mode contract, local placement paths, failure handling, and federated launch behavior.

Priority: ⬇️ Low

Merge Risk: ⚪ Minimal · up to f0c0a

No actionable launch regression is established; the PR is mergeable after normal checks.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 18.75% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 16 functions across 11 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
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.
Title check Passed The title clearly identifies the primary change: routing orchestration and remote workers through the shared launch executor.
Description check Passed The description is detailed and covers the core template sections, including the user impact, implementation, rationale, testing, visual proof, linked-work context, and compatibility notes. Some templ…
  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 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

Comment @coderabbitai help to get the list of available commands.

@brennanb2025

Copy link
Copy Markdown
Contributor Author

Retargeted to main and synced (end-of-review sync).

This PR was stacked on #26709. #26709 has now been squash-merged into main as d7e985c, so the base is now main, and main is merged into this branch at f0c0a73.

@brennanb2025
brennanb2025 merged commit 418c601 into main Oct 9, 2026
71 checks passed
brennanb2025 added a commit that referenced this pull request Oct 9, 2026
Main's orchestration workers (#26724) and worktree.create (#26709) pass
worktree-only launch factories, so createFolderWorkspace is optional on the
factory; a folder create without it is refused before anything is created.
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