Commit 7a8e667
authored
🤖 fix: enable xhigh reasoning for gpt-5.2 (#1117)
Enable `xhigh` thinking for `openai:gpt-5.2` by updating the per-model
thinking policy.
- Root cause: `gpt-5.2` was falling back to the default policy
(`off/low/medium/high`), so any `xhigh` selection got clamped before
building OpenAI provider options.
- Fix: allow `xhigh` in `getThinkingPolicyForModel()` for `gpt-5.2`
(including version-suffixed and mux-gateway forms) and add tests.
Validation:
- `bun test src/browser/utils/thinking/policy.test.ts`
- `make typecheck`
- `make static-check`
---
<details>
<summary>📋 Implementation Plan</summary>
# Enable xhigh reasoning for `openai:gpt-5.2`
## Context / Problem
The newly released `openai:gpt-5.2` model supports OpenAI’s
`reasoningEffort: "xhigh"`, but mux currently **cannot actually request
xhigh** for this model.
### Root cause (code-level)
Mux clamps the requested “thinking level” to a per-model capability
subset via:
- `src/browser/utils/thinking/policy.ts` → `getThinkingPolicyForModel()`
/ `enforceThinkingPolicy()`
- This policy is used both:
- in the **UI** (Thinking slider/options), and
- in the **backend request builder** (via `buildProviderOptions()` which
calls `enforceThinkingPolicy()`).
Right now `gpt-5.2` is not special-cased, so it falls into the **default
policy**:
- Default: `["off", "low", "medium", "high"]`
- Result: any attempt to set `xhigh` gets clamped (typically to
`"medium"`), so OpenAI never receives `reasoningEffort: "xhigh"`.
OpenAI request construction is already correct once `xhigh` is allowed:
- `src/common/utils/ai/providerOptions.ts` maps `ThinkingLevel` → OpenAI
`reasoningEffort`.
- `src/common/types/thinking.ts` includes `xhigh: "xhigh"` in
`OPENAI_REASONING_EFFORT`.
## Recommended approach (minimal change) — **Update thinking policy for
`gpt-5.2`**
**Net LoC estimate (product code only): ~+10–25 LoC** (policy +
comments; tests separate)
### What to change
1. **Allow `xhigh` for `gpt-5.2`** in `getThinkingPolicyForModel()`:
- File: `src/browser/utils/thinking/policy.ts`
- Add a special case similar to `gpt-5.2-pro` and `gpt-5.1-codex-max`.
Suggested policy:
- `openai:gpt-5.2` → `["off", "low", "medium", "high", "xhigh"]`
Notes:
- Keep the `gpt-5.2-pro` branch *above* the new `gpt-5.2` branch.
- Use the same “version suffix tolerant” regex style already used
elsewhere.
- Example: `^gpt-5\.2(?!-[a-z])` so it matches `gpt-5.2` and
`gpt-5.2-2025-12-11` but not `gpt-5.2-pro`.
2. **Update comments to match reality**
- File: `src/browser/utils/thinking/policy.ts`
- Update the “default policy” comment that currently implies `xhigh` is
only for codex-max.
- File: `src/common/types/thinking.ts`
- Update the comment on `OPENAI_REASONING_EFFORT.xhigh` (currently says
only `gpt-5.1-codex-max`).
- Optional (nice-to-have): `src/common/utils/tokens/models-extra.ts`
- The `gpt-5.2` comment block doesn’t mention xhigh. Add a short note
for consistency.
### Why this works
Once the policy allows `xhigh`, the normal request path already does the
right thing:
- UI can select/store `xhigh`.
- Backend uses `buildProviderOptions(modelString, thinkingLevel, ...)`.
- `buildProviderOptions()` will:
- preserve `xhigh` (no clamping),
- set `openai.reasoningEffort = "xhigh"`, and
- include `reasoning.encrypted_content` so tool-use works correctly for
reasoning models.
## Tests / Validation
1. Update/add unit tests for the policy:
- File: `src/browser/utils/thinking/policy.test.ts`
- Add cases:
- `getThinkingPolicyForModel("openai:gpt-5.2")` returns 5 levels
including `xhigh`.
- `getThinkingPolicyForModel("mux-gateway:openai/gpt-5.2")` returns
same.
- `getThinkingPolicyForModel("openai:gpt-5.2-2025-12-11")` returns same.
- `enforceThinkingPolicy("openai:gpt-5.2", "xhigh") === "xhigh"`.
2. Run targeted tests:
- `bun test src/browser/utils/thinking/policy.test.ts`
3. Run repo-wide correctness gates (expected in CI):
- `make typecheck`
- `make lint` (or `make lint-fix` if needed)
## Rollout notes / UX impact
- The Thinking slider will show an extra step for `gpt-5.2` once
selected.
- Command palette already offers `xhigh`; after this change, choosing
`xhigh` on `gpt-5.2` will no longer silently clamp back to `medium`.
- No changes required in provider config (`knownModels.ts` etc.).
## Alternative approach (more scalable, higher scope)
**Drive thinking policy from model metadata** (e.g., a single
authoritative model capabilities table that includes supported thinking
levels).
**Net LoC estimate (product code only): ~+80–200 LoC**
This would reduce future “forgot to special-case model X” issues, but
requires designing a shared model-capabilities schema and updating
multiple call sites (policy derivation, UI, provider options clamping).
## Execution checklist (when switching to Exec mode)
- [ ] Edit `src/browser/utils/thinking/policy.ts` to add `gpt-5.2` xhigh
support.
- [ ] Update relevant comments (policy + thinking mapping).
- [ ] Update `src/browser/utils/thinking/policy.test.ts` with new
assertions.
- [ ] Run `bun test ...policy.test.ts`.
- [ ] Run `make typecheck`.
</details>
---
_Generated with `mux`_
Signed-off-by: Thomas Kosiewski <tk@coder.com>1 parent 3594896 commit 7a8e667
File tree
4 files changed
+54
-3
lines changed- src
- browser/utils/thinking
- common
- types
- utils/tokens
4 files changed
+54
-3
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
64 | 64 | | |
65 | 65 | | |
66 | 66 | | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
67 | 97 | | |
68 | 98 | | |
69 | 99 | | |
| |||
205 | 235 | | |
206 | 236 | | |
207 | 237 | | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
208 | 252 | | |
209 | 253 | | |
210 | 254 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
25 | 25 | | |
26 | 26 | | |
27 | 27 | | |
| 28 | + | |
28 | 29 | | |
29 | 30 | | |
30 | 31 | | |
31 | | - | |
| 32 | + | |
32 | 33 | | |
33 | 34 | | |
34 | 35 | | |
| |||
55 | 56 | | |
56 | 57 | | |
57 | 58 | | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
58 | 64 | | |
59 | 65 | | |
60 | 66 | | |
| |||
65 | 71 | | |
66 | 72 | | |
67 | 73 | | |
68 | | - | |
| 74 | + | |
69 | 75 | | |
70 | 76 | | |
71 | 77 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
68 | 68 | | |
69 | 69 | | |
70 | 70 | | |
71 | | - | |
| 71 | + | |
72 | 72 | | |
73 | 73 | | |
74 | 74 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
43 | 43 | | |
44 | 44 | | |
45 | 45 | | |
| 46 | + | |
46 | 47 | | |
47 | 48 | | |
48 | 49 | | |
| |||
0 commit comments