From bc3ad67410aceffa9486f69109e36af54192f3ce Mon Sep 17 00:00:00 2001 From: Jinwoo-H Date: Wed, 28 Oct 2026 04:36:38 -0400 Subject: [PATCH] fix(orchestration): drop the older-runtime fallback; check the spec before a Run is created The CLI fallback matched a refusal text the client decorates, could not prove the caller was a root coordinator on an older runtime, and recovered an inner run-create under the worker-start command. Older runtimes keep their refusal and the guide says to run-create first there. The prompt budget check now runs before worker-start can create a Run. --- skill-guides/orchestration.md | 5 +- src/cli/bundled-skill-guides.ts | 5 +- .../orchestration/worker-launch-handler.ts | 98 +++---------------- .../worker-start-older-runtime-run.test.ts | 83 ---------------- .../methods/orchestration/worker/workers.ts | 8 +- .../orchestration-runtime-capabilities.ts | 4 - src/shared/protocol-version.ts | 1 - 7 files changed, 29 insertions(+), 175 deletions(-) delete mode 100644 src/cli/handlers/orchestration/worker-start-older-runtime-run.test.ts diff --git a/skill-guides/orchestration.md b/skill-guides/orchestration.md index 0f6a17c6d15..f899460808c 100644 --- a/skill-guides/orchestration.md +++ b/skill-guides/orchestration.md @@ -104,8 +104,9 @@ precedence over the idle rule. Do not reuse the settled lifecycle IDs. Confirm the runtime and start the full independent wave before waiting. `worker-start --spec` creates the Task and its attempt in one call; with no Run -bound, it also creates one bound to you. Its receipt's `run` names the Run it -created or joined; if that is an earlier goal's Run, `run-create` first: +bound, it also creates one bound to you (an older Orca refuses instead; then +`run-create` first). Its receipt's `run` names the Run it created or joined; if +that is an earlier goal's Run, `run-create` first: ```text ORCA status --json diff --git a/src/cli/bundled-skill-guides.ts b/src/cli/bundled-skill-guides.ts index e81dc42ab35..7442a8abdbc 100644 --- a/src/cli/bundled-skill-guides.ts +++ b/src/cli/bundled-skill-guides.ts @@ -2437,8 +2437,9 @@ const ORCHESTRATION_MARKDOWN = [ "", "Confirm the runtime and start the full independent wave before waiting.", "`worker-start --spec` creates the Task and its attempt in one call; with no Run", - "bound, it also creates one bound to you. Its receipt's `run` names the Run it", - "created or joined; if that is an earlier goal's Run, `run-create` first:", + "bound, it also creates one bound to you (an older Orca refuses instead; then", + "`run-create` first). Its receipt's `run` names the Run it created or joined; if", + "that is an earlier goal's Run, `run-create` first:", "", "```text", "ORCA status --json", diff --git a/src/cli/handlers/orchestration/worker-launch-handler.ts b/src/cli/handlers/orchestration/worker-launch-handler.ts index 53e8505e9a8..747d9801e4c 100644 --- a/src/cli/handlers/orchestration/worker-launch-handler.ts +++ b/src/cli/handlers/orchestration/worker-launch-handler.ts @@ -1,17 +1,9 @@ import type { CommandHandler } from '../../dispatch' import { printResult } from '../../format' import { getOptionalStringFlag, getPresentStringFlag } from '../../flags' -import { - RuntimeClientError, - type RuntimeClient, - type RuntimeRpcSuccess -} from '../../runtime-client' +import { RuntimeClientError } from '../../runtime-client' import type { RuntimeStatus } from '../../../shared/runtime-types' -import { - ORCHESTRATION_WORKER_LAUNCH_PREFERENCES_RUNTIME_CAPABILITY, - ORCHESTRATION_WORKER_START_CREATES_RUN_RUNTIME_CAPABILITY -} from '../../../shared/protocol-version' -import { buildOrchestrationTaskDisplayMetadata } from '../../../shared/orchestration-task-display' +import { ORCHESTRATION_WORKER_LAUNCH_PREFERENCES_RUNTIME_CAPABILITY } from '../../../shared/protocol-version' import { callOrchestrationMutation } from './mutation-request' import { getOptionalPositiveIntegerValueFlag } from './numeric-flags' import { isDevCliInvocation } from './runtime-compatibility' @@ -19,75 +11,6 @@ import { resolveCoordinatorTerminalHandle } from './terminal-identity' import { formatWorkerStart } from './worker-output' import { renderResolvedOrchestrationCommand } from '../../orchestration-mutation-recovery' -type WorkerStartResult = { - runId: string - taskId: string - dispatchId: string - state: string - failedStage?: string - lastError?: string - warning?: string - mode?: { mode: string; preferred: string; reason: string; detail: string } - run?: { id: string; objective: string; created: boolean } - effects: unknown[] - residualResources: unknown[] - nextCommands?: string[] -} - -// Older runtimes refuse an unbound coordinator with exactly this; it also proves the caller works no Dispatch there. -const OLDER_RUNTIME_UNBOUND_COORDINATOR = - 'worker-start needs the coordinator bound to the Run, or a worker on an active Dispatch in it.' - -/** Start a worker; against a runtime that cannot create the Run itself, run-create first as it would. */ -async function startWorker( - client: RuntimeClient, - flags: Map, - params: { spec?: string; taskTitle?: string; run?: string; from?: string } -): Promise> { - try { - return await callOrchestrationMutation( - client, - flags, - 'orchestration.workerStart', - params - ) - } catch (error) { - const { spec } = params - if ( - !spec || - params.run || - !(error instanceof RuntimeClientError) || - error.code !== 'consumer_fenced' || - error.message !== OLDER_RUNTIME_UNBOUND_COORDINATOR || - (await client.call('status.get')).result.capabilities?.includes( - ORCHESTRATION_WORKER_START_CREATES_RUN_RUNTIME_CAPABILITY - ) - ) { - throw error - } - const { taskTitle: objective } = buildOrchestrationTaskDisplayMetadata({ - spec, - taskTitle: params.taskTitle - }) - const created = await callOrchestrationMutation<{ run: { id: string; objective: string } }>( - client, - new Map(), - 'orchestration.runCreate', - { objective, from: params.from } - ) - const started = await callOrchestrationMutation( - client, - flags, - 'orchestration.workerStart', - params - ) - return { - ...started, - result: { ...started.result, run: { ...created.result.run, created: true } } - } - } -} - export const ORCHESTRATION_WORKER_LAUNCH_HANDLER: Record = { 'orchestration worker-start': async ({ flags, client, cwd, json }) => { const terminal = getPresentStringFlag(flags, 'terminal') @@ -111,7 +34,19 @@ export const ORCHESTRATION_WORKER_LAUNCH_HANDLER: Record const taskTitle = getOptionalStringFlag(flags, 'task-title') const deps = getOptionalStringFlag(flags, 'deps') const parent = getOptionalStringFlag(flags, 'parent') - const params = { + const result = await callOrchestrationMutation<{ + runId: string + taskId: string + dispatchId: string + state: string + failedStage?: string + lastError?: string + warning?: string + mode?: { mode: string; preferred: string; reason: string; detail: string } + effects: unknown[] + residualResources: unknown[] + nextCommands?: string[] + }>(client, flags, 'orchestration.workerStart', { task, ...(spec ? { spec } : {}), ...(taskTitle ? { taskTitle } : {}), @@ -134,8 +69,7 @@ export const ORCHESTRATION_WORKER_LAUNCH_HANDLER: Record run: getOptionalStringFlag(flags, 'run'), from: await resolveCoordinatorTerminalHandle(flags, cwd, client), devMode: isDevCliInvocation() - } - const result = await startWorker(client, flags, params) + }) if (result.result.state !== 'ready') { process.exitCode = 1 } diff --git a/src/cli/handlers/orchestration/worker-start-older-runtime-run.test.ts b/src/cli/handlers/orchestration/worker-start-older-runtime-run.test.ts deleted file mode 100644 index 48c083a2a19..00000000000 --- a/src/cli/handlers/orchestration/worker-start-older-runtime-run.test.ts +++ /dev/null @@ -1,83 +0,0 @@ -import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' -import { ORCHESTRATION_HANDLERS } from '../orchestration' -import { RuntimeClient, RuntimeClientError } from '../../runtime-client' -import { okFixture } from '../../test-fixtures' -import { ORCHESTRATION_WORKER_START_CREATES_RUN_RUNTIME_CAPABILITY } from '../../../shared/protocol-version' - -const client = new RuntimeClient('/tmp/orca-older-runtime-run', 60_000, null, null) -const UNBOUND = new RuntimeClientError( - 'consumer_fenced', - 'worker-start needs the coordinator bound to the Run, or a worker on an active Dispatch in it.' -) - -describe('worker-start against a runtime that cannot create the Run itself', () => { - const methods: string[] = [] - let runCreateParams: unknown - - function stubRuntime(capabilities: string[]): void { - let starts = 0 - vi.spyOn(client, 'call').mockImplementation(async (method: string, params?: unknown) => { - methods.push(method) - if (method === 'status.get') { - return okFixture('req_status', { capabilities }) - } - if (method === 'orchestration.runCreate') { - runCreateParams = params - return okFixture('req_run', { run: { id: 'run_1', objective: 'Audit the parser' } }) - } - if (method === 'orchestration.workerStart') { - starts += 1 - if (starts === 1) { - throw UNBOUND - } - return okFixture('req_start', { state: 'ready', effects: [], residualResources: [] }) - } - throw new Error(`Unexpected RPC: ${method}`) - }) - } - - async function start(): Promise { - await ORCHESTRATION_HANDLERS['orchestration worker-start']({ - flags: new Map([ - ['spec', 'Audit the parser\nCheck every branch.'], - ['terminal', 'term_worker'], - ['from', 'term_coord'] - ]), - client, - cwd: '/tmp/coord', - json: true - }) - } - - beforeEach(() => { - methods.length = 0 - runCreateParams = undefined - vi.spyOn(console, 'log').mockImplementation(() => {}) - }) - - afterEach(() => { - vi.restoreAllMocks() - process.exitCode = undefined - }) - - it('creates the Run as run-create would, then starts the worker once more', async () => { - stubRuntime([]) - - await start() - - expect(methods).toEqual([ - 'orchestration.workerStart', - 'status.get', - 'orchestration.runCreate', - 'orchestration.workerStart' - ]) - expect(runCreateParams).toEqual({ objective: 'Audit the parser', from: 'term_coord' }) - }) - - it('leaves the refusal alone when the runtime would have created the Run', async () => { - stubRuntime([ORCHESTRATION_WORKER_START_CREATES_RUN_RUNTIME_CAPABILITY]) - - await expect(start()).rejects.toBe(UNBOUND) - expect(methods).not.toContain('orchestration.runCreate') - }) -}) diff --git a/src/main/runtime/rpc/methods/orchestration/worker/workers.ts b/src/main/runtime/rpc/methods/orchestration/worker/workers.ts index df2385766ab..38937b74f01 100644 --- a/src/main/runtime/rpc/methods/orchestration/worker/workers.ts +++ b/src/main/runtime/rpc/methods/orchestration/worker/workers.ts @@ -48,6 +48,10 @@ export const ORCHESTRATION_WORKER_START_METHODS = [ callerEvidence: orchestrationCompatibilityEvidence, callerSession: orchestrationCaller }) + if (params.spec) { + // Before the Run resolves, so a refused spec cannot leave a new Run bound. + await assertWorkerStartTaskSpecWithinPromptBudget(params.spec) + } const { run, runCreated, helperCreator } = resolveWorkerStartRun(runtime, { coordinator, from: params.from, @@ -86,7 +90,9 @@ export const ORCHESTRATION_WORKER_START_METHODS = [ params }) } - await assertWorkerStartTaskSpecWithinPromptBudget(params.spec ?? existingTask!.spec) + if (existingTask) { + await assertWorkerStartTaskSpecWithinPromptBudget(existingTask.spec) + } const mode = decideWorkerStartMode({ params, settings: readWorkerStartModeSettings(runtime) diff --git a/src/shared/orchestration-runtime-capabilities.ts b/src/shared/orchestration-runtime-capabilities.ts index 4c340507515..7e33fc70d21 100644 --- a/src/shared/orchestration-runtime-capabilities.ts +++ b/src/shared/orchestration-runtime-capabilities.ts @@ -7,9 +7,6 @@ export const ORCHESTRATION_WORKER_STOP_VERDICT_RUNTIME_CAPABILITY = 'orchestration.worker-stop-verdict.v1' as const export const ORCHESTRATION_WORKER_LAUNCH_PREFERENCES_RUNTIME_CAPABILITY = 'orchestration.worker-launch-preferences.v1' as const -/** worker-start creates and binds a Run when a coordinator has none. */ -export const ORCHESTRATION_WORKER_START_CREATES_RUN_RUNTIME_CAPABILITY = - 'orchestration.worker-start-creates-run.v1' as const export const ORCHESTRATION_FEDERATION_STRUCTURED_READ_RUNTIME_CAPABILITY = 'orchestration.federation-structured-read.v1' as const export const ORCHESTRATION_FEDERATION_FLEET_SNAPSHOT_RUNTIME_CAPABILITY = @@ -27,7 +24,6 @@ export const ORCHESTRATION_RUNTIME_CAPABILITIES = [ ORCHESTRATION_FEDERATION_LIFECYCLE_SETTLEMENT_RUNTIME_CAPABILITY, ORCHESTRATION_WORKER_STOP_VERDICT_RUNTIME_CAPABILITY, ORCHESTRATION_WORKER_LAUNCH_PREFERENCES_RUNTIME_CAPABILITY, - ORCHESTRATION_WORKER_START_CREATES_RUN_RUNTIME_CAPABILITY, ORCHESTRATION_FEDERATION_STRUCTURED_READ_RUNTIME_CAPABILITY, ORCHESTRATION_FEDERATION_FLEET_SNAPSHOT_RUNTIME_CAPABILITY, ORCHESTRATION_FEDERATION_RELEASE_ARCHIVE_RUNTIME_CAPABILITY, diff --git a/src/shared/protocol-version.ts b/src/shared/protocol-version.ts index df661bf9686..5b989c2cc3f 100644 --- a/src/shared/protocol-version.ts +++ b/src/shared/protocol-version.ts @@ -90,7 +90,6 @@ export { ORCHESTRATION_FEDERATION_LIFECYCLE_SETTLEMENT_RUNTIME_CAPABILITY, ORCHESTRATION_WORKER_STOP_VERDICT_RUNTIME_CAPABILITY, ORCHESTRATION_WORKER_LAUNCH_PREFERENCES_RUNTIME_CAPABILITY, - ORCHESTRATION_WORKER_START_CREATES_RUN_RUNTIME_CAPABILITY, ORCHESTRATION_FEDERATION_STRUCTURED_READ_RUNTIME_CAPABILITY, ORCHESTRATION_FEDERATION_FLEET_SNAPSHOT_RUNTIME_CAPABILITY, ORCHESTRATION_FEDERATION_RELEASE_ARCHIVE_RUNTIME_CAPABILITY,