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:
SSU-WEI HUANG
2026-09-16 08:12:16 +08:00
committed by GitHub
co-authored by Cursor
parent 8f9d6bd7f8
commit ca1fd80afd
34 changed files with 977 additions and 199 deletions
@@ -30,7 +30,8 @@ export async function runCursorAcpModelProbe(cwd?: string): Promise<ListCursorMo
const response: ListCursorModelsResponse = {
success: true,
availableModels: snapshot.availableModels,
currentModelId: snapshot.currentModelId
currentModelId: snapshot.currentModelId,
...(snapshot.parameterized ? { parameterized: true } : {})
};
if (!hasAcpWireCatalog(response)) {
return { success: false, error: 'Cursor ACP catalog has no wire model ids' };
@@ -273,6 +273,50 @@ describe('listCursorModels', () => {
expect(spawnMock).not.toHaveBeenCalled()
})
test('attaches variant cliModelSkus to parameterized bare base catalogs (#1818)', async () => {
vi.mocked(isAgentAcpTransportActive).mockReturnValue(true)
const bareCatalog = [
{ modelId: 'composer-2.5', name: 'Composer 2.5' },
{ modelId: 'claude-opus-4-8', name: 'Claude Opus 4.8' },
{ modelId: 'grok-4.6', name: 'Cursor Grok 4.6' }
]
setCursorAcpModelsSnapshot({
availableModels: bareCatalog,
currentModelId: 'composer-2.5',
parameterized: true
})
writeSharedCursorModelsCache({
success: true,
parameterized: true,
availableModels: bareCatalog,
currentModelId: 'composer-2.5',
cliModelSkus: [
{ modelId: 'composer-2.5', name: 'Composer 2.5' },
{ modelId: 'composer-2.5-fast', name: 'Composer 2.5 Fast' },
{ modelId: 'claude-opus-4-8-low', name: 'Claude Opus 4.8 Low' },
{ modelId: 'cursor-grok-4.6-high', name: 'Cursor Grok 4.6' }
]
})
const result = await listCursorModels()
expect(result.availableModels?.map((row) => row.modelId)).toEqual([
'composer-2.5',
'claude-opus-4-8',
'grok-4.6'
])
// Parameterized ACP sessions apply fast/effort over config options, so the
// spawn-safe variant skus stay attached to their bare base rows — including
// CLI skus that keep Cursor's legacy `cursor-` family prefix.
expect(result.cliModelSkus?.map((row) => row.modelId)).toEqual([
'composer-2.5',
'composer-2.5-fast',
'claude-opus-4-8-low',
'cursor-grok-4.6-high'
])
expect(spawnMock).not.toHaveBeenCalled()
})
test('enriches live ACP snapshot with fuller shared cliModelSkus while lock is active', async () => {
vi.mocked(isAgentAcpTransportActive).mockReturnValue(true)
setCursorAcpModelsSnapshot({
+18 -12
View File
@@ -18,6 +18,7 @@ import {
import {
cursorCliSkuBaseId,
cursorModelBaseId,
cursorModelBaseMatches,
isCursorAcpCatalogModelId,
isCursorAcpWireModelId
} from '@hapi/protocol';
@@ -31,6 +32,7 @@ export function buildCursorModelsSeedPayload(
availableModels: CursorModelSummary[];
currentModelId: string | null;
cliModelSkus?: readonly CursorModelSummary[];
parameterized?: boolean;
},
shared?: CursorModelsResponse | null
): ListCursorModelsResponse {
@@ -42,6 +44,7 @@ export function buildCursorModelsSeedPayload(
success: true,
availableModels: snapshot.availableModels,
currentModelId: snapshot.currentModelId,
...(snapshot.parameterized ? { parameterized: true } : {}),
...(cliModelSkus.length > 0 ? { cliModelSkus } : {})
};
}
@@ -68,9 +71,9 @@ function filterCliSkusForWireBases(
cliSkus: CursorModelSummary[],
wires: CursorModelSummary[]
): CursorModelSummary[] {
const wireBases = new Set(
wires.map((entry) => cursorModelBaseId(entry.modelId)).filter((base) => base.length > 0)
);
const wireBases = wires
.map((entry) => cursorModelBaseId(entry.modelId))
.filter((base) => base.length > 0);
return cliSkus.filter((entry) => {
const modelId = entry.modelId.trim();
@@ -78,7 +81,8 @@ function filterCliSkusForWireBases(
if (!modelId || modelId === 'auto' || isCursorAcpWireModelId(modelId)) {
return false;
}
return wireBases.has(cursorCliSkuBaseId(modelId));
const skuBase = cursorCliSkuBaseId(modelId);
return wireBases.some((base) => cursorModelBaseMatches(skuBase, base));
});
}
@@ -87,22 +91,24 @@ function attachCliSkusToResponse(
cliSkus: readonly CursorModelSummary[]
): ListCursorModelsResponse {
const wires = (response.availableModels ?? []).filter((entry) => isCursorAcpCatalogModelId(entry.modelId));
// Suffixed CLI variants (effort/speed) only apply when ACP exposes parameterized
// wires for that base. Bare-only catalogs cannot express those variants
// (apply path is model + fast at most), so attaching them creates dead picker rows.
const parameterizedBases = new Set(
wires
// Variant skus are only usable when the ACP apply path can express them:
// parameterized pickers apply model + fast + thought_level over config options,
// and wire catalogs already pair each variant with a base wire. Bare-only
// catalogs without the parameterized picker keep base rows only.
const applyableBases = (response.parameterized === true
? wires.map((entry) => cursorModelBaseId(entry.modelId))
: wires
.filter((entry) => isCursorAcpWireModelId(entry.modelId))
.map((entry) => cursorModelBaseId(entry.modelId))
.filter((base) => base.length > 0)
);
).filter((base) => base.length > 0);
const filtered = filterCliSkusForWireBases(
mergeCliModelSkus(response.cliModelSkus ?? [], [...cliSkus]),
wires
).filter((entry) => {
const modelId = entry.modelId.trim();
const base = cursorCliSkuBaseId(modelId);
return modelId === base || parameterizedBases.has(base);
return modelId === base
|| applyableBases.some((candidate) => cursorModelBaseMatches(base, candidate));
});
if (filtered.length === 0) {
return response.cliModelSkus?.length
@@ -1,5 +1,5 @@
import { afterAll, afterEach, describe, expect, test } from 'vitest';
import { mkdtempSync, rmSync } from 'node:fs';
import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from 'node:fs';
import { tmpdir } from 'node:os';
import { join } from 'node:path';
import {
@@ -59,4 +59,21 @@ describe('cursorModelsSharedCache', () => {
expect(readSharedCursorModelsCache()?.cliModelSkus).toEqual(payload.cliModelSkus);
});
test('ignores pre-versioned cache files that carry synthesized wire ids', () => {
// v1 files carried `[fast=…]` wires Cursor rejects; a runner must re-probe
// instead of serving them forever (listCursorModels trusts the cache).
mkdirSync(join(testHapiHome, 'cache'), { recursive: true });
writeFileSync(
join(testHapiHome, 'cache', 'cursor-models.json'),
JSON.stringify({
success: true,
availableModels: [{ modelId: 'grok-4.6[fast=false]', name: 'Cursor Grok 4.6' }],
currentModelId: 'grok-4.6[fast=false]'
}),
'utf8'
);
expect(readSharedCursorModelsCache()).toBeNull();
});
});
@@ -18,6 +18,18 @@ function isUsableModelsResponse(response: CursorModelsResponse | null): response
);
}
/**
* Bumped when a cached catalog can no longer be trusted. v1 carried synthesized
* `[fast=…]` wire ids that Cursor rejects at `session/new`; `listCursorModels`
* serves the on-disk cache without re-probing, so stale entries must not be read.
*/
const SHARED_CACHE_VERSION = 2;
type SharedCacheEnvelope = {
version: number;
response: CursorModelsResponse;
};
/** Cross-process catalog for New Session while an ACP lock blocks `agent --list-models`. */
export function readSharedCursorModelsCache(): CursorModelsResponse | null {
const path = getSharedCachePath();
@@ -26,8 +38,12 @@ export function readSharedCursorModelsCache(): CursorModelsResponse | null {
}
try {
const parsed = JSON.parse(readFileSync(path, 'utf8')) as CursorModelsResponse;
return isUsableModelsResponse(parsed) ? parsed : null;
const parsed = JSON.parse(readFileSync(path, 'utf8')) as Partial<SharedCacheEnvelope> | null;
if (!parsed || parsed.version !== SHARED_CACHE_VERSION) {
return null;
}
const response = parsed.response ?? null;
return isUsableModelsResponse(response) ? response : null;
} catch {
return null;
}
@@ -41,7 +57,8 @@ export function writeSharedCursorModelsCache(response: CursorModelsResponse): vo
const path = getSharedCachePath();
try {
mkdirSync(dirname(path), { recursive: true });
writeFileSync(path, JSON.stringify(response), 'utf8');
const envelope: SharedCacheEnvelope = { version: SHARED_CACHE_VERSION, response };
writeFileSync(path, JSON.stringify(envelope), 'utf8');
} catch {
// Best effort — in-process cache still works in the session child.
}