From 3e9cbc91788c0206a3125db6746fcf9f3b7781af Mon Sep 17 00:00:00 2001 From: Aiden Cline Date: Wed, 1 Jul 2026 11:18:35 -0500 Subject: [PATCH] fix(provider): keep budget variants distinct --- packages/opencode/src/provider/transform.ts | 3 ++- .../opencode/test/provider/transform.test.ts | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/packages/opencode/src/provider/transform.ts b/packages/opencode/src/provider/transform.ts index ff58b48d37..f0a0e077b3 100644 --- a/packages/opencode/src/provider/transform.ts +++ b/packages/opencode/src/provider/transform.ts @@ -615,8 +615,9 @@ function reasoningBudgetVariants( ) { const max = Math.max(1, Math.min(budget.max ?? 31_999, maxOutputTokens(model) - 1)) const min = Math.min(budget.min ?? 1, max) + const high = Math.max(min, max > 16_000 ? 16_000 : Math.ceil(max / 2)) return { - high: make(Math.max(min, Math.min(16_000, max))), + high: make(high), max: make(max), } } diff --git a/packages/opencode/test/provider/transform.test.ts b/packages/opencode/test/provider/transform.test.ts index 49b1e78583..9b21429a46 100644 --- a/packages/opencode/test/provider/transform.test.ts +++ b/packages/opencode/test/provider/transform.test.ts @@ -3072,6 +3072,25 @@ describe("ProviderTransform.variants", () => { expect(result.max).toEqual({ thinkingConfig: { includeThoughts: true, thinkingBudget: 31999 } }) }) + test("reasoning_options budget tokens keep high and max distinct below the default cap", () => { + const result = ProviderTransform.variants( + createMockModel({ + id: "google/gemini-small-budget", + providerID: "google", + api: { + id: "gemini-small-budget", + url: "https://generativelanguage.googleapis.com", + npm: "@ai-sdk/google", + }, + reasoning_options: [{ type: "budget_tokens", min: 128, max: 8000 }], + }), + ) + expect(result).toEqual({ + high: { thinkingConfig: { includeThoughts: true, thinkingBudget: 4000 } }, + max: { thinkingConfig: { includeThoughts: true, thinkingBudget: 8000 } }, + }) + }) + test("reasoning_options ignore toggle-only models", () => { const result = ProviderTransform.variants( createMockModel({