mirror of
https://github.com/stablyai/orca.git
synced 2026-11-17 19:34:29 +00:00
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.
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -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<string, string | boolean>,
|
||||
params: { spec?: string; taskTitle?: string; run?: string; from?: string }
|
||||
): Promise<RuntimeRpcSuccess<WorkerStartResult>> {
|
||||
try {
|
||||
return await callOrchestrationMutation<WorkerStartResult>(
|
||||
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<RuntimeStatus>('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<WorkerStartResult>(
|
||||
client,
|
||||
flags,
|
||||
'orchestration.workerStart',
|
||||
params
|
||||
)
|
||||
return {
|
||||
...started,
|
||||
result: { ...started.result, run: { ...created.result.run, created: true } }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export const ORCHESTRATION_WORKER_LAUNCH_HANDLER: Record<string, CommandHandler> = {
|
||||
'orchestration worker-start': async ({ flags, client, cwd, json }) => {
|
||||
const terminal = getPresentStringFlag(flags, 'terminal')
|
||||
@@ -111,7 +34,19 @@ export const ORCHESTRATION_WORKER_LAUNCH_HANDLER: Record<string, CommandHandler>
|
||||
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<string, CommandHandler>
|
||||
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
|
||||
}
|
||||
|
||||
@@ -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<void> {
|
||||
await ORCHESTRATION_HANDLERS['orchestration worker-start']({
|
||||
flags: new Map<string, string | boolean>([
|
||||
['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')
|
||||
})
|
||||
})
|
||||
@@ -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)
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user