Skip to content

Commit 61d6d38

Browse files
author
jun
committed
feat(cursor): let the Codex Fast toggle reach Cursor's fast variant
Codex's Fast toggle is OpenAI's service_tier field, and Cursor has no such field - its fast product is a different model variant (claude-opus-5-thinking-high-fast) or a {id:fast} request parameter for Grok. So a service_tier on a Cursor route was silently dropped, and no Cursor row could advertise the toggle at all: FAST_WIRE_ADAPTERS is a closed set that Cursor was not in. Add a cursor-variant FastWire kind, declare it on the Cursor registry entry, and have the request builder consume the tier DECISION (not the raw caller field, so fastMode=false still suppresses a caller's request). A thinking umbrella pick upgrades to thinkingFast rather than the regular-fast sibling, which is a different product with a shorter ladder whose regular family is quarantined for claude-opus-5. Only the five bases that actually declare a fast variant advertise the tier, so there is no dead toggle. That required one more fix: forwardCallerTier ignored the wire's foreignCallerTiers declaration, so an unclassified cursor-variant route projected 'unknown' support - enough for Codex to offer a toggle on kimi-k3, which has no fast variant at all. Telemetry recomputes the variant from the same pure inputs the builder uses. Rebuilding the request there would be wrong twice over: tierLogForRunTurn runs before runTurn, and createCursorRequest mints conversation ids. Also widens the usage/log.ts wireKind allowlist, which silently returns null - dropping the whole tier row - for a kind it does not recognise. Refs devlog/_plan/260902_cursor_unified_identity/020_wp3_codex_fast_toggle.md
1 parent 7aa64bb commit 61d6d38

9 files changed

Lines changed: 233 additions & 15 deletions

File tree

‎src/adapters/cursor.ts‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {
1212
cursorClientThreadOwner,
1313
cursorCoveredPrefixDigest,
1414
cursorInstructionDigest,
15+
cursorRequestEmitsFastVariant,
1516
} from "./cursor/request-builder";
1617
import {
1718
createLiveCursorTransport,
@@ -26,6 +27,7 @@ import {
2627
invalidateCursorCheckpoint,
2728
} from "./cursor/checkpoint-store";
2829
import { debugProviderDiagnostic } from "../lib/debug";
30+
import { createAdapterTierMetadata } from "../providers/fastwire";
2931
import { estimateTokens } from "../lib/token-estimate";
3032
import { rememberCursorThreadConversation } from "./cursor/thread-continuity";
3133
import { runCursorTurnWithRetry } from "./cursor/transport-retry";
@@ -100,6 +102,21 @@ export function createCursorAdapter(provider: OcxProviderConfig, deps: CursorAda
100102
return {
101103
name: "cursor",
102104

105+
// Cursor emits Fast as a model variant, so the generic "no field emitted" fallback in
106+
// adapters/registry.ts would report every Fast turn as downgraded. This recomputes the
107+
// variant from the same pure inputs the builder uses: tierLogForRunTurn runs BEFORE
108+
// runTurn, and createCursorRequest mints conversation ids, so rebuilding it here would
109+
// describe a request that was never sent.
110+
tierLogForRunTurn(parsed) {
111+
const fast = cursorRequestEmitsFastVariant(parsed);
112+
return createAdapterTierMetadata(
113+
parsed.options.tierObservation,
114+
parsed.options.tierDecision,
115+
fast ? "cursor-variant" : null,
116+
fast ? "fast" : null,
117+
);
118+
},
119+
103120
buildRequest() {
104121
return {
105122
url: provider.baseUrl || CURSOR_API_URL,

‎src/adapters/cursor/catalog.ts‎

Lines changed: 39 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -443,6 +443,32 @@ function defaultKindFor(baseId: string): CursorVariantKind {
443443
return CURSOR_CAPABILITIES[baseId]?.defaultVariant ?? "regular";
444444
}
445445

446+
/**
447+
* Promote a variant to its fast sibling when the base declares one, else leave it alone.
448+
*
449+
* Thinking must map to thinkingFast rather than to the plain fast variant: the umbrella row
450+
* for a Claude base routes THINKING, and its regular-fast sibling is a different product
451+
* with a shorter ladder (claude-opus-5-fast stops at high) whose regular family is
452+
* quarantined. A base with no fast dimension keeps its kind, so Fast degrades to today's
453+
* behavior instead of erroring.
454+
*/
455+
export function upgradeToFast(baseId: string, kind: CursorVariantKind): CursorVariantKind {
456+
const variants = CURSOR_CAPABILITIES[baseId]?.variants;
457+
if (!variants) return kind;
458+
if (kind === "thinking" || kind === "thinkingFast") {
459+
return variants.thinkingFast ? "thinkingFast" : kind;
460+
}
461+
return variants.fast ? "fast" : kind;
462+
}
463+
464+
/** Bases whose capability declares a fast or thinking-fast variant. */
465+
export function cursorFastCapableBases(): string[] {
466+
return Object.entries(CURSOR_CAPABILITIES)
467+
.filter(([, capability]) => capability.variants.fast !== undefined
468+
|| capability.variants.thinkingFast !== undefined)
469+
.map(([baseId]) => baseId);
470+
}
471+
446472
function normalizeRequestedEffort(reasoning: string | undefined): string | undefined {
447473
const normalized = reasoning?.toLowerCase();
448474
return normalized === "ultra" ? "max" : normalized;
@@ -523,20 +549,25 @@ export function resolveCursorSelection(
523549
pickedId: string,
524550
reasoning: string | undefined,
525551
liveMaxModeIds?: ReadonlySet<string>,
552+
options: { fast?: boolean } = {},
526553
): CursorResolvedSelection {
527554
const parsed = parseCursorVariantId(pickedId);
528555
if (!parsed.known) {
529556
return { wireId: pickedId, canonicalId: pickedId, maxMode: false, known: false };
530557
}
531558
const capability = CURSOR_CAPABILITIES[parsed.baseId]!;
532-
const spec = capability.variants[parsed.kind] ?? capability.variants.regular;
559+
// Codex's Fast toggle is a variant switch here; every later read must use the upgraded
560+
// kind, not parsed.kind, or the wire id loses its -fast marker (or keeps the cursor-
561+
// prefix that only the regular variant takes).
562+
const kind = options.fast === true ? upgradeToFast(parsed.baseId, parsed.kind) : parsed.kind;
563+
const spec = capability.variants[kind] ?? capability.variants.regular;
533564
if (!spec) {
534565
return { wireId: parsed.baseId, canonicalId: parsed.baseId, maxMode: false, known: true };
535566
}
536567
const requested = parsed.level ?? reasoning;
537568
const effort = cursorVariantEffort(spec, requested);
538-
const canonicalId = composeWireId(parsed.baseId, parsed.kind, effort);
539-
const wireId = capability.wirePrefix && parsed.kind === "regular"
569+
const canonicalId = composeWireId(parsed.baseId, kind, effort);
570+
const wireId = capability.wirePrefix && kind === "regular"
540571
? `${capability.wirePrefix}${canonicalId}`
541572
: canonicalId;
542573
const ultraRequested = parsed.ultra || reasoning?.toLowerCase() === "ultra";
@@ -584,9 +615,13 @@ export interface CursorUmbrellaRow {
584615
export function cursorGrokFastSelection(
585616
pickedId: string,
586617
reasoning: string | undefined,
618+
fast?: boolean,
587619
): { wireBaseId: string; effort: string } | undefined {
588620
const parsed = parseCursorVariantId(pickedId);
589-
if (!parsed.known || parsed.kind !== "fast") return undefined;
621+
// Both call paths must learn the flag together: if only resolveCursorSelection did, a
622+
// toggled Grok pick would emit a flattened grok-4.6-high-fast id, which the wire rejects.
623+
const kind = fast === true ? upgradeToFast(parsed.baseId, parsed.kind) : parsed.kind;
624+
if (!parsed.known || kind !== "fast") return undefined;
590625
const capability = CURSOR_CAPABILITIES[parsed.baseId];
591626
if (capability?.wirePrefix !== "cursor-") return undefined;
592627
const spec = capability.variants.fast;

‎src/adapters/cursor/request-builder.ts‎

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -180,13 +180,40 @@ function catalogLimitNote(kept: readonly OcxTool[], omitted: readonly OcxTool[])
180180
: `[opencodex] Cursor's transport limit allows ${kept.length} of ${kept.length + omitted.length} client tools this turn. Omitted and unavailable this turn: ${omittedSummary}.`;
181181
}
182182

183+
/**
184+
* True when this turn should take Cursor's fast variant.
185+
*
186+
* Reads the tier DECISION rather than the raw caller field so one authority owns precedence:
187+
* `decideTier` has already applied config `fastMode`, the caller's `service_tier`, and the
188+
* route's eligibility, so `fastMode: false` correctly suppresses a caller's Fast request.
189+
* A `{kind:"set"}` decision on a Cursor route means canonical Fast survived that gate.
190+
*/
191+
export function cursorFastRequested(parsed: OcxParsedRequest): boolean {
192+
return parsed.options.tierDecision?.kind === "set";
193+
}
194+
195+
/**
196+
* Whether the wire this request will carry expresses the fast variant, for tier telemetry.
197+
*
198+
* Recomputed from the same pure inputs the builder uses rather than read off a built
199+
* request: `tierLogForRunTurn` runs BEFORE `runTurn` (server/responses/core.ts), and
200+
* `createCursorRequest` is not pure — it mints conversation ids — so rebuilding there would
201+
* report a request that was never sent.
202+
*/
203+
export function cursorRequestEmitsFastVariant(parsed: OcxParsedRequest): boolean {
204+
if (!cursorFastRequested(parsed)) return false;
205+
const model = normalizeCursorModelId(parsed.modelId, parsed.options.reasoning, true);
206+
return model.modelId.endsWith("-fast")
207+
|| (model.requestedModelParameters ?? []).some(p => p.id === "fast" && p.value === "true");
208+
}
209+
183210
/**
184211
* Resolve a `cursor/<model>` selection + Codex reasoning effort to Cursor's requested model shape.
185212
* Most models encode effort in a flat id (`claude-4.6-opus-high`). Grok Fast is parameterized
186213
* instead: current Cursor clients send the matching Grok base id plus `effort` and `fast` parameters.
187214
* A fully-qualified id (one that is not a known effort base) passes through unchanged.
188215
*/
189-
function normalizeCursorModelId(modelId: string, reasoning?: string): {
216+
function normalizeCursorModelId(modelId: string, reasoning?: string, fast?: boolean): {
190217
modelId: string;
191218
requestedModelParameters?: readonly CursorRequestedModelParameter[];
192219
routingLevel?: CursorRoutingLevel;
@@ -201,7 +228,7 @@ function normalizeCursorModelId(modelId: string, reasoning?: string): {
201228
const id = selection.modelId;
202229
// Grok Fast stays parameterized: current Cursor clients send the base id
203230
// plus effort/fast parameters instead of the flattened -fast id.
204-
const grokFast = cursorGrokFastSelection(id, reasoning);
231+
const grokFast = cursorGrokFastSelection(id, reasoning, fast);
205232
if (grokFast) {
206233
return {
207234
...selection,
@@ -212,7 +239,7 @@ function normalizeCursorModelId(modelId: string, reasoning?: string): {
212239
],
213240
};
214241
}
215-
const resolved = resolveCursorSelection(id, reasoning);
242+
const resolved = resolveCursorSelection(id, reasoning, undefined, { fast });
216243
return {
217244
...selection,
218245
...(resolved.maxMode ? { maxMode: true } : {}),
@@ -455,7 +482,7 @@ export function createCursorRequest(
455482
const visibleTools = cursorToolsForActivePrompt(parsed.context.tools, activeText, parsed.options.toolChoice);
456483
const budget = applyCursorToolBudget(visibleTools, parsed.options.toolChoice);
457484
const limitNote = catalogLimitNote(budget.tools, budget.omitted);
458-
const model = normalizeCursorModelId(parsed.modelId, parsed.options.reasoning);
485+
const model = normalizeCursorModelId(parsed.modelId, parsed.options.reasoning, cursorFastRequested(parsed));
459486
const request: CursorRunRequest = {
460487
modelId: model.modelId,
461488
...(model.requestedModelParameters ? { requestedModelParameters: model.requestedModelParameters } : {}),

‎src/providers/fastwire.ts‎

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ const FAST_WIRE_ADAPTERS: Readonly<Record<FastWire["kind"], ReadonlySet<string>>
1414
"service-tier": SERVICE_TIER_ADAPTERS,
1515
// A1 deliberately has no adapter implementation for Anthropic speed.
1616
"anthropic-speed": new Set(),
17+
// Cursor expresses Fast as a variant dimension of the picked model, resolved in the
18+
// request builder, so the adapter set is exactly the cursor adapter.
19+
"cursor-variant": new Set(["cursor"]),
1720
};
1821

1922
const DEFAULT_SERVICE_TIER_FAST_WIRE: FastWire = Object.freeze({
@@ -209,8 +212,13 @@ export function resolveFastPolicy(
209212
// On classified routes this permission applies only to a caller's foreign tier: proxy-owned
210213
// canonical Fast has already passed capability validation. On unclassified routes every caller
211214
// tier still needs the final wire's forwarding permission.
215+
// A wire that declares `foreignCallerTiers: "drop"` cannot carry an arbitrary tier string at
216+
// all — cursor-variant resolves a MODEL VARIANT, so there is nothing to forward a foreign
217+
// value into. Without this, an unclassified route on such a wire projects "unknown" support
218+
// and Codex would show a Fast toggle on a base that has no fast variant.
212219
const forwardCallerTier = capability !== false
213220
&& callerWireAvailable
221+
&& fastWire?.foreignCallerTiers !== "drop"
214222
&& forwardCallerServiceTier !== false
215223
&& (adapter !== "openai-chat" || authority.capability.chatServiceTier === true);
216224

@@ -467,8 +475,8 @@ export function fastWireDeclarationError(source: {
467475
}
468476
if (value === null) return null;
469477
if (!isPlainRecord(value)) return "fastWire must be an object, null, or absent";
470-
if (value.kind !== "service-tier" && value.kind !== "anthropic-speed") {
471-
return "fastWire.kind must be service-tier or anthropic-speed";
478+
if (value.kind !== "service-tier" && value.kind !== "anthropic-speed" && value.kind !== "cursor-variant") {
479+
return "fastWire.kind must be service-tier, anthropic-speed, or cursor-variant";
472480
}
473481
if (value.foreignCallerTiers !== "verbatim" && value.foreignCallerTiers !== "drop") {
474482
return "fastWire.foreignCallerTiers must be verbatim or drop";

‎src/providers/registry.ts‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import {
1818
cursorModelInputModalities,
1919
cursorModelReasoningEfforts,
2020
} from "../adapters/cursor/discovery";
21+
import { cursorFastCapableBases } from "../adapters/cursor/catalog";
2122
import { COMMAND_CODE_MODEL_REASONING_EFFORTS } from "./command-code-efforts";
2223
import { isCanonicalOpenRouterTarget } from "./openrouter-routing";
2324

@@ -1120,6 +1121,15 @@ export const PROVIDER_REGISTRY: readonly ProviderRegistryEntry[] = [
11201121
defaultModel: "auto",
11211122
modelContextWindows: cursorModelContextWindows(CURSOR_STATIC_MODELS),
11221123
modelDisplayNames: cursorModelDisplayNames(),
1124+
// Cursor's Fast product is a model VARIANT, not a service_tier field, so the wire kind
1125+
// is cursor-variant and the request builder consumes the decision.
1126+
fastWire: { kind: "cursor-variant", canonicalToWire: { priority: "fast" }, foreignCallerTiers: "drop" },
1127+
// Deliberately NO provider-level supportsServiceTier: resolveFastPolicy short-circuits on
1128+
// `capability.provider === false` BEFORE consulting the per-model map, which would make
1129+
// these entries dead config. Absent leaves unlisted bases "unclassified", and a
1130+
// non-service-tier adapter cannot forward a caller tier, so they still publish no toggle.
1131+
modelSupportsServiceTier: Object.fromEntries(cursorFastCapableBases().map(id => [id, true])),
1132+
fastTierDescription: "Cursor Fast variant",
11231133
modelInputModalities: cursorModelInputModalities(CURSOR_STATIC_MODELS),
11241134
modelReasoningEfforts: cursorModelReasoningEfforts(CURSOR_STATIC_MODELS),
11251135
// Kimi K3 documents `max` as its API default, and its Cursor ladder has no `medium`

‎src/types/provider.ts‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,13 @@ export interface ProviderRequestPacingConfig extends RequestPacingRule {
106106
}
107107

108108
export interface FastWire {
109-
kind: "service-tier" | "anthropic-speed";
109+
/**
110+
* How the provider expresses Fast on the wire. `service-tier` is OpenAI's
111+
* `service_tier` request field; `cursor-variant` is a MODEL-VARIANT switch, because
112+
* Cursor has no tier field — its fast product is a different model id
113+
* (`claude-opus-5-thinking-high-fast`) or a `{id:"fast"}` request parameter for Grok.
114+
*/
115+
kind: "service-tier" | "anthropic-speed" | "cursor-variant";
110116
/** Canonical tier name to upstream wire spelling. */
111117
canonicalToWire: Readonly<Record<string, string>>;
112118
/** Policy for non-canonical caller-provided tier values. */

‎src/usage/log.ts‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,8 @@ function normalizeAttemptTierOutcome(raw: unknown): AttemptTierOutcome | null {
322322
if ("wireKind" in outcome
323323
&& outcome.wireKind !== null
324324
&& outcome.wireKind !== "service-tier"
325-
&& outcome.wireKind !== "anthropic-speed") return null;
325+
&& outcome.wireKind !== "anthropic-speed"
326+
&& outcome.wireKind !== "cursor-variant") return null;
326327
if ("wireValue" in outcome && outcome.wireValue !== null && typeof outcome.wireValue !== "string") return null;
327328
if ("fastDowngradeReason" in outcome
328329
&& (typeof outcome.fastDowngradeReason !== "string"
@@ -337,7 +338,10 @@ function normalizeAttemptTierOutcome(raw: unknown): AttemptTierOutcome | null {
337338
const responseServiceTier = sanitizeLogMetadataString(outcome.responseServiceTier);
338339
return {
339340
...(outcome.canonical === "priority" ? { canonical: "priority" as const } : {}),
340-
...(outcome.wireKind === null || outcome.wireKind === "service-tier" || outcome.wireKind === "anthropic-speed"
341+
...(outcome.wireKind === null
342+
|| outcome.wireKind === "service-tier"
343+
|| outcome.wireKind === "anthropic-speed"
344+
|| outcome.wireKind === "cursor-variant"
341345
? { wireKind: outcome.wireKind }
342346
: {}),
343347
...(outcome.wireValue === null

0 commit comments

Comments
 (0)