mirror of
https://github.com/wu736139669/hapi.git
synced 2026-11-25 05:07:05 +00:00
fix(cursor): pin Auto to CLI --model auto instead of account default (#1819)
* fix(cursor): pin Auto to CLI --model auto instead of account default Selecting Auto was treated as unset/ACP default[] after the Default→Auto rename. Persist and spawn `auto` so the picker matches `agent --list-models`. Co-authored-by: Cursor <cursoragent@cursor.com> * fix(cursor): keep live ACP model until Auto actually applies Pin session.model to auto for the next `--model auto` spawn, but do not claim the live backend switched when ACP only advertises default[]. Co-authored-by: Cursor <cursoragent@cursor.com> * fix(cursor): reject live Auto unless ACP auto or spawn confirmed it Do not persist Auto when the running catalog has no auto option. Clear the spawn-auto flag after a concrete model apply so Auto → concrete → Auto cannot fake a live switch. Co-authored-by: Cursor <cursoragent@cursor.com> * fix(cursor): keep ACP wire ids spawn-safe and apply effort Cursor's parameterized picker (`clientCapabilities._meta.parameterizedModelPicker`) advertises bare model bases plus separate `fast` / `thought_level` config options. `buildCursorModelsSnapshotFromAcp` synthesized every base as `${base}[fast=${fast}]`, and Cursor rejects any bracket id whose parameter set is not that model's complete set, so 74 of the 76 published picker ids failed at ACP `session/new` with `Cannot use this model` (#1818). - Stop synthesizing wire ids: keep the advertised values verbatim (bare bases are accepted by `--model`, defaults applied). Parameter sets differ per model, so a synthesized id cannot be validated from the options alone. - Flag such catalogs as `parameterized` so variant CLI skus still attach to their base rows — the ACP apply path expresses them through config options. - Apply effort in `applyParameterizedCursorModel` (ids `effort`, `reasoning`, `reasoning_effort`), applied against the config options Cursor re-advertises for the newly selected model, and skipped on models without that axis. - Match CLI sku bases across Cursor's legacy `cursor-` family prefix (`cursor-grok-4.6-high` → ACP base `grok-4.6`) so those variant rows are not dropped. - Version the shared on-disk catalog cache (v2) so runners that already cached the rejected synthesized ids re-probe instead of serving them. Verified with live `cursor-agent 2026.09.10-fd3934a` ACP runs: the catalog no longer contains bracket ids, every advertised base and sampled variant sku spawns, and in-session `claude-opus-4-8-low` / `cursor-grok-4.6-low` set the matching `effort`/`reasoning` option. * test(cursor): cover aliased effort ids and thinking coexistence Covers the branches the HAPI bot review called out for #1818: the `xhigh` → `extra-high` alias on `gpt-5.5` (`reasoning`), the `reasoning_effort` id used by `gemini-3.8-flash`, and switching effort on a model that also advertises Claude's separate `thought_level` `thinking` toggle. * test(cursor): cover legacy sku base and post-switch effort option Adds the two apply-path cases the HAPI bot review called out for #1818: resolving `cursor-grok-4.6-high` onto an advertised `grok-4.6` base, and reading the effort option Cursor advertises for the newly selected model (`reasoning` for gpt-5.5 → `effort` for claude-opus-4-8) instead of the previous model's options. * test(cursor): create the cache dir in the migration test The version-envelope test wrote $HAPI_HOME/cache/cursor-models.json without creating the directory, so running it alone (or filtering with -t) failed with ENOENT before the assertion; it only passed because sibling tests in the same file had already created the path. Reported in the HAPI bot review of #1822. Verified: `vitest run ... -t 'ignores pre-versioned'` → 1 passed, whole file → 4 passed, and every other changed test file passes when run standalone. * Clarify Cursor Auto live-switch limitation in session pickers * Reconcile partial Cursor model changes before acknowledging Auto * Serialize Cursor model changes across clients with the existing async lock --------- Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -10,6 +10,7 @@ const harness = vi.hoisted(() => ({
|
||||
loadSessionError: null as Error | null,
|
||||
newSessionError: null as Error | null,
|
||||
failSetConfigOption: false,
|
||||
failFastConfigOption: false,
|
||||
supportsLoadSession: true,
|
||||
loadSessionCalled: false,
|
||||
newSessionCalled: false,
|
||||
@@ -26,6 +27,15 @@ const harness = vi.hoisted(() => ({
|
||||
promptStderrErrors: [] as Array<{ type: string; message: string; raw: string }>,
|
||||
releasePrompt: null as (() => void) | null,
|
||||
backendArgs: null as { command: string; args?: string[] } | null,
|
||||
modelOptionValues: [
|
||||
'default[]',
|
||||
'composer-2.5[fast=true]',
|
||||
'composer-2.5[fast=false]',
|
||||
'gpt-5.3-codex[reasoning=medium,fast=false]',
|
||||
'gpt-5.3-codex[reasoning=medium,fast=true]',
|
||||
'cursor-grok-4.5-medium',
|
||||
'cursor-grok-4.5-medium-fast',
|
||||
] as string[],
|
||||
setConfigOptionCalls: [] as Array<{ sessionId: string; configId: string; value: string }>,
|
||||
deferSetConfigOption: null as Promise<void> | null,
|
||||
releaseSetConfigOption: null as (() => void) | null,
|
||||
@@ -48,8 +58,11 @@ vi.mock('./utils/cursorAcpBackend', () => ({
|
||||
createCursorAcpBackend: vi.fn((opts?: { model?: string | null }) => {
|
||||
const args = ['acp'];
|
||||
const model = opts?.model?.trim();
|
||||
if (model && model !== 'auto' && model !== 'default' && model !== 'default[]') {
|
||||
args.unshift('--model', model);
|
||||
const spawn = !model
|
||||
? null
|
||||
: (model === 'auto' || model === 'default' || model === 'default[]' ? 'auto' : model);
|
||||
if (spawn) {
|
||||
args.unshift('--model', spawn);
|
||||
}
|
||||
harness.backendArgs = { command: 'agent', args };
|
||||
return {
|
||||
@@ -96,6 +109,9 @@ vi.mock('./utils/cursorAcpBackend', () => ({
|
||||
if (harness.failSetConfigOption && configId === 'model-opt') {
|
||||
throw new Error('set_config_option rejected');
|
||||
}
|
||||
if (harness.failFastConfigOption && configId === 'fast') {
|
||||
throw new Error('fast update rejected');
|
||||
}
|
||||
harness.setConfigOptionCalls.push({ sessionId, configId, value });
|
||||
}),
|
||||
pinSessionModelWireId: vi.fn(),
|
||||
@@ -111,6 +127,12 @@ vi.mock('./utils/cursorAcpBackend', () => ({
|
||||
currentModelId: 'composer-2.5[fast=true]'
|
||||
})),
|
||||
getConfigOptionByCategory: vi.fn((_sessionId: string, category: string) => {
|
||||
if (category === 'fast' && harness.failFastConfigOption) {
|
||||
return {
|
||||
id: 'fast',
|
||||
options: [{ value: 'false' }, { value: 'true' }]
|
||||
};
|
||||
}
|
||||
if (category === 'mode') {
|
||||
return {
|
||||
id: 'mode-opt',
|
||||
@@ -124,15 +146,7 @@ vi.mock('./utils/cursorAcpBackend', () => ({
|
||||
if (category === 'model') {
|
||||
return {
|
||||
id: 'model-opt',
|
||||
options: [
|
||||
{ value: 'default[]' },
|
||||
{ value: 'composer-2.5[fast=true]' },
|
||||
{ value: 'composer-2.5[fast=false]' },
|
||||
{ value: 'gpt-5.3-codex[reasoning=medium,fast=false]' },
|
||||
{ value: 'gpt-5.3-codex[reasoning=medium,fast=true]' },
|
||||
{ value: 'cursor-grok-4.5-medium' },
|
||||
{ value: 'cursor-grok-4.5-medium-fast' },
|
||||
]
|
||||
options: harness.modelOptionValues.map((value) => ({ value }))
|
||||
};
|
||||
}
|
||||
return undefined;
|
||||
@@ -285,6 +299,16 @@ describe('cursorAcpRemoteLauncher', () => {
|
||||
harness.loadSessionError = null;
|
||||
harness.newSessionError = null;
|
||||
harness.failSetConfigOption = false;
|
||||
harness.failFastConfigOption = false;
|
||||
harness.modelOptionValues = [
|
||||
'default[]',
|
||||
'composer-2.5[fast=true]',
|
||||
'composer-2.5[fast=false]',
|
||||
'gpt-5.3-codex[reasoning=medium,fast=false]',
|
||||
'gpt-5.3-codex[reasoning=medium,fast=true]',
|
||||
'cursor-grok-4.5-medium',
|
||||
'cursor-grok-4.5-medium-fast',
|
||||
];
|
||||
harness.supportsLoadSession = true;
|
||||
harness.loadSessionCalled = false;
|
||||
harness.newSessionCalled = false;
|
||||
@@ -596,6 +620,15 @@ describe('cursorAcpRemoteLauncher', () => {
|
||||
expect(legacyLauncher).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('pins CLI auto with --model auto on spawn', async () => {
|
||||
const session = makeSession(null);
|
||||
session.model = 'auto';
|
||||
await cursorAcpRemoteLauncher(session);
|
||||
|
||||
expect(harness.backendArgs).toEqual({ command: 'agent', args: ['--model', 'auto', 'acp'] });
|
||||
expect(session.model).toBe('auto');
|
||||
});
|
||||
|
||||
it('applies harness thinking transitions once per edge (#1470)', async () => {
|
||||
const keepAlive = vi.fn();
|
||||
const queue = new MessageQueue2<EnhancedMode>(() => 'mode');
|
||||
@@ -1533,7 +1566,7 @@ describe('cursorAcpRemoteLauncher', () => {
|
||||
await runPromise;
|
||||
});
|
||||
|
||||
it('applies ACP default model when setModel is cleared', async () => {
|
||||
it('does not claim live Auto when ACP has no auto option', async () => {
|
||||
const queue = new MessageQueue2<EnhancedMode>((mode) => mode.permissionMode);
|
||||
const client = {
|
||||
rpcHandlerManager: { registerHandler: vi.fn() },
|
||||
@@ -1575,16 +1608,14 @@ describe('cursorAcpRemoteLauncher', () => {
|
||||
});
|
||||
|
||||
harness.setConfigOptionCalls.length = 0;
|
||||
session.setModel(null);
|
||||
session.setModel('auto');
|
||||
|
||||
await vi.waitFor(() => {
|
||||
expect(
|
||||
harness.setConfigOptionCalls.some(
|
||||
(call) => call.configId === 'model-opt' && call.value === 'default[]'
|
||||
)
|
||||
).toBe(true);
|
||||
expect(session.model).toBeUndefined();
|
||||
expect(session.model).toBe('composer-2.5[fast=false]');
|
||||
});
|
||||
await new Promise((resolve) => setTimeout(resolve, 30));
|
||||
expect(session.model).toBe('composer-2.5[fast=false]');
|
||||
expect(harness.setConfigOptionCalls.filter((call) => call.configId === 'model-opt')).toEqual([]);
|
||||
|
||||
queue.close();
|
||||
await runPromise;
|
||||
@@ -1634,7 +1665,7 @@ describe('cursorAcpRemoteLauncher', () => {
|
||||
await runPromise;
|
||||
});
|
||||
|
||||
it('applyModelConfig(null) resets ACP to the default model option', async () => {
|
||||
it('rejects live applyModelConfig Auto when ACP has no auto option', async () => {
|
||||
const queue = new MessageQueue2<EnhancedMode>((mode) => mode.permissionMode);
|
||||
const client = {
|
||||
rpcHandlerManager: { registerHandler: vi.fn() },
|
||||
@@ -1669,11 +1700,59 @@ describe('cursorAcpRemoteLauncher', () => {
|
||||
await session.applyModelConfig('composer-2.5[fast=false]');
|
||||
harness.setConfigOptionCalls.length = 0;
|
||||
|
||||
await session.applyModelConfig(null);
|
||||
await expect(session.applyModelConfig('auto')).rejects.toThrow(
|
||||
'Cursor Auto requires restarting with --model auto'
|
||||
);
|
||||
|
||||
expect(session.model).toBe('composer-2.5[fast=false]');
|
||||
expect(harness.setConfigOptionCalls.filter((call) => call.configId === 'model-opt')).toEqual([]);
|
||||
|
||||
queue.close();
|
||||
await runPromise;
|
||||
});
|
||||
|
||||
it('applies Auto via ACP when the catalog advertises auto', async () => {
|
||||
harness.modelOptionValues = ['auto', 'composer-2.5[fast=false]'];
|
||||
const queue = new MessageQueue2<EnhancedMode>((mode) => mode.permissionMode);
|
||||
const client = {
|
||||
rpcHandlerManager: { registerHandler: vi.fn() },
|
||||
updateMetadata: vi.fn(),
|
||||
flushMetadata: vi.fn(async () => true),
|
||||
sendSessionEvent: vi.fn(),
|
||||
sendAgentMessage: vi.fn(),
|
||||
keepAlive: vi.fn(),
|
||||
emitSessionReady: vi.fn()
|
||||
} as unknown as ApiSessionClient;
|
||||
|
||||
const session = new CursorSession({
|
||||
api: {} as never,
|
||||
client,
|
||||
path: '/tmp/project',
|
||||
logPath: '/tmp/log',
|
||||
sessionId: null,
|
||||
messageQueue: queue,
|
||||
onModeChange: vi.fn(),
|
||||
mode: 'remote',
|
||||
startedBy: 'runner',
|
||||
startingMode: 'remote',
|
||||
permissionMode: 'default'
|
||||
});
|
||||
session.onSessionFoundWithProtocol = vi.fn();
|
||||
queue.push('hold-open', { permissionMode: 'default' });
|
||||
|
||||
const runPromise = cursorAcpRemoteLauncher(session);
|
||||
await vi.waitFor(() => expect(harness.newSessionCalled).toBe(true));
|
||||
await vi.waitFor(() => expect(session.canApplyModelConfig()).toBe(true));
|
||||
|
||||
await session.applyModelConfig('composer-2.5[fast=false]');
|
||||
harness.setConfigOptionCalls.length = 0;
|
||||
|
||||
await session.applyModelConfig('auto');
|
||||
|
||||
expect(session.model).toBe('auto');
|
||||
expect(
|
||||
harness.setConfigOptionCalls.some(
|
||||
(call) => call.configId === 'model-opt' && call.value === 'default[]'
|
||||
(call) => call.configId === 'model-opt' && call.value === 'auto'
|
||||
)
|
||||
).toBe(true);
|
||||
|
||||
@@ -1681,6 +1760,127 @@ describe('cursorAcpRemoteLauncher', () => {
|
||||
await runPromise;
|
||||
});
|
||||
|
||||
it('rejects applyModelConfig Auto when advertised auto cannot be set', async () => {
|
||||
harness.modelOptionValues = ['auto', 'composer-2.5[fast=false]'];
|
||||
harness.failSetConfigOption = true;
|
||||
const queue = new MessageQueue2<EnhancedMode>((mode) => mode.permissionMode);
|
||||
const client = {
|
||||
rpcHandlerManager: { registerHandler: vi.fn() },
|
||||
updateMetadata: vi.fn(),
|
||||
flushMetadata: vi.fn(async () => true),
|
||||
sendSessionEvent: vi.fn(),
|
||||
sendAgentMessage: vi.fn(),
|
||||
keepAlive: vi.fn(),
|
||||
emitSessionReady: vi.fn()
|
||||
} as unknown as ApiSessionClient;
|
||||
|
||||
const session = new CursorSession({
|
||||
api: {} as never,
|
||||
client,
|
||||
path: '/tmp/project',
|
||||
logPath: '/tmp/log',
|
||||
sessionId: null,
|
||||
messageQueue: queue,
|
||||
onModeChange: vi.fn(),
|
||||
mode: 'remote',
|
||||
startedBy: 'runner',
|
||||
startingMode: 'remote',
|
||||
permissionMode: 'default'
|
||||
});
|
||||
session.onSessionFoundWithProtocol = vi.fn();
|
||||
queue.push('hold-open', { permissionMode: 'default' });
|
||||
|
||||
const runPromise = cursorAcpRemoteLauncher(session);
|
||||
await vi.waitFor(() => expect(harness.newSessionCalled).toBe(true));
|
||||
await vi.waitFor(() => expect(session.canApplyModelConfig()).toBe(true));
|
||||
|
||||
await expect(session.applyModelConfig('auto')).rejects.toThrow(
|
||||
'Cursor auto model is not available via ACP'
|
||||
);
|
||||
expect(session.model).not.toBe('auto');
|
||||
|
||||
queue.close();
|
||||
await runPromise;
|
||||
});
|
||||
|
||||
it.each([[false, false], [true, false], [false, true], [true, true]])('rejects Auto after an Auto-spawned concrete switch (partial=%s, concurrent=%s)', async (partial, concurrent) => {
|
||||
const queue = new MessageQueue2<EnhancedMode>((mode) => mode.permissionMode);
|
||||
const client = {
|
||||
rpcHandlerManager: { registerHandler: vi.fn() },
|
||||
updateMetadata: vi.fn(),
|
||||
flushMetadata: vi.fn(async () => true),
|
||||
sendSessionEvent: vi.fn(),
|
||||
sendAgentMessage: vi.fn(),
|
||||
keepAlive: vi.fn(),
|
||||
emitSessionReady: vi.fn()
|
||||
} as unknown as ApiSessionClient;
|
||||
|
||||
const session = new CursorSession({
|
||||
api: {} as never,
|
||||
client,
|
||||
path: '/tmp/project',
|
||||
logPath: '/tmp/log',
|
||||
sessionId: null,
|
||||
messageQueue: queue,
|
||||
onModeChange: vi.fn(),
|
||||
mode: 'remote',
|
||||
startedBy: 'runner',
|
||||
startingMode: 'remote',
|
||||
permissionMode: 'default',
|
||||
model: 'auto'
|
||||
});
|
||||
session.onSessionFoundWithProtocol = vi.fn();
|
||||
queue.push('hold-open', { permissionMode: 'default' });
|
||||
|
||||
const runPromise = cursorAcpRemoteLauncher(session);
|
||||
await vi.waitFor(() => expect(harness.newSessionCalled).toBe(true));
|
||||
await vi.waitFor(() => expect(session.canApplyModelConfig()).toBe(true));
|
||||
expect(harness.backendArgs).toEqual({ command: 'agent', args: ['--model', 'auto', 'acp'] });
|
||||
|
||||
if (partial) {
|
||||
harness.modelOptionValues = ['default', 'composer-2.5'];
|
||||
harness.failFastConfigOption = true;
|
||||
}
|
||||
if (concurrent) {
|
||||
harness.deferSetConfigOption = new Promise<void>((resolve) => {
|
||||
harness.releaseSetConfigOption = resolve;
|
||||
});
|
||||
}
|
||||
const concreteRequest = session.applyModelConfig('composer-2.5[fast=false]');
|
||||
const autoRequest = concurrent
|
||||
? session.applyModelConfig('auto').then(
|
||||
value => ({ value, error: null }),
|
||||
error => ({ value: null, error })
|
||||
)
|
||||
: null;
|
||||
if (concurrent) {
|
||||
await new Promise<void>(resolve => setImmediate(resolve));
|
||||
harness.releaseSetConfigOption?.();
|
||||
}
|
||||
if (partial) {
|
||||
await expect(concreteRequest).rejects.toThrow(
|
||||
'Cursor model is not available via ACP'
|
||||
);
|
||||
} else {
|
||||
await concreteRequest;
|
||||
}
|
||||
if (autoRequest) {
|
||||
expect((await autoRequest).error?.message).toContain('Cursor Auto requires restarting with --model auto');
|
||||
}
|
||||
const concreteModel = partial ? 'composer-2.5' : 'composer-2.5[fast=false]';
|
||||
expect(session.model).toBe(concreteModel);
|
||||
harness.setConfigOptionCalls.length = 0;
|
||||
|
||||
await expect(session.applyModelConfig('auto')).rejects.toThrow(
|
||||
'Cursor Auto requires restarting with --model auto'
|
||||
);
|
||||
expect(session.model).toBe(concreteModel);
|
||||
expect(harness.setConfigOptionCalls.filter((call) => call.configId === 'model-opt')).toEqual([]);
|
||||
|
||||
queue.close();
|
||||
await runPromise;
|
||||
});
|
||||
|
||||
it('rejects applyModelConfig when ACP does not expose the requested model', async () => {
|
||||
const queue = new MessageQueue2<EnhancedMode>((mode) => mode.permissionMode);
|
||||
const client = {
|
||||
|
||||
Reference in New Issue
Block a user