Skip to content

The ultimate harness for coding agents and beyond. All your agents. All your machines. One command center. Start with code, then follow your curiosity and build across disciplines: CAD, circuits, robots, games and music.

fix(cli): trust accepted effort flag during routed start resume (#1623)

0xken155106bf5e68f6
diff --git a/cli/e2e/harness/fakeEngine.mjs b/cli/e2e/harness/fakeEngine.mjs
index 257c40e5f..b9f0617f4 100644
--- a/cli/e2e/harness/fakeEngine.mjs
+++ b/cli/e2e/harness/fakeEngine.mjs
@@ -422,13 +422,11 @@ export async function run(engine, config = {}, { native = false } = {}) {
? (args.includes('--dangerously-skip-permissions') ? 'bypassPermissions'
: args.includes('--permission-mode') ? args[args.indexOf('--permission-mode') + 1] ?? 'default' : 'default')
: (args.includes('--dangerously-bypass-approvals-and-sandbox') ? 'bypassPermissions' : 'default')
- // The model and effort the thread runs on: what Codex writes in each turn's context, and what its
- // `/model` picker changes (below). Its `-m`/`--model` on the command line outranks the configured one, as
- // in the real CLI: that is how a relaunch puts an agent back on the model it had before a grid
- // (subscriptionModel.ts).
- const modelAt = engine === 'codex' ? args.findIndex((arg) => arg === '-m' || arg === '--model') : -1
+ // The model passed on either engine's command line outranks the fixture default, as in the real CLI.
+ // Codex writes its model and effort in each turn's context; Claude writes its model in the transcript.
+ const modelAt = args.findIndex((arg) => arg === '-m' || arg === '--model')
let current = { model: (modelAt >= 0 && args[modelAt + 1]) || config.codexModel || 'gpt-6', effort: 'high' }
- let claudeModel = config.claudeModel ?? 'claude-opus-5-5'
+ let claudeModel = (modelAt >= 0 && args[modelAt + 1]) || config.claudeModel || 'claude-opus-5-5'
// Test-owned file gate, used to stop an engine worker after its command reached the live CLI.
const modelGate = async command => {
const log = join(config.root, 'model-control-commands')
diff --git a/cli/src/core/agents/launches.spec.ts b/cli/src/core/agents/launches.spec.ts
index 31a55dd97..be246a6d4 100644
--- a/cli/src/core/agents/launches.spec.ts
+++ b/cli/src/core/agents/launches.spec.ts
@@ -820,9 +820,9 @@ describe('agent_create with a receipt', () => {
})
it('says why a receipt could not be kept, and answers INTERNAL when the answer cannot be put together', async () => {
- const storage = setup({ receipts: { has: vi.fn(() => false), creator: vi.fn(), runIntent: vi.fn(), pendingIntents: vi.fn(), pendingIntent: vi.fn(), cancelIntent: vi.fn(), status: vi.fn(), run: vi.fn(() => { throw new AgentCreationReceiptError('CREATION_STORAGE_FAILED') }) } })
+ const storage = setup({ receipts: { has: vi.fn(() => false), creator: vi.fn(), createdLaunchModel: vi.fn(() => null), runIntent: vi.fn(), pendingIntents: vi.fn(), pendingIntent: vi.fn(), cancelIntent: vi.fn(), status: vi.fn(), run: vi.fn(() => { throw new AgentCreationReceiptError('CREATION_STORAGE_FAILED') }) } })
expect(await storage.ask({ engine: 'claude', cwd: '/w', creationId: CREATION })).toStrictEqual({ error: 'CREATION_STORAGE_FAILED' })
- const broken = setup({ receipts: { has: vi.fn(() => false), creator: vi.fn(), runIntent: vi.fn(), pendingIntents: vi.fn(), pendingIntent: vi.fn(), cancelIntent: vi.fn(), status: vi.fn(), run: vi.fn(() => { throw new Error('bug') }) } })
+ const broken = setup({ receipts: { has: vi.fn(() => false), creator: vi.fn(), createdLaunchModel: vi.fn(() => null), runIntent: vi.fn(), pendingIntents: vi.fn(), pendingIntent: vi.fn(), cancelIntent: vi.fn(), status: vi.fn(), run: vi.fn(() => { throw new Error('bug') }) } })
expect(await broken.ask({ engine: 'claude', cwd: '/w', creationId: CREATION })).toStrictEqual({ error: 'INTERNAL' })
const frameless = setup({ toProject: vi.fn(async () => { throw new Error('no frame') }) })
await frameless.ask({ engine: 'claude', cwd: '/w', creationId: CREATION })
@@ -912,6 +912,15 @@ describe('durable model request validation', () => {
})
describe('agent_create_status', () => {
+ it('reports the model and effort flags saved by a completed native launch', async () => {
+ const { status, deps } = setup()
+ const request = { kind: 'native-create-v1', input: { launchModel: { model: 'opus', effort: 'high' } } }
+ await deps.receipts.runIntent(CREATION, creationFingerprint(request), request,
+ { service: 'launch', detail: 'Preparing.' }, async () => async () => ({ state: 'created', agentId: 'new-agent' }))
+ expect(await status({ creationId: CREATION })).toStrictEqual({ creationId: CREATION, state: 'created', agent: { id: 'new-agent' },
+ launchModel: { model: 'opus', effort: 'high' } })
+ })
+
it('names a launch by a valid creation id, and says what became of it', async () => {
const { status, deps } = setup()
expect(await status({ creationId: 'short' })).toStrictEqual({ error: 'INVALID_CREATION_ID' })
@@ -930,9 +939,9 @@ describe('agent_create_status', () => {
})
it('says why a receipt could not be read', async () => {
- const storage = setup({ receipts: { has: vi.fn(() => false), creator: vi.fn(), runIntent: vi.fn(), pendingIntents: vi.fn(), pendingIntent: vi.fn(), cancelIntent: vi.fn(), run: vi.fn(), status: vi.fn(() => { throw new AgentCreationReceiptError('CREATION_STORAGE_FAILED') }) } })
+ const storage = setup({ receipts: { has: vi.fn(() => false), creator: vi.fn(), createdLaunchModel: vi.fn(() => null), runIntent: vi.fn(), pendingIntents: vi.fn(), pendingIntent: vi.fn(), cancelIntent: vi.fn(), run: vi.fn(), status: vi.fn(() => { throw new AgentCreationReceiptError('CREATION_STORAGE_FAILED') }) } })
expect(await storage.status({ creationId: CREATION })).toStrictEqual({ error: 'CREATION_STORAGE_FAILED' })
- const broken = setup({ receipts: { has: vi.fn(() => false), creator: vi.fn(), runIntent: vi.fn(), pendingIntents: vi.fn(), pendingIntent: vi.fn(), cancelIntent: vi.fn(), run: vi.fn(), status: vi.fn(() => { throw new Error('bug') }) } })
+ const broken = setup({ receipts: { has: vi.fn(() => false), creator: vi.fn(), createdLaunchModel: vi.fn(() => null), runIntent: vi.fn(), pendingIntents: vi.fn(), pendingIntent: vi.fn(), cancelIntent: vi.fn(), run: vi.fn(), status: vi.fn(() => { throw new Error('bug') }) } })
expect(await broken.status({ creationId: CREATION })).toStrictEqual({ error: 'INTERNAL' })
})
})
@@ -987,9 +996,9 @@ describe('agent_resume and agent_restart', () => {
})
it('say why a receipt could not be kept, and INTERNAL when the answer cannot be put together', async () => {
- const storage = setup({ receipts: { has: vi.fn(() => false), creator: vi.fn(), runIntent: vi.fn(), pendingIntents: vi.fn(), pendingIntent: vi.fn(), cancelIntent: vi.fn(), status: vi.fn(), run: vi.fn(() => { throw new AgentCreationReceiptError('CREATION_STORAGE_FAILED') }) } })
+ const storage = setup({ receipts: { has: vi.fn(() => false), creator: vi.fn(), createdLaunchModel: vi.fn(() => null), runIntent: vi.fn(), pendingIntents: vi.fn(), pendingIntent: vi.fn(), cancelIntent: vi.fn(), status: vi.fn(), run: vi.fn(() => { throw new AgentCreationReceiptError('CREATION_STORAGE_FAILED') }) } })
expect(await storage.relaunch('agent_restart', { agentId: 'a1', creationId: CREATION })).toStrictEqual({ error: 'CREATION_STORAGE_FAILED' })
- const broken = setup({ receipts: { has: vi.fn(() => false), creator: vi.fn(), runIntent: vi.fn(), pendingIntents: vi.fn(), pendingIntent: vi.fn(), cancelIntent: vi.fn(), status: vi.fn(), run: vi.fn(() => { throw new Error('bug') }) } })
+ const broken = setup({ receipts: { has: vi.fn(() => false), creator: vi.fn(), createdLaunchModel: vi.fn(() => null), runIntent: vi.fn(), pendingIntents: vi.fn(), pendingIntent: vi.fn(), cancelIntent: vi.fn(), status: vi.fn(), run: vi.fn(() => { throw new Error('bug') }) } })
expect(await broken.relaunch('agent_restart', { agentId: 'a1', creationId: CREATION })).toStrictEqual({ error: 'INTERNAL' })
const frameless = setup({ toProject: vi.fn(async () => { throw new Error('no frame') }) })
await frameless.relaunch('agent_restart', { agentId: 'a1', creationId: CREATION })
@@ -1045,9 +1054,9 @@ describe('agent_fork', () => {
})
it('says why a receipt could not be kept, and INTERNAL when the answer cannot be put together', async () => {
- const storage = setup({ receipts: { has: vi.fn(() => false), creator: vi.fn(), runIntent: vi.fn(), pendingIntents: vi.fn(), pendingIntent: vi.fn(), cancelIntent: vi.fn(), status: vi.fn(), run: vi.fn(() => { throw new AgentCreationReceiptError('CREATION_CONFLICT') }) } })
+ const storage = setup({ receipts: { has: vi.fn(() => false), creator: vi.fn(), createdLaunchModel: vi.fn(() => null), runIntent: vi.fn(), pendingIntents: vi.fn(), pendingIntent: vi.fn(), cancelIntent: vi.fn(), status: vi.fn(), run: vi.fn(() => { throw new AgentCreationReceiptError('CREATION_CONFLICT') }) } })
expect(await storage.forkAsk({ agentId: 'a1', creationId: CREATION })).toStrictEqual({ error: 'CREATION_CONFLICT' })
- const broken = setup({ receipts: { has: vi.fn(() => false), creator: vi.fn(), runIntent: vi.fn(), pendingIntents: vi.fn(), pendingIntent: vi.fn(), cancelIntent: vi.fn(), status: vi.fn(), run: vi.fn(() => { throw new Error('bug') }) } })
+ const broken = setup({ receipts: { has: vi.fn(() => false), creator: vi.fn(), createdLaunchModel: vi.fn(() => null), runIntent: vi.fn(), pendingIntents: vi.fn(), pendingIntent: vi.fn(), cancelIntent: vi.fn(), status: vi.fn(), run: vi.fn(() => { throw new Error('bug') }) } })
expect(await broken.forkAsk({ agentId: 'a1', creationId: CREATION })).toStrictEqual({ error: 'INTERNAL' })
const frameless = setup({ toProject: vi.fn(async () => { throw new Error('no frame') }) })
await frameless.forkAsk({ agentId: 'a1', creationId: CREATION })
diff --git a/cli/src/core/agents/launches.ts b/cli/src/core/agents/launches.ts
index 4837b3112..f006d16f3 100644
--- a/cli/src/core/agents/launches.ts
+++ b/cli/src/core/agents/launches.ts
@@ -56,7 +56,7 @@ export type ResumeAgent = (agentId: string, permissionMode?: string) => ReturnTy
export interface LaunchRequestDeps {
/** The receipts of launches asked for with a `creationId`. */
- receipts: Pick<AgentCreationReceipts, 'run' | 'status' | 'creator' | 'has' | 'runIntent' | 'pendingIntents' | 'pendingIntent' | 'cancelIntent'>
+ receipts: Pick<AgentCreationReceipts, 'run' | 'status' | 'createdLaunchModel' | 'creator' | 'has' | 'runIntent' | 'pendingIntents' | 'pendingIntent' | 'cancelIntent'>
/** Each launch, read when a request comes in: null on a machine that cannot launch agents. */
createAgent: () => CreateAgent | null
prepareCreate?: (input: Parameters<CreateAgent>[0], authority: LaunchAuthority, context?: { local: boolean }) => Promise<LaunchPreparation<Awaited<ReturnType<CreateAgent>>>>
@@ -268,7 +268,9 @@ export function createLaunchRequests({ receipts, createAgent, prepareCreate, pre
if (!validCreationId(creationId)) { reply({ error: 'INVALID_CREATION_ID' }); return }
try {
if (hiddenFrom(asker, creationId)) { reply({ creationId, state: 'missing' }); return }
- reply({ creationId, ...await creationStatusPayload(receipts.status(creationId)) })
+ const status = receipts.status(creationId)
+ const launchModel = status.state === 'created' ? receipts.createdLaunchModel(creationId) : null
+ reply({ creationId, ...await creationStatusPayload(status), ...(launchModel ? { launchModel } : {}) })
} catch (error) {
reply({ error: error instanceof AgentCreationReceiptError ? error.code : 'INTERNAL' })
}
diff --git a/cli/src/lib/agentCreationReceipt.ts b/cli/src/lib/agentCreationReceipt.ts
index 0a2e239af..61059b411 100644
--- a/cli/src/lib/agentCreationReceipt.ts
+++ b/cli/src/lib/agentCreationReceipt.ts
@@ -3,6 +3,7 @@ import { closeSync, constants, fstatSync, fsyncSync, linkSync, lstatSync, mkdirS
import { opendir } from 'node:fs/promises'
import { dirname, join } from 'node:path'
import { readPrivateStateFile, secureStateDirectory, syncStateDirectory } from './secureState.js'
+import type { LaunchModel } from './launchModel.js'
export type AgentCreationOutcome =
| { state: 'created'; agentId: string; level?: 'native' | 'handoff'; resumed?: boolean }
@@ -110,6 +111,19 @@ export class AgentCreationReceipts {
: receipt.outcome
}
+ /** The launch flags kept in a completed native intent, absent for legacy or fallback creates. */
+ createdLaunchModel(id: string): LaunchModel | null {
+ const receipt = this.read(id)
+ if (receipt?.version !== 2 || 'cancelled' in receipt || this.intentStatus(id, receipt).state !== 'created') return null
+ const saved = receipt.request
+ if (saved.kind !== 'native-create-v1' || !saved.input || typeof saved.input !== 'object') return null
+ const launchModel = (saved.input as Record<string, unknown>).launchModel
+ if (!launchModel || typeof launchModel !== 'object') return null
+ const { model, effort } = launchModel as Record<string, unknown>
+ return (model === null || typeof model === 'string') && (effort === null || typeof effort === 'string')
+ ? { model, effort } : null
+ }
+
/** Whose launch an id names: a guest's key, or null for the owner's, an intent's and an unknown id (which a
* guest hears the same way). */
creator(id: string): string | null {
diff --git a/cli/src/superTabs/start.spec.ts b/cli/src/superTabs/start.spec.ts
index 3fdf3c249..119d64b9f 100644
--- a/cli/src/superTabs/start.spec.ts
+++ b/cli/src/superTabs/start.spec.ts
@@ -2,7 +2,7 @@ import { describe, expect, it, vi } from 'vitest'
import { inspectCapacity, startAgent } from './start.js'
import { buildEngineCommandArgv } from '../lib/engineLaunch.js'
const where = { port: 14001, machineId: 'lead-machine', dataDir: '/fixture' }
-function fixture(options: { state?: Record<string, unknown> | Error; refuse?: string; loseCancel?: boolean; loseFailure?: boolean; launchModel?: string[]; refuseModel?: string; frame?: string; guest?: boolean; identity?: { sessionId: string; createdAt: string } } = {}) {
+function fixture(options: { state?: Record<string, unknown> | Error; refuse?: string; loseCancel?: boolean; loseFailure?: boolean; launchModel?: string[]; acceptedLaunchModel?: { model: string | null; effort: string | null }; refuseModel?: string; frame?: string; guest?: boolean; identity?: { sessionId: string; createdAt: string } } = {}) {
const start = { creationId: 'super-native-receipt', error: null as string | null, request: { machineId: 'target', conversationId: 'group', engine: 'claude', name: 'Builder', cwd: '/repo', worktree: true,
requirements: { memoryBytes: 100, diskBytes: 200, maxCpuPercent: 80, tools: ['git'], devices: [], quotaRequired: false } }, dispatched: false }
let nativeState = 'missing', lostJoin = false
@@ -22,7 +22,7 @@ function fixture(options: { state?: Record<string, unknown> | Error; refuse?: st
return { ok: true, value: { result: cmd.type === 'agent.start' ? { startId: 'start' } : { agentId: 'worker' } } }
})
const request = vi.fn(async (type: string, payload: Record<string, unknown> = {}, _ms?: number): Promise<Record<string, unknown>> => {
- if (type === 'agent_create_status') return { creationId: start.creationId, state: nativeState, ...(nativeState === 'created' ? { agent: { id: 'native', engine: 'claude', selectedModel: 'runtime-v1:native:claude:fixture-model@high', ...options.identity } } : {}) }
+ if (type === 'agent_create_status') return { creationId: start.creationId, state: nativeState, ...(nativeState === 'created' ? { agent: { id: 'native', engine: 'claude', selectedModel: 'runtime-v1:native:claude:fixture-model@high', ...options.identity }, ...(options.acceptedLaunchModel ? { launchModel: options.acceptedLaunchModel } : {}) } : {}) }
if (type === 'agents_list' && options.frame) return { agents: [{ id: 'native', engine: 'claude', selectedModel: options.frame }] }
if (type === 'engines_probe') return { engines: [{ engine: (payload.engines as string[])[0], installed: true }] }
if (type === 'usage_read') return { providers: [] }
@@ -744,6 +744,19 @@ describe('a routed Claude start launches with the model instead of switching it
expect(switched(f)).toBe(false)
})
+ it('does not type an effort command when the accepted launch flag precedes runtime effort detection', async () => {
+ const f = fixture({ launchModel: ['claude'], acceptedLaunchModel: { model: 'opus', effort: 'high' }, frame: 'runtime-v1:native:claude:opus@auto' })
+ expect(await resume(f)).toMatchObject({ ok: true })
+ expect(created(f)).toHaveLength(1)
+ expect(switched(f)).toBe(false)
+ })
+
+ it('still switches when runtime settles on a concrete effort different from the launch flag', async () => {
+ const f = fixture({ launchModel: ['claude'], acceptedLaunchModel: { model: 'opus', effort: 'high' }, frame: 'runtime-v1:native:claude:opus@low' })
+ expect(await resume(f)).toMatchObject({ ok: true })
+ expectSwitchTo(f, 'runtime-v1:native:claude:opus@high')
+ })
+
it('does not count default or an automatic effort as a difference', async () => {
const f = fixture({ launchModel: ['claude'], frame: 'runtime-v1:native:claude:opus@high' })
const result = await resume(f)
diff --git a/cli/src/superTabs/start.ts b/cli/src/superTabs/start.ts
index ed6ac5b91..e6d97e311 100644
--- a/cli/src/superTabs/start.ts
+++ b/cli/src/superTabs/start.ts
@@ -258,12 +258,17 @@ export async function startAgent(input: Json, scoped: ScopedRequest, where: Wher
let switching = routedModel && launched === false
if (routedModel && launched === undefined) {
// This invocation did not send the create, and the one that did may have launched with the model, fallen back to
- // the switch, or been cut off before either. Only the agent's frame says which; /model is never typed blind, as
- // Claude Code would save it as the person's default.
+ // the switch, or been cut off before either. A concrete runtime difference still needs a switch. A temporary
+ // automatic effort is not a difference when the completed native receipt proves that effort was passed at launch.
+ // /model is never typed blind, as Claude Code would save it as the person's default.
const ran = await ranNow(nativeId, String(request.engine))
const same = (wanted: string, actual: string) => wanted === 'default' || wanted === 'auto' || wanted === actual
if (!ran) modelWarning = `Could not confirm that the agent runs ${model} ${effort}; its configuration could not be read, so it was left as it is.`
- else switching = !same(String(model), ran.model) || !same(String(effort), ran.effort)
+ else {
+ const accepted = object(native.launchModel)
+ const effortStillUnknown = ran.effort === 'auto' && accepted.effort === effort && same(String(model), ran.model)
+ switching = !same(String(model), ran.model) || (!same(String(effort), ran.effort) && !effortStillUnknown)
+ }
}
if (switching) {
const selectedModel = encodeRuntimeProfile({ sessionId: nativeId, engine: String(request.engine) as never, model: String(model), effort: effort as never })