fix(anthropic): send adaptive thinking only to models that support it#699
Merged
Merged
Conversation
While evaluating the Claude subscription (OAuth) flow, every Anthropic
request 400'd with "adaptive thinking is not supported on this model"
for any model except sonnet-4-6 / opus-4-6 / opus-4-7. _call_model_sync
sent thinking={type:adaptive} + output_config={effort} to ALL Claude
4.x models, gated only by the broad _model_supports_extended_thinking
regex. Pre-existing + general (hits the API-key path identically); the
default model sonnet-4-6 supports adaptive, which masked it. It made
the subscription flow dead-on-arrival for a Max user picking haiku or
sonnet-4-5.
Port the authoritative selection from the in-repo upstream source
(typescript/src/services/api/claude.ts:1612-1640, utils/thinking.ts,
utils/effort.ts):
- _model_supports_adaptive_thinking: opus-4-6/4-7, sonnet-4-6 only
- _model_supports_effort: opus-4-6, sonnet-4-6 only
Thinking-capable-but-not-adaptive models now get
{type:enabled, budget_tokens: max_tokens-1} (clamped >=1024, <max_tokens);
effort is gated independently. Adaptive models (incl. the default) are
unchanged.
Validated LIVE against api.anthropic.com with a Max OAuth token: haiku
headless (previously 400) + full Bash tool loop now pass; sonnet-4-6
default unchanged. Unit: updated 2 tests that pinned the old buggy
behavior, added the opus-4-7 adaptive-without-effort pin + a direct
allowlist matrix. Full suite green.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Testing the Claude subscription (OAuth) login flow end-to-end surfaced a pre-existing, general bug: every Anthropic request 400s with
adaptive thinking is not supported on this modelfor any model exceptsonnet-4-6/opus-4-6/opus-4-7._call_model_sync(src/query/query.py) sentthinking={"type":"adaptive"}+output_config={"effort":...}to all Claude 4.x models, gated only by the broad_model_supports_extended_thinkingregex. But adaptive thinking and effort are supported by only a narrow subset. This is not subscription-specific — the API-key path 400s identically — but the default modelsonnet-4-6supports adaptive, which masked it. For the subscription flow it was fatal: a Max user selectinghaiku(very plausible, to conserve rate limit) orsonnet-4-5got a hard 400 on every turn.Fix
Ports the authoritative adaptive-vs-budget selection from the in-repo upstream Claude Code source (
typescript/):claude.ts:1612-1640— the selection logicutils/thinking.ts:117-169—modelSupportsThinking(all Claude 4+ incl. Haiku on first-party) vsmodelSupportsAdaptiveThinking(opus-4-6/4-7, sonnet-4-6 only)utils/effort.ts:32-51—modelSupportsEffort(opus-4-6, sonnet-4-6 only)Two new helpers (
_model_supports_adaptive_thinking,_model_supports_effort) split the single injection into three independently-gated decisions:{type:adaptive}+ effort{type:adaptive}{type:enabled, budget_tokens}Budget models get
budget_tokens = max_tokens-1(clamped ≥1024, <max_tokens, matchingclaude.ts:1628-1635). Adaptive-capable models — including the defaultsonnet-4-6— are unchanged, so there is no regression for the common path.Validation
Live against
api.anthropic.comwith a Claude Max OAuth token (the subscription path #697 added):Also independently confirms the #697 subscription request path works: OAuth bearer + beta headers accepted,
mcp_tool prefixing/stripping correct,billing_mode: subscription($0), 2-turn tool exchange.Unit tests (
tests/test_query_extended_thinking.py): updated 2 that pinned the old buggy behavior (asserted adaptive forsonnet-4-5), added the opus-4-7 adaptive-without-effort regression pin (the fix's most fragile case) and a direct allowlist matrix. Full suite: 8482 passed, 3 skipped. Critic-reviewed: APPROVE.🤖 Generated with Claude Code