Skip to content

Commit c2c380f

Browse files
committed
fix(google-antigravity): route gemini-3.7-flash to suffixed wire tiers
The CCA backend gates gemini-3.7-flash by wire id: the envelope 404s on the bare id (and on thinkingConfig tiers riding it), while only the suffixed wire ids gemini-3.7-flash-low/-medium/-high are real upstream entities. Proven live: bare id + thinkingLevel=medium -> 404; all three suffixed ids -> 200. Route the picker base through ANTIGRAVITY_FLASH_WIRE_TIERS so every effort lands on a suffixed wire id, with the tier still carried as thinkingLevel. Retired 3.6/3.5 tier ids now land on the matching 3.7 suffix. The bare id must never reach the wire — guarded by a regression test.
1 parent 936e708 commit c2c380f

4 files changed

Lines changed: 110 additions & 68 deletions

File tree

‎src/providers/antigravity-models.ts‎

Lines changed: 44 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,27 @@ import { isValidModelDiscoveryModelId, MODEL_DISCOVERY_MAX_MODELS } from "./mode
1111

1212
// ── Wire IDs (what CCA :fetchAvailableModels returns) ──
1313

14-
/** Current Antigravity Flash generation. */
14+
/**
15+
* Current Antigravity Flash generation: tier → the wire id that actually exists.
16+
*
17+
* Proven against the live backend: the CCA envelope 404s on the bare id
18+
* `gemini-3.7-flash` and on `thinkingConfig` tiers riding that bare id — only the
19+
* SUFFIXED wire ids (`gemini-3.7-flash-low/-medium/-high`) are real entities.
20+
* Every request must therefore land on a suffixed id; the bare id stays the
21+
* picker identity that the resolver maps to the current default tier.
22+
*/
23+
const ANTIGRAVITY_FLASH_WIRE_TIERS: Record<string, string> = {
24+
low: "gemini-3.7-flash-low",
25+
medium: "gemini-3.7-flash-medium",
26+
high: "gemini-3.7-flash-high",
27+
};
28+
29+
/** Picker identity of the current Flash generation (a collapsed base, not a wire id). */
1530
const GEMINI_FLASH_CURRENT = "gemini-3.7-flash";
1631

32+
/** Default tier for the bare 3.7 picker id — matches the previous generation's default. */
33+
const ANTIGRAVITY_FLASH_DEFAULT_TIER = "medium";
34+
1735
/**
1836
* Retired Flash ids → the reasoning tier they used to encode.
1937
*
@@ -23,9 +41,6 @@ const GEMINI_FLASH_CURRENT = "gemini-3.7-flash";
2341
* alias as "the suffix IS the effort" and deliberately sends no thinkingConfig, so
2442
* `gemini-3.6-flash-high` would silently become an untiered 3.7 call. Carrying the
2543
* level here preserves what the user actually chose.
26-
*
27-
* 3.7 exposes tiers through `thinkingLevel` on ONE wire id rather than through
28-
* suffixed wire ids, which is why the mapping is id → level and not id → id.
2944
*/
3045
const RETIRED_FLASH_TIERS: Record<string, string> = {
3146
// 3.6 generation.
@@ -42,7 +57,9 @@ const RETIRED_FLASH_TIERS: Record<string, string> = {
4257
};
4358

4459
const ANTIGRAVITY_WIRE_MODELS = [
45-
"gemini-3.7-flash",
60+
"gemini-3.7-flash-low",
61+
"gemini-3.7-flash-medium",
62+
"gemini-3.7-flash-high",
4663
"gemini-3.1-pro-low",
4764
"gemini-pro-agent",
4865
"gemini-3.1-flash-image",
@@ -110,6 +127,7 @@ export const ANTIGRAVITY_MODEL_EFFORTS: Record<string, string[]> = {
110127

111128
// ── Effort → wire model map for Gemini base models ──
112129
const ANTIGRAVITY_EFFORT_WIRE_MAP: Record<string, Record<string, string>> = {
130+
"gemini-3.7-flash": ANTIGRAVITY_FLASH_WIRE_TIERS,
113131
"gemini-3.1-pro": {
114132
low: "gemini-3.1-pro-low",
115133
high: "gemini-pro-agent",
@@ -118,17 +136,10 @@ const ANTIGRAVITY_EFFORT_WIRE_MAP: Record<string, Record<string, string>> = {
118136

119137
// ── Default effort per Gemini base model ──
120138
const ANTIGRAVITY_DEFAULT_EFFORT: Record<string, string> = {
139+
"gemini-3.7-flash": ANTIGRAVITY_FLASH_DEFAULT_TIER,
121140
"gemini-3.1-pro": "high",
122141
};
123142

124-
/**
125-
* Gemini base models whose efforts ride on `thinkingLevel` against a single wire id
126-
* instead of suffixed wire ids, with the level applied when the caller names none.
127-
*/
128-
const ANTIGRAVITY_THINKING_LEVEL_MODELS: Record<string, string> = {
129-
"gemini-3.7-flash": "medium",
130-
};
131-
132143
// `minimal` is deliberately absent: Google documents it as unsupported for the current
133144
// Flash generation, where it is an error rather than a quieter tier.
134145
const ANTIGRAVITY_THINKING_LEVELS = new Set(["low", "medium", "high"]);
@@ -150,6 +161,9 @@ const ANTIGRAVITY_VISIBLE_MODEL_ALIASES: Record<string, string> = {
150161
const ANTIGRAVITY_COMPATIBILITY_MODEL_ALIASES: Record<string, string> = {
151162
"gemini-3.1-pro-low": "gemini-3.1-pro-low",
152163
"gemini-pro-agent": "gemini-pro-agent",
164+
// 3.7 Flash wire tiers are real upstream entities: identity aliases so a saved
165+
// selection with an explicit suffix keeps routing to that exact tier.
166+
...ANTIGRAVITY_FLASH_WIRE_TIERS,
153167
// ── Retired Flash generations ──
154168
// Google takes the previous Antigravity Flash model offline almost immediately
155169
// once its successor ships, so 3.6 (and the 3.5 ids that used to land on it)
@@ -182,7 +196,9 @@ function isKnownAntigravityPickerModelId(value: string): boolean {
182196

183197
// Context windows from the upstream `:fetchAvailableModels` maxTokens per model.
184198
const ANTIGRAVITY_WIRE_MODEL_CONTEXT_WINDOWS: Record<string, number> = {
185-
"gemini-3.7-flash": 1_048_576,
199+
"gemini-3.7-flash-low": 1_048_576,
200+
"gemini-3.7-flash-medium": 1_048_576,
201+
"gemini-3.7-flash-high": 1_048_576,
186202
"gemini-3.1-pro-low": 1_048_576,
187203
"gemini-pro-agent": 1_048_576,
188204
"gemini-3.1-flash-image": 1_048_576,
@@ -341,6 +357,7 @@ export function retiredAntigravityFlashTier(modelId: string): string | undefined
341357
* Resolve a picker-visible base model + optional reasoning effort to the CCA wire model ID.
342358
*
343359
* Precedence (evaluated in order):
360+
* 0. Retired Flash id → current Flash wire id + thinkingLevel carrying the retired tier.
344361
* 1. Suffix wire ID or compat alias → resolve via `resolveAntigravityWireModelId`, no thinkingConfig.
345362
* 2. Mapped Gemini base with effort → return mapped wire ID + thinkingLevel.
346363
* 3. Mapped Gemini base without effort → return default-effort wire ID, no thinkingConfig.
@@ -356,32 +373,27 @@ export function resolveAntigravityEffortWireModel(
356373
// suffix check because those ids are aliases, and rule 1 would drop the tier.
357374
const retiredTier = retiredAntigravityFlashTier(modelId);
358375
if (retiredTier) {
359-
return {
360-
wireModelId: GEMINI_FLASH_CURRENT,
361-
thinkingLevel: effort ? resolveAntigravityThinkingLevel(effort) ?? retiredTier : retiredTier,
362-
};
376+
const level = effort ? resolveAntigravityThinkingLevel(effort) ?? retiredTier : retiredTier;
377+
return { wireModelId: ANTIGRAVITY_FLASH_WIRE_TIERS[level]!, thinkingLevel: level };
363378
}
364379

365-
// Rule 1: suffix/compat alias — suffix IS the effort.
380+
// Rule 1: suffix/compat alias — suffix IS the effort. 3.7 Flash wire tiers land here
381+
// (identity aliases) and must NOT carry thinkingConfig: the suffix already IS the tier,
382+
// and sending both on the same suffixed id is a contradictory request.
366383
if (isAntigravitySuffixModelId(modelId)) {
367384
return { wireModelId: resolveAntigravityWireModelId(modelId) };
368385
}
369386

370-
// Rule 1b: single-wire-id Gemini model whose tiers ride on thinkingLevel. Without
371-
// this the model falls to rule 5 and silently loses reasoning control entirely.
372-
const defaultLevel = ANTIGRAVITY_THINKING_LEVEL_MODELS[modelId];
373-
if (defaultLevel) {
374-
return {
375-
wireModelId: modelId,
376-
thinkingLevel: effort ? resolveAntigravityThinkingLevel(effort) ?? defaultLevel : defaultLevel,
377-
};
378-
}
379-
380-
// Rule 2/3: mapped Gemini base model.
387+
// Rule 2/3: mapped Gemini base model. Non-enum efforts clamp through the same
388+
// thinking-level sanitizer first ("max" → high), so an out-of-ladder value can
389+
// never silently degrade to the default tier.
381390
const effortMap = ANTIGRAVITY_EFFORT_WIRE_MAP[modelId];
382391
if (effortMap) {
383-
if (effort && effort in effortMap) {
384-
return { wireModelId: effortMap[effort]!, thinkingLevel: effort };
392+
if (effort) {
393+
const level = resolveAntigravityThinkingLevel(effort);
394+
if (level && level in effortMap) {
395+
return { wireModelId: effortMap[level]!, thinkingLevel: level };
396+
}
385397
}
386398
const defaultEffort = ANTIGRAVITY_DEFAULT_EFFORT[modelId]!;
387399
return { wireModelId: effortMap[defaultEffort]! };

‎tests/gemini-37-flash-migration.test.ts‎

Lines changed: 37 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -64,14 +64,14 @@ describe("retired Flash ids keep routing AND keep their tier", () => {
6464
"%s routes to 3.7 carrying thinkingLevel %s",
6565
(retired, expectedLevel) => {
6666
const resolved = resolveAntigravityEffortWireModel(retired);
67-
expect(resolved.wireModelId).toBe("gemini-3.7-flash");
67+
expect(resolved.wireModelId).toBe(`gemini-3.7-flash-${expectedLevel}`);
6868
expect(resolved.thinkingLevel).toBe(expectedLevel);
6969
},
7070
);
7171

7272
test("an explicit effort still wins over the id's historical tier", () => {
7373
const resolved = resolveAntigravityEffortWireModel("gemini-3.6-flash-low", "high");
74-
expect(resolved.wireModelId).toBe("gemini-3.7-flash");
74+
expect(resolved.wireModelId).toBe("gemini-3.7-flash-high");
7575
expect(resolved.thinkingLevel).toBe("high");
7676
});
7777

@@ -84,27 +84,52 @@ describe("retired Flash ids keep routing AND keep their tier", () => {
8484
});
8585

8686
describe("3.7 reasoning control", () => {
87-
test("an unset effort still sends the documented medium default", () => {
87+
test("an unset effort still routes to the documented medium tier", () => {
8888
const resolved = resolveAntigravityEffortWireModel("gemini-3.7-flash");
89-
expect(resolved.wireModelId).toBe("gemini-3.7-flash");
90-
// Without an explicit branch this model falls through to the resolver's final rule
91-
// and returns no thinkingConfig at all, silently ignoring reasoning effort.
92-
expect(resolved.thinkingLevel).toBe("medium");
89+
expect(resolved.wireModelId).toBe("gemini-3.7-flash-medium");
90+
// The suffix IS the tier: no thinkingConfig rides alongside it.
91+
expect(resolved.thinkingLevel).toBeUndefined();
9392
});
9493

95-
test.each(["low", "medium", "high"])("%s is passed through", level => {
96-
expect(resolveAntigravityEffortWireModel("gemini-3.7-flash", level).thinkingLevel).toBe(level);
94+
test.each([
95+
["low", "gemini-3.7-flash-low"],
96+
["medium", "gemini-3.7-flash-medium"],
97+
["high", "gemini-3.7-flash-high"],
98+
])("%s routes to %s", (level, wireId) => {
99+
const resolved = resolveAntigravityEffortWireModel("gemini-3.7-flash", level);
100+
expect(resolved.wireModelId).toBe(wireId);
101+
expect(resolved.thinkingLevel).toBe(level);
97102
});
98103

99104
test("minimal never reaches CCA", () => {
100105
// Google documents minimal as unsupported for this generation: it errors rather
101106
// than degrading, so it must fall back to the default instead of being forwarded.
102-
expect(resolveAntigravityEffortWireModel("gemini-3.7-flash", "minimal").thinkingLevel).toBe("medium");
107+
const resolved = resolveAntigravityEffortWireModel("gemini-3.7-flash", "minimal");
108+
expect(resolved.wireModelId).toBe("gemini-3.7-flash-medium");
109+
expect(resolved.thinkingLevel).toBeUndefined();
103110
});
104111

105112
test("efforts above the enum clamp to high", () => {
106113
for (const effort of ["xhigh", "max", "ultra"]) {
107-
expect(resolveAntigravityEffortWireModel("gemini-3.7-flash", effort).thinkingLevel).toBe("high");
114+
const resolved = resolveAntigravityEffortWireModel("gemini-3.7-flash", effort);
115+
expect(resolved.wireModelId).toBe("gemini-3.7-flash-high");
116+
expect(resolved.thinkingLevel).toBe("high");
117+
}
118+
});
119+
120+
test("the bare picker id must never reach the wire — upstream 404s it", () => {
121+
// Proven against the live CCA backend: the envelope 404s on the bare id and only
122+
// accepts the suffixed tiers. Every resolution path must land on a suffix.
123+
for (const [id, effort] of [
124+
["gemini-3.7-flash", undefined],
125+
["gemini-3.7-flash", "low"],
126+
["gemini-3.7-flash", "high"],
127+
["gemini-3.6-flash", "medium"],
128+
["gemini-3.5-flash-high", undefined],
129+
]) {
130+
const resolved = resolveAntigravityEffortWireModel(id, effort);
131+
expect(resolved.wireModelId).not.toBe("gemini-3.7-flash");
132+
expect(resolved.wireModelId).toMatch(/^gemini-3\.7-flash-(low|medium|high)$/);
108133
}
109134
});
110135
});
@@ -218,7 +243,7 @@ describe("a saved config survives the retirement", () => {
218243
const prov = config.providers["google-antigravity"]!;
219244
const mapped = mapReasoningEffort(prov, "gemini-3.6-flash", "high");
220245
expect(resolveAntigravityEffortWireModel("gemini-3.6-flash", mapped)).toEqual({
221-
wireModelId: "gemini-3.7-flash",
246+
wireModelId: "gemini-3.7-flash-high",
222247
thinkingLevel: "high",
223248
});
224249
});

‎tests/google-antigravity-wire.test.ts‎

Lines changed: 27 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -103,12 +103,13 @@ describe("antigravity CCA envelope", () => {
103103

104104
for (const [alias, wire] of [
105105
// Google retires the previous Flash generation from CCA when the next ships, so
106-
// every retired id — 3.6 tiers included — now lands on 3.7.
107-
["gemini-3.5-flash-extra-low", "gemini-3.7-flash"],
108-
["gemini-3.5-flash-low", "gemini-3.7-flash"],
109-
["gemini-3.5-flash-mid", "gemini-3.7-flash"],
110-
["gemini-3.5-flash-high", "gemini-3.7-flash"],
111-
["gemini-3-flash-agent", "gemini-3.7-flash"],
106+
// every retired id — 3.6 tiers included — now lands on the 3.7 wire tier that
107+
// carries the same reasoning level.
108+
["gemini-3.5-flash-extra-low", "gemini-3.7-flash-low"],
109+
["gemini-3.5-flash-low", "gemini-3.7-flash-medium"],
110+
["gemini-3.5-flash-mid", "gemini-3.7-flash-medium"],
111+
["gemini-3.5-flash-high", "gemini-3.7-flash-high"],
112+
["gemini-3-flash-agent", "gemini-3.7-flash-high"],
112113
["gemini-3.1-pro-high", "gemini-pro-agent"],
113114
["gemini-3.1-pro-preview", "gemini-pro-agent"],
114115
]) {
@@ -118,8 +119,12 @@ describe("antigravity CCA envelope", () => {
118119

119120
for (const modelId of ["gemini-3.6-flash-low", "gemini-3.6-flash-medium", "gemini-3.6-flash-high"]) {
120121
const req = await createGoogleAdapter(provider).buildRequest(parsed("x", false, modelId));
121-
// The retired tier ids no longer exist upstream; they route to the live model.
122-
expect(JSON.parse(req.body).model).toBe("gemini-3.7-flash");
122+
// The retired tier ids no longer exist upstream; they route to the live
123+
// suffixed 3.7 wire tier that carries the same reasoning level.
124+
const tier = /-(low|medium|high)$/.exec(modelId)![1]!;
125+
const env = JSON.parse(req.body);
126+
expect(env.model).toBe(`gemini-3.7-flash-${tier}`);
127+
expect(env.request.generationConfig?.thinkingConfig?.thinkingLevel).toBe(tier);
123128
}
124129
});
125130

@@ -391,33 +396,33 @@ describe("antigravity CCA envelope", () => {
391396

392397
// ── Effort routing: base model + effort → wire model ID + thinkingConfig ──
393398

394-
// 3.7 Flash carries its tiers on thinkingLevel against ONE wire id, unlike the 3.6
395-
// generation which used suffixed wire ids.
396-
test("gemini-3.7-flash with effort=high keeps the wire id + thinkingConfig", async () => {
399+
// 3.7 Flash is gated on SUFFIXED wire ids: the bare id 404s upstream, so effort
400+
// routes to the matching tier id (and the tier still rides the request as well).
401+
test("gemini-3.7-flash with effort=high routes to the -high wire tier", async () => {
397402
const req = await createGoogleAdapter(effortProvider).buildRequest(parsedWithEffort("gemini-3.7-flash", "high"));
398403
const env = JSON.parse(req.body);
399-
expect(env.model).toBe("gemini-3.7-flash");
404+
expect(env.model).toBe("gemini-3.7-flash-high");
400405
expect(env.request.generationConfig?.thinkingConfig?.thinkingLevel).toBe("high");
401406
});
402407

403-
test("gemini-3.7-flash with effort=low keeps the wire id + thinkingConfig", async () => {
408+
test("gemini-3.7-flash with effort=low routes to the -low wire tier", async () => {
404409
const req = await createGoogleAdapter(effortProvider).buildRequest(parsedWithEffort("gemini-3.7-flash", "low"));
405410
const env = JSON.parse(req.body);
406-
expect(env.model).toBe("gemini-3.7-flash");
411+
expect(env.model).toBe("gemini-3.7-flash-low");
407412
expect(env.request.generationConfig?.thinkingConfig?.thinkingLevel).toBe("low");
408413
});
409414

410-
test("gemini-3.7-flash with no effort still sends the documented medium default", async () => {
415+
test("gemini-3.7-flash with no effort still routes to the documented medium tier", async () => {
411416
const req = await createGoogleAdapter(effortProvider).buildRequest(parsedWithEffort("gemini-3.7-flash"));
412417
const env = JSON.parse(req.body);
413-
expect(env.model).toBe("gemini-3.7-flash");
414-
expect(env.request.generationConfig?.thinkingConfig?.thinkingLevel).toBe("medium");
418+
expect(env.model).toBe("gemini-3.7-flash-medium");
419+
expect(env.request.generationConfig?.thinkingConfig).toBeUndefined();
415420
});
416421

417-
test("gemini-3.7-flash with effort=max clamps to high", async () => {
422+
test("gemini-3.7-flash with effort=max clamps to the -high tier", async () => {
418423
const req = await createGoogleAdapter(effortProvider).buildRequest(parsedWithEffort("gemini-3.7-flash", "max"));
419424
const env = JSON.parse(req.body);
420-
expect(env.model).toBe("gemini-3.7-flash");
425+
expect(env.model).toBe("gemini-3.7-flash-high");
421426
expect(env.request.generationConfig?.thinkingConfig?.thinkingLevel).toBe("high");
422427
});
423428

@@ -455,7 +460,7 @@ describe("antigravity CCA envelope", () => {
455460
// A retired id must not keep its dead wire id, and an explicit effort still wins.
456461
const req = await createGoogleAdapter(effortProvider).buildRequest(parsedWithEffort("gemini-3.6-flash-low", "high"));
457462
const env = JSON.parse(req.body);
458-
expect(env.model).toBe("gemini-3.7-flash");
463+
expect(env.model).toBe("gemini-3.7-flash-high");
459464
expect(env.request.generationConfig?.thinkingConfig?.thinkingLevel).toBe("high");
460465
});
461466

@@ -464,14 +469,14 @@ describe("antigravity CCA envelope", () => {
464469
// survive as an explicit thinkingLevel or the user silently loses their choice.
465470
const req = await createGoogleAdapter(effortProvider).buildRequest(parsedWithEffort("gemini-3.6-flash-low"));
466471
const env = JSON.parse(req.body);
467-
expect(env.model).toBe("gemini-3.7-flash");
472+
expect(env.model).toBe("gemini-3.7-flash-low");
468473
expect(env.request.generationConfig?.thinkingConfig?.thinkingLevel).toBe("low");
469474
});
470475

471476
test("legacy 3.5 compat alias now resolves to 3.7 with an explicit effort", async () => {
472477
const req = await createGoogleAdapter(effortProvider).buildRequest(parsedWithEffort("gemini-3.5-flash-high", "low"));
473478
const env = JSON.parse(req.body);
474-
expect(env.model).toBe("gemini-3.7-flash");
479+
expect(env.model).toBe("gemini-3.7-flash-low");
475480
expect(env.request.generationConfig?.thinkingConfig?.thinkingLevel).toBe("low");
476481
});
477482

‎tests/google-hardening.test.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -416,8 +416,8 @@ describe("google provider hardening", () => {
416416
expect(JSON.parse(legacy.body).generationConfig.thinkingConfig).toEqual({ thinkingLevel: "medium" });
417417
// Antigravity used to encode the tier in the wire id, so it sent no thinkingConfig.
418418
// Now that Google has retired the suffixed 3.6 ids, that tier has nowhere to live
419-
// except an explicit thinkingLevel on the current model.
420-
expect(JSON.parse(antigravity.body).model).toBe("gemini-3.7-flash");
419+
// except the equivalent suffixed 3.7 wire tier (the bare id 404s upstream).
420+
expect(JSON.parse(antigravity.body).model).toBe("gemini-3.7-flash-high");
421421
expect(JSON.parse(antigravity.body).request.generationConfig.thinkingConfig)
422422
.toEqual({ thinkingLevel: "high" });
423423
});

0 commit comments

Comments
 (0)