Skip to content

Commit 5299fea

Browse files
committed
fix(ThinkingBudget): handling xhigh, max and disabled values
1 parent 67df9f9 commit 5299fea

2 files changed

Lines changed: 73 additions & 29 deletions

File tree

‎webview-ui/src/components/settings/ThinkingBudget.tsx‎

Lines changed: 19 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
Semantics for Reasoning Effort (ThinkingBudget)
33
44
Capability surface:
5-
- modelInfo.supportsReasoningEffort: boolean | Array<"disable" | "none" | "minimal" | "low" | "medium" | "high">
5+
- modelInfo.supportsReasoningEffort: boolean | Array<"disable" | "none" | "minimal" | "low" | "medium" | "high" | "xhigh" | "max">
66
- true → UI shows ["low","medium","high"]
7-
- array → UI shows exactly the provided values
7+
- array → UI shows exactly the provided values (e.g. GPT-5.5 includes "xhigh")
88
99
Selection behavior:
1010
- "disable":
@@ -17,7 +17,7 @@ Selection behavior:
1717
- set enableReasoningEffort = true
1818
- persist reasoningEffort = "none"
1919
- request builders include reasoning with value "none"
20-
- "minimal" | "low" | "medium" | "high":
20+
- "minimal" | "low" | "medium" | "high" | "xhigh" | "max":
2121
- set enableReasoningEffort = true
2222
- persist the selected value
2323
- request builders include reasoning with the selected effort
@@ -35,12 +35,7 @@ Notes:
3535
import { useEffect } from "react"
3636
import { Checkbox } from "vscrui"
3737

38-
import {
39-
type ProviderSettings,
40-
type ModelInfo,
41-
type ReasoningEffortWithMinimal,
42-
reasoningEfforts,
43-
} from "@roo-code/types"
38+
import { type ProviderSettings, type ModelInfo, type ReasoningEffortExtended, reasoningEfforts } from "@roo-code/types"
4439

4540
import {
4641
DEFAULT_HYBRID_REASONING_MODEL_MAX_TOKENS,
@@ -81,31 +76,32 @@ export const ThinkingBudget = ({ apiConfiguration, setApiConfigurationField, mod
8176
// max-tokens control, so only surface this standalone slider when that branch is inactive.
8277
const isMaxTokensConfigurable = !!modelInfo && modelInfo.supportsMaxTokens && !isReasoningBudgetSupported
8378

84-
// Build available reasoning efforts list from capability
79+
// "disable" turns off reasoning entirely; "none" is a valid reasoning level.
80+
// Both display as "None" in the UI but behave differently.
81+
// Arrays from supportsReasoningEffort may include "disable" (e.g. Z.ai GLM), so type the
82+
// full option set as ReasoningEffortExtended | "disable" from the start to avoid casts.
83+
type ReasoningEffortOption = ReasoningEffortExtended | "disable"
8584
const supports = modelInfo?.supportsReasoningEffort
86-
const baseAvailableOptions: ReadonlyArray<ReasoningEffortWithMinimal> =
85+
const baseAvailableOptions: ReadonlyArray<ReasoningEffortOption> =
8786
supports === true
88-
? (reasoningEfforts as readonly ReasoningEffortWithMinimal[])
87+
? (reasoningEfforts as readonly ReasoningEffortOption[])
8988
: Array.isArray(supports)
90-
? (supports as ReadonlyArray<ReasoningEffortWithMinimal>)
91-
: (reasoningEfforts as readonly ReasoningEffortWithMinimal[])
89+
? (supports as ReadonlyArray<ReasoningEffortOption>)
90+
: (reasoningEfforts as readonly ReasoningEffortOption[])
9291

93-
// "disable" turns off reasoning entirely; "none" is a valid reasoning level.
94-
// Both display as "None" in the UI but behave differently.
9592
// Add "disable" option only when:
9693
// 1. requiredReasoningEffort is not true, AND
9794
// 2. supportsReasoningEffort is boolean true (not an explicit array)
9895
// When the model provides an explicit array, respect those exact values.
99-
type ReasoningEffortOption = ReasoningEffortWithMinimal | "none" | "disable"
10096
const shouldAutoAddDisable =
101-
!modelInfo?.requiredReasoningEffort && supports === true && !baseAvailableOptions.includes("disable" as any)
97+
!modelInfo?.requiredReasoningEffort && supports === true && !baseAvailableOptions.includes("disable")
10298
const availableOptions: ReadonlyArray<ReasoningEffortOption> = shouldAutoAddDisable
103-
? (["disable", ...baseAvailableOptions] as ReasoningEffortOption[])
104-
: (baseAvailableOptions as ReadonlyArray<ReasoningEffortOption>)
99+
? ["disable", ...baseAvailableOptions]
100+
: baseAvailableOptions
105101

106102
// Default reasoning effort - use model's default if available
107103
// GPT-5 models have "medium" as their default in the model configuration
108-
const modelDefaultReasoningEffort = modelInfo?.reasoningEffort as ReasoningEffortWithMinimal | undefined
104+
const modelDefaultReasoningEffort = modelInfo?.reasoningEffort as ReasoningEffortExtended | undefined
109105
const defaultReasoningEffort: ReasoningEffortOption = modelInfo?.requiredReasoningEffort
110106
? modelDefaultReasoningEffort || "medium"
111107
: "disable"
@@ -118,7 +114,7 @@ export const ThinkingBudget = ({ apiConfiguration, setApiConfigurationField, mod
118114
if (isReasoningEffortSupported && !apiConfiguration.reasoningEffort) {
119115
// Only set a default if reasoning is required, otherwise leave as undefined (which maps to "disable")
120116
if (modelInfo?.requiredReasoningEffort && defaultReasoningEffort !== "disable") {
121-
setApiConfigurationField("reasoningEffort", defaultReasoningEffort as ReasoningEffortWithMinimal, false)
117+
setApiConfigurationField("reasoningEffort", defaultReasoningEffort as ReasoningEffortExtended, false)
122118
}
123119
}
124120
}, [
@@ -282,7 +278,7 @@ export const ThinkingBudget = ({ apiConfiguration, setApiConfigurationField, mod
282278
} else {
283279
// "none", "minimal", "low", "medium", "high" all enable reasoning
284280
setApiConfigurationField("enableReasoningEffort", true)
285-
setApiConfigurationField("reasoningEffort", value as ReasoningEffortWithMinimal)
281+
setApiConfigurationField("reasoningEffort", value as ReasoningEffortExtended)
286282
}
287283
}}>
288284
<SelectTrigger className="w-full">

‎webview-ui/src/components/settings/__tests__/ThinkingBudget.spec.tsx‎

Lines changed: 54 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
// npx vitest src/components/settings/__tests__/ThinkingBudget.spec.tsx
22

3+
import React from "react"
4+
35
import { render, screen, fireEvent } from "@/utils/test-utils"
46

57
import type { ModelInfo } from "@roo-code/types"
@@ -18,16 +20,20 @@ vi.mock("@/components/ui", () => ({
1820
onChange={(e) => onValueChange([parseInt(e.target.value)])}
1921
/>
2022
),
21-
Select: ({ children, value, onValueChange: _onValueChange }: any) => (
22-
<div data-testid="select" data-value={value}>
23-
{children}
23+
Select: ({ children, value, onValueChange }: any) => (
24+
<div data-testid="select" data-value={value} data-onvaluechange={onValueChange}>
25+
{React.Children.map(children, (child) => React.cloneElement(child, { onValueChange }))}
2426
</div>
2527
),
2628
SelectTrigger: ({ children }: any) => <button data-testid="select-trigger">{children}</button>,
2729
SelectValue: ({ placeholder }: any) => <span data-testid="select-value">{placeholder}</span>,
28-
SelectContent: ({ children }: any) => <div data-testid="select-content">{children}</div>,
29-
SelectItem: ({ children, value }: any) => (
30-
<div data-testid={`select-item-${value}`} data-value={value}>
30+
SelectContent: ({ children, onValueChange }: any) => (
31+
<div data-testid="select-content">
32+
{React.Children.map(children, (child) => React.cloneElement(child, { onValueChange }))}
33+
</div>
34+
),
35+
SelectItem: ({ children, value, onValueChange }: any) => (
36+
<div data-testid={`select-item-${value}`} data-value={value} onClick={() => onValueChange?.(value)}>
3137
{children}
3238
</div>
3339
),
@@ -304,6 +310,48 @@ describe("ThinkingBudget", () => {
304310
expect(screen.getByTestId("select-item-medium")).toBeInTheDocument()
305311
expect(screen.getByTestId("select-item-high")).toBeInTheDocument()
306312
})
313+
314+
it("should show 'xhigh' option when supportsReasoningEffort array includes xhigh (e.g. gpt-5.5)", () => {
315+
render(
316+
<ThinkingBudget
317+
{...defaultProps}
318+
modelInfo={{
319+
...reasoningEffortModelInfo,
320+
supportsReasoningEffort: ["none", "low", "medium", "high", "xhigh"],
321+
}}
322+
/>,
323+
)
324+
325+
expect(screen.getByTestId("reasoning-effort")).toBeInTheDocument()
326+
// Exactly the declared options — no unsupported tiers or auto-added "disable"
327+
expect(screen.getByTestId("select-item-none")).toBeInTheDocument()
328+
expect(screen.getByTestId("select-item-low")).toBeInTheDocument()
329+
expect(screen.getByTestId("select-item-medium")).toBeInTheDocument()
330+
expect(screen.getByTestId("select-item-high")).toBeInTheDocument()
331+
expect(screen.getByTestId("select-item-xhigh")).toBeInTheDocument()
332+
expect(screen.queryByTestId("select-item-disable")).not.toBeInTheDocument()
333+
expect(screen.queryByTestId("select-item-max")).not.toBeInTheDocument()
334+
})
335+
336+
it("should enable reasoning and persist 'xhigh' when xhigh is selected", () => {
337+
const setApiConfigurationField = vi.fn()
338+
339+
render(
340+
<ThinkingBudget
341+
{...defaultProps}
342+
setApiConfigurationField={setApiConfigurationField}
343+
modelInfo={{
344+
...reasoningEffortModelInfo,
345+
supportsReasoningEffort: ["none", "low", "medium", "high", "xhigh"],
346+
}}
347+
/>,
348+
)
349+
350+
fireEvent.click(screen.getByTestId("select-item-xhigh"))
351+
352+
expect(setApiConfigurationField).toHaveBeenCalledWith("enableReasoningEffort", true)
353+
expect(setApiConfigurationField).toHaveBeenCalledWith("reasoningEffort", "xhigh")
354+
})
307355
})
308356

309357
describe("configurable max output tokens (supportsMaxTokens)", () => {

0 commit comments

Comments
 (0)