Repository navigation
Studio: honor the effort level Claude Code sends on /v1/messages - #9941
Conversation
(cherry picked from commit d508d6e)
|
@codex review |
Review + GitHub Actions reproductionPinned review: What Claude Code actually puts on the wireCaptured from Claude Code 2.1.251 against a local capture server on the path
The tier only ever arrives as The findingBecause the level is present on every request, adopting it unconditionally handed it A/B/C on ActionsOne probe, one dependency set, three regimes — only the checked-out Resolved
Reading the rows: Three regression tests cover the restored rows and fail on Note on the red checksBoth reds were checked against trees without this PR; neither is attributable here.
|
|
Codex Review: Didn't find any major issues. Delightful! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
|
@codex review |
|
Codex Review: Didn't find any major issues. Nice work! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
|
@codex review |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
Codex Review: Didn't find any major issues. Keep it up! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
|
Looks good! |
…lothai#17557) Turning thinking off in Claude Code does not stop a local model from thinking when Claude Code talks to Studio. With `MAX_THINKING_TOKENS=0`, or with thinking turned off in `/config`, a model whose template thinks by default (Qwen3, GLM and similar) still reasons on every turn. This was reported on Discord. ## Cause Claude Code only sends `thinking: {"type": "disabled"}` for Claude model ids it knows. For any other id, which is every model Studio serves, it sends `thinking: {"type": "adaptive"}` when thinking is on and leaves `thinking` out when thinking is off. The review capture in unslothai#9941 showed this on 2.1.251, and it is the same on 2.1.322: | Claude Code setting | Model id | `thinking` sent | |---|---|---| | default | `unsloth/Qwen3-0.6B-GGUF` | `{"type": "adaptive"}` | | `MAX_THINKING_TOKENS=0` | `unsloth/Qwen3-0.6B-GGUF` | absent | | `alwaysThinkingEnabled: false` | `unsloth/Qwen3-0.6B-GGUF` | absent | | `MAX_THINKING_TOKENS=0` | `claude-sonnet-4-6` | `{"type": "disabled"}` | `AnthropicMessagesRequest.resolved_enable_thinking()` reads a missing `thinking` as "use the model default", so the template default applies and the model thinks. ## Fix - When a `/v1/messages` request comes from Claude Code, a missing or null `thinking` now resolves to off. Claude Code is recognized by its `claude-cli/` User-Agent or its `claude-code-*` entry in `anthropic-beta`. Both are present under the environment `unsloth start claude` sets. - `/v1/messages/count_tokens` applies the same rule, so counting renders the same prompt as generation. ## Behavior boundaries - Other clients are unchanged: a missing `thinking` still means the model default. This matches Anthropic's API, where the default depends on the model ([per-model table](https://platform.claude.com/docs/en/build-with-claude/thinking)), and llama.cpp's and vLLM's `/v1/messages`, which also leave the template default in place. Making a missing field mean off for every client would break clients that rely on that default. - `enable_thinking` and `reasoning_effort` sent in the body still take precedence over `thinking`, so `unsloth start claude --reasoning on` keeps thinking on. - Claude Code's `CLAUDE_CODE_DISABLE_THINKING=1` sends the same request shape, so it now also turns thinking off. Claude Code's docs say the two settings behave the same on third-party providers. - `output_config.effort`, which Claude Code sends even with thinking off, still does not turn thinking back on. ## Testing Live, with Claude Code 2.1.322 (`claude -p`) against Studio on CPU with `unsloth/Qwen3-0.6B-GGUF` Q4_K_M, a model that thinks by default. Main is `5d5c1381b0`. | Claude Code setting | main | this PR | |---|---|---| | default | thinking block, 187 output tokens | thinking block, 182 output tokens | | `MAX_THINKING_TOKENS=0` | thinking block, 165 output tokens | no thinking block, 13 output tokens | | `alwaysThinkingEnabled: false` | thinking block, 112 output tokens | no thinking block, 12 output tokens | A direct `/v1/messages` request without `thinking` and with an `Anthropic/Python` User-Agent returns a thinking block on both main and this PR. Automated: - 13 new tests in `test_anthropic_messages.py`. They cover header detection, precedence against explicit controls, and the generation and count paths through the real route handlers. 12 of them fail on main. - The 21 backend test files that cover the Anthropic path pass (5,183 passed, 1 skipped). The in-session thinking toggle (Alt+T) was not tested.
/effort and --effort have no effect against a local model. The level is dropped before it reaches the template.
Studio reads the level as reasoning_effort. Claude Code sends it as output_config.effort, which nothing read. Thinking on and off already worked, so only the level was missing.
Studio emits the same shape when it calls Anthropic. This reads it on the way in as well. An explicit reasoning_effort still takes precedence, and an unrecognised level is ignored rather than rejected. Three tests cover it.