Skip to content

Studio: honor the effort level Claude Code sends on /v1/messages - #9941

Merged
mahiatlinux merged 4 commits into
unslothai:mainfrom
NilayYadav:fix-anthropic-effort-passthrough
Aug 30, 2026
Merged

mahiatlinux merged 4 commits into
unslothai:mainfrom
NilayYadav:fix-anthropic-effort-passthrough

Conversation

@NilayYadav

Copy link
Copy Markdown
Collaborator

/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.

@NilayYadav

Copy link
Copy Markdown
Collaborator Author

@codex review

@NilayYadav

NilayYadav commented Aug 28, 2026 •

Copy link
Copy Markdown
Collaborator Author

Review + GitHub Actions reproduction

Pinned review: 63c69a42b77e562fe222935367d1dd6d5bf67fd2 — one blocking finding, fixed in this PR.

What Claude Code actually puts on the wire

Captured from Claude Code 2.1.251 against a local capture server on the path unsloth start wires up (ANTHROPIC_BASE_URL), POST /v1/messages?beta=true:

client state output_config thinking reasoning_effort
--effort high {"effort": "high"} {"type": "adaptive", "display": "omitted"} absent
--effort low {"effort": "low"} {"type": "adaptive", "display": "omitted"} absent
no flag (session default) {"effort": "xhigh"} {"type": "adaptive", "display": "omitted"} absent
thinking off (MAX_THINKING_TOKENS=0) {"effort": "high"} absent absent

The tier only ever arrives as output_config.effort, which is the premise this PR is built on. The last row is what the finding turned on: the effort is still sent when thinking is off.

The finding

Because the level is present on every request, adopting it unconditionally handed it reasoning_effort's documented power to outrank thinking (the precedence _THINKING_EFFORT_MATRIX pins). A session that asked for no reasoning got reasoning anyway, pinned to a level the user never chose. The fix takes the level only once thinking already resolves on, so output_config.effort stays a level dial rather than becoming an always-on thinking switch.

A/B/C on Actions

One probe, one dependency set, three regimes — only the checked-out studio/backend differs between jobs: run 33214603696. Each job asserts its regime exactly and fails on any drift.

Resolved chat_template_kwargs for an enable_thinking_effort (GLM-style) template:

Claude Code shape base 9640d8c6 prefix 3d7b5f6e fixed 63c69a42b
thinking on, /effort high {'enable_thinking': True} {'enable_thinking': True, 'reasoning_effort': 'high'} {'enable_thinking': True, 'reasoning_effort': 'high'}
thinking on, /effort low {'enable_thinking': True} {'enable_thinking': True, 'reasoning_effort': 'low'} {'enable_thinking': True, 'reasoning_effort': 'low'}
thinking off, effort high None {'enable_thinking': True, 'reasoning_effort': 'high'} None
thinking: {"type": "disabled"} {'enable_thinking': False} {'enable_thinking': True, 'reasoning_effort': 'high'} {'enable_thinking': False}

Reading the rows: base proves the bug this PR fixes — the tier never reaches the template, and on reasoning_effort-style templates it resolved to a blanket high regardless of the level asked for. prefix proves the tier now lands (rows 1–2) but that thinking-off had become thinking-on (rows 3–4). fixed keeps rows 1–2 and returns rows 3–4 to exactly what base did.

Three regression tests cover the restored rows and fail on prefix.

Note on the red checks

Both reds were checked against trees without this PR; neither is attributable here.

  • startup windows-latest fails in Install Unsloth on Access is denied removing _pydantic_core.cp313-win_amd64.pyd, before any code from this PR runs. It survived a rerun and reproduces byte-identically on unrelated branches (e.g. codex/issue-9737-mcp-arguments-r2), so it is a deterministic repo-wide installer issue rather than a flake.

  • (Python 3.13) Backend CI reports 20 failures across test_async_singleton_access, test_openai_auto_switch, test_parallel_slots_per_load, test_responses_tool_passthrough and test_video_attachment_part — none in the Anthropic path. Running those five files on plain 4b52ff56b and on 4b52ff56b merged with this PR head gives identical failure sets (25 = 25 locally), zero introduced and zero fixed, so they are pre-existing on main.

  • Core (HF=default + TRL=default) fails in its unsloth_zoo @ main - full pytest (CPU) step: 9 failures, all in tests/test_mlx_neftune_quant_map.py. That step clones unsloth_zoo fresh at its own moving main, so the failures live in a separate repository this PR cannot alter, and concern MLX NEFTune rather than anything it touches.

startup macos-15 was a transient Failed to CreateArtifact: ENOTFOUND and cleared on rerun.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Delightful!

Reviewed commit: 63c69a42b7

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

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".

@NilayYadav

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Nice work!

Reviewed commit: 63c69a42b7

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

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".

@mahiatlinux
mahiatlinux self-requested a review August 30, 2026 23:08
@mahiatlinux

Copy link
Copy Markdown
Contributor

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Aug 30, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-08-30T23:11:41.201690Z f749ce5 Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Keep it up!

Reviewed commit: f749ce5cba

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

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".

@mahiatlinux

Copy link
Copy Markdown
Contributor

Looks good!

@mahiatlinux
mahiatlinux merged commit 565cecd into unslothai:main Aug 30, 2026
44 checks passed
danielhanchen pushed a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Nov 12, 2026
…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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants