mirror of
https://github.com/stablyai/orca.git
synced 2026-11-19 04:23:57 +00:00
Orchestration: keep open workers started in a new workspace (#36782)
This commit is contained in:
@@ -38,7 +38,9 @@ ORCA orchestration worker-start --spec "<task>" --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:<repoId> --name <short-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 <dispatch_id>` 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 <dispatch_id>`.
|
||||
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
|
||||
|
||||
|
||||
@@ -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:<repoId> --name <short-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 <dispatch_id>` 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 <dispatch_id>`.",
|
||||
"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",
|
||||
"",
|
||||
|
||||
@@ -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<string, string | boolean>([
|
||||
['task', 'task_1'],
|
||||
['agent', 'codex'],
|
||||
['keep-open', true]
|
||||
]),
|
||||
new Map<string, string | boolean>([['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<string, string | boolean>(flags), false)
|
||||
expect(callMock).not.toHaveBeenCalledWith('orchestration.workerRetain', expect.anything())
|
||||
})
|
||||
|
||||
it.each([
|
||||
[
|
||||
'released',
|
||||
|
||||
@@ -86,7 +86,7 @@ export const ORCHESTRATION_WORKER_LAUNCH_HANDLER: Record<string, CommandHandler>
|
||||
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<string, CommandHandler>
|
||||
} 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<string, CommandHandler>
|
||||
}
|
||||
}
|
||||
|
||||
// A worker given its own new workspace is that workspace's chat; closing it frees no space.
|
||||
function startsInNewWorkspace(flags: Map<string, string | boolean>): 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<string> {
|
||||
try {
|
||||
|
||||
@@ -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.',
|
||||
|
||||
Reference in New Issue
Block a user