From c408634ada74b0fd7ea8f4aaa726f3aa56a32f95 Mon Sep 17 00:00:00 2001 From: Jinwoo Hong <73622457+Jinwoo-H@users.noreply.github.com> Date: Sat, 31 Oct 2026 18:07:30 -0400 Subject: [PATCH] Orchestration: keep open workers started in a new workspace (#36782) --- skill-guides/orchestration.md | 13 +++++++---- src/cli/bundled-skill-guides.ts | 13 +++++++---- .../handlers/orchestration-worker-cli.test.ts | 23 ++++++++++++++----- .../orchestration/worker-launch-handler.ts | 11 +++++++-- src/cli/specs/orchestration-worker-specs.ts | 1 + 5 files changed, 43 insertions(+), 18 deletions(-) diff --git a/skill-guides/orchestration.md b/skill-guides/orchestration.md index db1d87ffc3e..a6474b11def 100644 --- a/skill-guides/orchestration.md +++ b/skill-guides/orchestration.md @@ -38,7 +38,9 @@ ORCA orchestration worker-start --spec "" --worktree current --agent codex - `--worktree current` uses your workspace. Use a new one only when the user asks or sharing would conflict: `--worktree new-top-level --repo id: --name ` - (`ORCA repo list --json` gives the id). + (`ORCA repo list --json` gives the id). A worker in a new workspace stays open + after it reports; if the user won't use that chat, run + `ORCA orchestration worker-release --dispatch ` once it reports. - Add `--model` only if the user named one. - If `worker-start` fails, do not rerun it; read `failedStage` and load `references/recovery-and-cleanup.md`. @@ -71,11 +73,12 @@ Never: shows mail `check` already handled. Finished workers close on their own; `send` reopens one when you need it again. -Start a worker with `--keep-open` when the user will keep using its chat after it -reports: they want to watch it, talk to it, or the fan-out sets up workspaces or -sessions to work in rather than tasks to finish. To keep one already started, run +Start a worker in your workspace with `--keep-open` when the user will keep using +its chat after it reports: they want to watch it or talk to it. To keep one already +started, run `ORCA orchestration worker-keep-open --dispatch `. -If `worker-list` shows no `autoReleaseAt` for a finished worker, release it yourself. +If a finished worker you did not keep open shows no `autoReleaseAt` in `worker-list`, +release it yourself. ## Task spec diff --git a/src/cli/bundled-skill-guides.ts b/src/cli/bundled-skill-guides.ts index 7977d884d8e..d4fd23ab57b 100644 --- a/src/cli/bundled-skill-guides.ts +++ b/src/cli/bundled-skill-guides.ts @@ -2516,7 +2516,9 @@ const ORCHESTRATION_MARKDOWN = [ "- `--worktree current` uses your workspace. Use a new one only when the user", " asks or sharing would conflict:", " `--worktree new-top-level --repo id: --name `", - " (`ORCA repo list --json` gives the id).", + " (`ORCA repo list --json` gives the id). A worker in a new workspace stays open", + " after it reports; if the user won't use that chat, run", + " `ORCA orchestration worker-release --dispatch ` once it reports.", "- Add `--model` only if the user named one.", "- If `worker-start` fails, do not rerun it; read `failedStage` and load", " `references/recovery-and-cleanup.md`.", @@ -2549,11 +2551,12 @@ const ORCHESTRATION_MARKDOWN = [ " shows mail `check` already handled.", "", "Finished workers close on their own; `send` reopens one when you need it again.", - "Start a worker with `--keep-open` when the user will keep using its chat after it", - "reports: they want to watch it, talk to it, or the fan-out sets up workspaces or", - "sessions to work in rather than tasks to finish. To keep one already started, run", + "Start a worker in your workspace with `--keep-open` when the user will keep using", + "its chat after it reports: they want to watch it or talk to it. To keep one already", + "started, run", "`ORCA orchestration worker-keep-open --dispatch `.", - "If `worker-list` shows no `autoReleaseAt` for a finished worker, release it yourself.", + "If a finished worker you did not keep open shows no `autoReleaseAt` in `worker-list`,", + "release it yourself.", "", "## Task spec", "", diff --git a/src/cli/handlers/orchestration-worker-cli.test.ts b/src/cli/handlers/orchestration-worker-cli.test.ts index 96d39e31319..9854240c9f2 100644 --- a/src/cli/handlers/orchestration-worker-cli.test.ts +++ b/src/cli/handlers/orchestration-worker-cli.test.ts @@ -781,24 +781,35 @@ describe('orchestration worker-start CLI contract', () => { ).not.toContain('orchestration worker-retain') }) - it('keeps a worker started with --keep-open open after it finishes', async () => { + it.each([ + ['--keep-open', ['keep-open', true]], + ['a new top-level workspace', ['worktree', 'new-top-level']], + ['a new child workspace', ['worktree', 'new-child']] + ] as const)('keeps a worker started with %s open after it finishes', async (_, flag) => { callMock.mockImplementation(async (method: string) => method === 'orchestration.workerStart' ? { result: { taskId: 'task_1', dispatchId: 'ctx_1', state: 'ready', effects: [] } } : { result: { dispatchId: 'ctx_1', state: 'retained', processAction: 'none' } } ) await invokeWorkerStart( - new Map([ - ['task', 'task_1'], - ['agent', 'codex'], - ['keep-open', true] - ]), + new Map([['task', 'task_1'], ['agent', 'codex'], flag]), false ) expect(callMock).toHaveBeenLastCalledWith('orchestration.workerRetain', { dispatch: 'ctx_1' }) expect(printedText()).toContain('keptOpen=true') }) + it('lets a worker in the current workspace close on its own', async () => { + callMock.mockResolvedValue({ result: { dispatchId: 'ctx_1', state: 'ready', effects: [] } }) + const flags: [string, string][] = [ + ['task', 'task_1'], + ['agent', 'codex'], + ['worktree', 'current'] + ] + await invokeWorkerStart(new Map(flags), false) + expect(callMock).not.toHaveBeenCalledWith('orchestration.workerRetain', expect.anything()) + }) + it.each([ [ 'released', diff --git a/src/cli/handlers/orchestration/worker-launch-handler.ts b/src/cli/handlers/orchestration/worker-launch-handler.ts index 62fc74d46cf..4de2244095a 100644 --- a/src/cli/handlers/orchestration/worker-launch-handler.ts +++ b/src/cli/handlers/orchestration/worker-launch-handler.ts @@ -86,7 +86,7 @@ export const ORCHESTRATION_WORKER_LAUNCH_HANDLER: Record process.exitCode = 1 } const keepOpenState = - flags.has('keep-open') && + (flags.has('keep-open') || startsInNewWorkspace(flags)) && (result.result.state === 'ready' || isUnobservedTurnStart(result.result)) ? await keepWorkerOpen(client, result.result.dispatchId) : undefined @@ -107,7 +107,8 @@ export const ORCHESTRATION_WORKER_LAUNCH_HANDLER: Record } else { printOrchestrationResult(renderedResult, json, WORKER_START_VIEW) } - if (keepOpenState && keepOpenState !== 'retained') { + // Only an explicit --keep-open fails the start; a new workspace's default is best effort. + if (flags.has('keep-open') && keepOpenState && keepOpenState !== 'retained') { const dispatchId = result.result.dispatchId // The worker runs either way, so the next step never starts it again. const verb = @@ -124,6 +125,12 @@ export const ORCHESTRATION_WORKER_LAUNCH_HANDLER: Record } } +// A worker given its own new workspace is that workspace's chat; closing it frees no space. +function startsInNewWorkspace(flags: Map): boolean { + const worktree = getOptionalStringFlag(flags, 'worktree') + return worktree === 'new-child' || worktree === 'new-top-level' +} + // Every host version serves workerRetain, so older servers keep the worker open too. async function keepWorkerOpen(client: RuntimeClient, dispatch: string): Promise { try { diff --git a/src/cli/specs/orchestration-worker-specs.ts b/src/cli/specs/orchestration-worker-specs.ts index 0640ad27373..cdb28456a77 100644 --- a/src/cli/specs/orchestration-worker-specs.ts +++ b/src/cli/specs/orchestration-worker-specs.ts @@ -42,6 +42,7 @@ export const ORCHESTRATION_WORKER_COMMAND_SPECS: CommandSpec[] = [ 'A terminal the user kept open takes --terminal work and stays kept open.', '--agent takes an Orca agent id enabled on the worker server, such as claude, codex, cursor, antigravity, muse, zcode, opencode, or opencode2.', '--model supports Claude, Codex, Cursor, Antigravity, Grok, and Muse opaque provider model ids; --effort requires --model. OMP accepts --model only; --effort is unsupported. Neither can combine with --terminal. OpenCode model selection requires an existing worktree, a verified execution-host CLI, and an available model; effort is unsupported. Other agents, including zcode, launch with the model from their own config.', + 'Finished workers close on their own unless started with --keep-open; a worker started in a new worktree (new-child or new-top-level) is kept open, so release it when no one will use its chat.', 'New worktrees use agent-first creation and default --setup to run. Repository start-immediately runs setup beside the agent; wait-for-setup gates agent readiness and task input.', 'New worktrees without --name get the name Orca gives an unnamed workspace; the receipt names it. Servers older than this change still require --name.', 'Creation flags (--name, --repo, --base-branch, --display-name, --comment, --setup) are rejected for current/existing worktrees. Use exact --repo on the selected server; project/host convenience routing remains on worktree create.',