Skip to content

Commit 380beb3

Browse files
anandgupta42claude
andcommitted
fix: use thinking levels for Gemini 4 small calls
`smallOptions` gave every Google reasoning model except Gemini 3 `thinkingBudget: 0`. Gemini 4 rejects budgets with a 400 ("Thinking budget is not supported for this model. Use thinking level instead."), so every small call (session title, prompt enhancement, project copy) failed on it. - Gemini 2.x and unversioned aliases keep `thinkingBudget: 0`; Gemini 3 keeps `thinkingLevel: "minimal"`; Gemini 4+ uses the lowest configured supported level, falling back to `low`. - Tests cover Google and Vertex for 2.0/2.5/3/3.1/4/5/30 and an unversioned alias, with and without generated variants. Closes #1533 Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 19f909c commit 380beb3

2 files changed

Lines changed: 55 additions & 3 deletions

File tree

‎packages/opencode/src/provider/transform.ts‎

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1347,18 +1347,26 @@ export namespace ProviderTransform {
13471347
) {
13481348
return mergeDeep({ store: false }, small)
13491349
}
1350-
// altimate_change start — upstream_fix: restore Google minimal thinking for small calls only on reasoning models
1350+
// altimate_change start — upstream_fix: use generation-supported Google thinking controls for small reasoning calls
13511351
if (
13521352
(model.providerID === "google" ||
13531353
model.api.npm === "@ai-sdk/google" ||
13541354
model.api.npm === "@ai-sdk/google-vertex") &&
13551355
model.capabilities.reasoning
13561356
) {
13571357
const id = model.api.id.toLowerCase()
1358-
if (id.includes("gemini-3")) {
1358+
const generation = Number(/(?:^|\/)gemini-(\d+)(?:[.-]|$)/.exec(id)?.[1])
1359+
if (generation === 3) {
13591360
return { thinkingConfig: { thinkingLevel: "minimal" } }
13601361
}
1361-
return { thinkingConfig: { thinkingBudget: 0 } }
1362+
// Gemini 2.x and unversioned aliases (e.g. gemini-flash-latest) keep the budget control.
1363+
if (!(generation >= 4)) {
1364+
return { thinkingConfig: { thinkingBudget: 0 } }
1365+
}
1366+
// Gemini 4+ rejects budgets and "minimal"; prefer the lowest configured supported level.
1367+
const levels = Object.values(model.variants ?? {}).map((variant) => variant.thinkingConfig?.thinkingLevel)
1368+
const thinkingLevel = WIDELY_SUPPORTED_EFFORTS.find((level) => levels.includes(level)) ?? "low"
1369+
return { thinkingConfig: { thinkingLevel } }
13621370
}
13631371
// altimate_change end
13641372
if (model.providerID === "openrouter" || model.providerID === "llmgateway") {

‎packages/opencode/test/provider/transform.test.ts‎

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,50 @@ describe("ProviderTransform.smallOptions - google thinking", () => {
307307
variants: overrides.variants ?? {},
308308
}) as any
309309

310+
// altimate_change start — small calls must use thinking controls supported by each Gemini generation
311+
for (const provider of [
312+
{ providerID: "google", npm: "@ai-sdk/google" },
313+
{ providerID: "google-vertex", npm: "@ai-sdk/google-vertex" },
314+
] as const) {
315+
for (const testCase of [
316+
{ id: "gemini-2.0-flash", thinkingConfig: { thinkingBudget: 0 } },
317+
{ id: "gemini-2.5-flash", thinkingConfig: { thinkingBudget: 0 } },
318+
{ id: "gemini-3-pro", thinkingConfig: { thinkingLevel: "minimal" } },
319+
{ id: "gemini-3.1-pro", thinkingConfig: { thinkingLevel: "minimal" } },
320+
{ id: "gemini-4-argon", thinkingConfig: { thinkingLevel: "low" } },
321+
{ id: "gemini-5-pro", thinkingConfig: { thinkingLevel: "low" } },
322+
{ id: "gemini-30-pro", thinkingConfig: { thinkingLevel: "low" } },
323+
{ id: "gemini-flash-latest", thinkingConfig: { thinkingBudget: 0 } },
324+
]) {
325+
for (const configured of [false, true]) {
326+
test(`${provider.providerID} ${testCase.id} uses supported small thinking controls with ${configured ? "generated" : "empty"} variants`, () => {
327+
const model = createGoogleModel(testCase.id, provider)
328+
if (configured) model.variants = ProviderTransform.variants(model)
329+
330+
const result = ProviderTransform.smallOptions(model)
331+
332+
expect(result).toEqual({ thinkingConfig: testCase.thinkingConfig })
333+
if (testCase.thinkingConfig.thinkingLevel) {
334+
expect(result.thinkingConfig).not.toHaveProperty("thinkingBudget")
335+
}
336+
})
337+
}
338+
}
339+
340+
test(`${provider.providerID} uses the lowest configured Gemini 4 thinking level regardless of variant names or order`, () => {
341+
const model = createGoogleModel("gemini-4-argon", {
342+
...provider,
343+
variants: {
344+
detailed: { thinkingConfig: { includeThoughts: true, thinkingLevel: "high" } },
345+
balanced: { thinkingConfig: { includeThoughts: true, thinkingLevel: "medium" } },
346+
},
347+
})
348+
349+
expect(ProviderTransform.smallOptions(model)).toEqual({ thinkingConfig: { thinkingLevel: "medium" } })
350+
})
351+
}
352+
// altimate_change end
353+
310354
test("disables Gemini 2.5 thinking budget for small calls even when high is the first variant", () => {
311355
const result = ProviderTransform.smallOptions(
312356
createGoogleModel("gemini-2.5-pro", {

0 commit comments

Comments
 (0)