fix(core): cap Alibaba thinking budget variants at 64k (#51154)

This commit is contained in:
Aiden Cline
2026-09-24 13:14:49 -05:00
committed by GitHub
parent 03af821aa5
commit 499c2feaa3
2 changed files with 41 additions and 9 deletions
+20 -7
View File
@@ -28,6 +28,8 @@ const EFFORTS = ["low", "medium", "high"]
const ENCRYPTED_REASONING = ["reasoning.encrypted_content"]
const ADAPTIVE_THINKING = { type: "adaptive", display: "summarized" }
const ANTHROPIC_OUTPUT_TOKEN_MAX = 32_000
// Alibaba thinking budget variants stay under 64k instead of reaching the model's whole output limit.
const ALIBABA_THINKING_BUDGET_MAX = 64_000
const variant = (id: string, overlay: Overlay): Variants[number] => ({ id: Model.VariantID.make(id), ...overlay })
@@ -224,9 +226,12 @@ const alibabaChat: Protocol = (model, support) => {
case "toggle":
return toggle({ settings: { enableThinking: false } }, { settings: { enableThinking: true } })
case "budget_tokens":
return budgets(model, support, (tokens) => ({
settings: { enableThinking: true, thinkingBudget: tokens },
}))
return budgets(
model,
support,
(tokens) => ({ settings: { enableThinking: true, thinkingBudget: tokens } }),
ALIBABA_THINKING_BUDGET_MAX,
)
}
}
@@ -310,9 +315,12 @@ const alibabaMessages: Protocol = (model, support) => {
case "toggle":
return toggle({ settings: { thinking: { type: "disabled" } } }, { settings: { thinking: { type: "enabled" } } })
case "budget_tokens":
return budgets(model, support, (tokens) => ({
settings: { thinking: { type: "enabled", budgetTokens: tokens } },
}))
return budgets(
model,
support,
(tokens) => ({ settings: { thinking: { type: "enabled", budgetTokens: tokens } } }),
ALIBABA_THINKING_BUDGET_MAX,
)
}
}
@@ -405,7 +413,12 @@ const alibabaAISDK: Protocol = (model, support) => {
case "toggle":
return toggle({ settings: { enableThinking: false } }, { settings: { enableThinking: true } })
case "budget_tokens":
return budgets(model, support, (tokens) => ({ settings: { enableThinking: true, thinkingBudget: tokens } }))
return budgets(
model,
support,
(tokens) => ({ settings: { enableThinking: true, thinkingBudget: tokens } }),
ALIBABA_THINKING_BUDGET_MAX,
)
}
}
+21 -2
View File
@@ -175,8 +175,8 @@ test("spells Chat Completions variants for direct providers", () => {
]),
).toEqual([
{ id: "none", settings: { enableThinking: false } },
{ id: "high", settings: { enableThinking: true, thinkingBudget: 131_072 } },
{ id: "max", settings: { enableThinking: true, thinkingBudget: 262_144 } },
{ id: "high", settings: { enableThinking: true, thinkingBudget: 32_000 } },
{ id: "max", settings: { enableThinking: true, thinkingBudget: 63_999 } },
])
expect(
@@ -214,6 +214,25 @@ test("spells Bedrock Converse effort for Grok and Nova", () => {
])
})
test("caps Alibaba thinking budget variants at 64k", () => {
const supports: Variant.Support[] = [{ type: "toggle" }, { type: "budget_tokens" }]
expect(resolve(model("@opencode/ai/providers/alibaba/chat", "kimi-k2.6", 262_144), supports)).toEqual([
{ id: "none", settings: { enableThinking: false } },
{ id: "high", settings: { enableThinking: true, thinkingBudget: 32_000 } },
{ id: "max", settings: { enableThinking: true, thinkingBudget: 63_999 } },
])
expect(resolve(model("@opencode/ai/providers/alibaba/messages", "kimi-k2.6", 262_144), supports)).toEqual([
{ id: "none", settings: { thinking: { type: "disabled" } } },
{ id: "high", settings: { thinking: { type: "enabled", budgetTokens: 32_000 } } },
{ id: "max", settings: { thinking: { type: "enabled", budgetTokens: 63_999 } } },
])
expect(resolve(model("@opencode/ai/providers/alibaba/chat", "kimi-k2.5", 32_768), supports)).toEqual([
{ id: "none", settings: { enableThinking: false } },
{ id: "high", settings: { enableThinking: true, thinkingBudget: 16_384 } },
{ id: "max", settings: { enableThinking: true, thinkingBudget: 32_767 } },
])
})
test("spells Chat Completions variants for hosting providers", () => {
expect(
resolve(model("@opencode/ai/providers/openai-compatible", "deepseek-ai/deepseek-v4-pro", undefined, "nvidia"), [