Repository navigation
Studio: Forward thinking controls and return reasoning on /v1/messages and /v1/responses - #9107
Conversation
…ed thinking blocks on all /v1/messages paths
💡 Codex ReviewWhen reasoning is streamed, both ℹ️ About Codex in GitHubCodex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback". |
💡 Codex ReviewWhen either streaming path emits reasoning, the unsloth/studio/backend/models/inference.py Line 2705 in 2cd0678 When an Anthropic client replays a returned https://github.com/unslothai/unsloth/blob/2cd0678fb7ffcb6cf4d9012173e8e9f6c394d041/studio/backend/routes/inference.py#L2962-L2963 When a caller sends only ℹ️ About Codex in GitHubCodex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback". |
|
All three addressed in 963131a: (1) thinking content_block_start now carries an empty signature field in both stream emitters; (2) anthropic_messages_to_openai() keeps replayed assistant thinking blocks as reasoning_content when preserve_thinking=true (dropped otherwise, redacted_thinking always dropped); (3) _anthropic_reasoning_args() now maps an effort-only request onto enable_thinking exactly like /v1/responses (none=off, named level=on) and the think-markup parsing gate reads those same effective args, so generation and parsing can no longer disagree. Tests added for each. |
…n effective template mode
preserve_thinking is three valued: omitted means use the template the model was launched with, and only an explicit value overrides it. Coercing it with bool() made an omitted field indistinguishable from an explicit false, so on a model whose launch template sets preserve_thinking_default the request stripped reasoning_content from every replayed turn while still leaving the server in preserve mode. The template was told to preserve history that had already been deleted. Resolve the effective value once and use it for both conversion and counting so the two cannot drift.
|
Codex Review: Didn't find any major issues. Bravo. 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". |
The request model states the x-unsloth reasoning controls win over thinking when both are present, and resolved_enable_thinking promises the same, but it consults only the boolean. Reading it first made the effort-to-boolean mapping dead whenever thinking was supplied, so on a plain enable_thinking template a request asking for thinking enabled with reasoning_effort none had the effort dropped and the model thought anyway, and the inverse stayed off. The effort-dial templates already honoured it, so one request meant three different things. llama.cpp resolves this itself, but only for a top-level reasoning_effort body field, and the passthrough payload forwards chat_template_kwargs only, so that never fires here.
|
@codex review |
1 similar comment
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 003d63b80c
ℹ️ 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".
| enable_thinking = payload.resolved_enable_thinking() | ||
| return { | ||
| "enable_thinking": enable_thinking, | ||
| "reasoning_effort": reasoning_effort, |
There was a problem hiding this comment.
Drop contradictory effort when enable_thinking is explicit
When a caller supplies both x-unsloth controls, this returns the explicit boolean and the contradictory effort together even though the new precedence test documents the boolean as authoritative. The downstream LlamaCppBackend._request_reasoning_kwargs at studio/backend/core/inference/llama_cpp.py:5125-5131 prioritizes a recognized effort for effort-dial models, so enable_thinking=false, reasoning_effort="high" becomes high effort on gpt-oss while the same request disables Qwen-style templates; the inverse pair likewise selects none. Normalize or discard reasoning_effort when enable_thinking is explicitly present so the request has consistent behavior across model families.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Not changing this. The premise is a misread of what the model documents. The comment above the x-unsloth group says These win over thinking when both are present, which is cross-group, the pair versus the native block; it says nothing about the two x-unsloth controls relative to each other. resolved_enable_thinking is documented the same way, preferring the x-unsloth field over thinking. Worth noting the authors did document independence where they meant it: preserve_thinking is explicitly Independent of enable_thinking / reasoning_effort. And the test cited as documenting the boolean as authoritative asserts only on the resolved boolean, never that reasoning_effort is dropped and never on template kwargs; it exists so an effort-only request can still drive a boolean-only template. So intra-group precedence is undefined, which makes this a design question rather than a bug. The family split reproduces, but it is a property of the families, not of this resolution. gpt-oss already ignores the boolean by design, and its published chat template contains no enable_thinking at all while Harmony defines only low, medium and high with no none, so enable_thinking false never means off there whatever we do. The split also predates this PR: the downstream branch is unchanged from the merge base and already governs chat completions on main, so this PR gives messages and responses the semantics the OpenAI endpoint already had. Both suggested resolutions regress well-formed input. Studio's own frontend sends both controls together and agreeing, because each family reads a different key. Discarding the effort when the boolean is explicit strips the effort level from every GLM turn the UI sends, and normalizing the effort to none when the boolean is false makes llama-server erase the kwarg so gpt-oss falls back to its medium template default, which is more reasoning than the low it gets today while claiming to disable. llama.cpp itself defines no precedence and treats the two as orthogonal, with only reasoning_effort none having a cross-effect. If you want intra-group precedence to become defined, that is an API decision to document in the request model first.
|
@codex review |
1 similar comment
|
@codex review |
|
Codex Review: Didn't find any major issues. What shall we delve into next? 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". |
Local models reasoning was invisible over Studio's Anthropic- and OpenAI-compatible endpoints:
thinking/reasoningrequest fields were parsed and silently dropped, and llama-server'sreasoning_contentwas never relayed back so clients like Claude Code and Codex could neither turn thinking on nor see the trace.Changes:
/v1/messages: accept Anthropic'sthinkingconfig (plus x-unslothenable_thinking/reasoning_effort/preserve_thinking) and forward them to llama-server aschat_template_kwargsthinking.typevalues (adaptive tiers) as "enabled" instead of 400ing; accept and ignorebudget_tokensreasoning_contentas Anthropicthinkingblocks (streaming SSE + non-streaming)/v1/responses: forwardreasoning.effortand returnreasoning_contentas reasoning output items (streaming + non-streaming)thinking/redacted_thinkingblocks in/v1/messagesinput so tool-use turns don't 422 on turn 2