Skip to content

Studio: keep literal <think> text visible when the request turns thinking off - #10662

Merged
Lyxot merged 5 commits into
unslothai:mainfrom
NilayYadav:fix-responses-think-parse-gate
Sep 10, 2026
Merged

Lyxot merged 5 commits into
unslothai:mainfrom
NilayYadav:fix-responses-think-parse-gate

Conversation

@NilayYadav

Copy link
Copy Markdown
Collaborator

When a request turns thinking off, the server still runs the think tag splitter on the reply. So if a model writes the literal text <think>hi</think> as part of its answer, that text gets cut out of the visible reply and moved into a hidden reasoning block. A stray closing tag is deleted outright. This happens on the chat completions and responses endpoints, and Studio's own composer sends this shape when the Thinking toggle is off.

The gate now checks the request the same way the messages endpoint already does. Thinking off means the tags stay as text. Thinking on, always on reasoning models, and models that map thinking off to a low effort keep splitting as before. Two existing tests that locked in the old behavior are updated, and new tests cover both endpoints.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 9, 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-09-10T07:57:42.408327Z 4aa8a22 Manual request
🔒 Security Review ✅ Completed 2026-09-10T06:59:32.106669Z 4aa8a22 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 chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 316c4a5896

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

Comment thread studio/backend/routes/inference.py Resolved
@NilayYadav

Copy link
Copy Markdown
Collaborator Author

Reproduction on Actions (A/B)

Two branches off the same fresh upstream/main, running the same generated workflow with the same test files. The only difference between them is studio/backend/routes/inference.py: the base branch does not carry this PR's change, the head branch does. Verified byte-identical workflow and test files before pushing.

base implementation this PR (b59af700b)
run 34411250999 34411250612
install + collect success success
control: thinking-on cases still split 3 passed 3 passed
the gate: literal <think> survives with thinking off 6 failed, 1 passed 7 passed
result failure success

The probe step prints which implementation it got, so the pair cannot be mixed up: base logs shared gate helper ABSENT (this is the base implementation), head logs no bare string-only effort comparison left plus the three _resolved_kwargs_think sites.

What the base run actually fails on - this is the bug, on a runner:

# /v1/responses - the tags are moved into a reasoning item
assert ['reasoning', 'message'] == ['message']

# /v1/chat/completions - the text is cut out of the answer
assert 'Use  in your prompt.' == 'Use <think>hi</think> in your prompt.'

# streaming - the contents leak into reasoning_content
assert 'hi' == ''

The one test that passes on both sides is test_launch_default_thinking_on_still_parses_think_tags, the deliberate mirror: a thinking-on request must keep splitting. A pair where that one also flipped would mean parsing broke rather than the gate being fixed.

Since the last round the gate also handles two shapes it previously got wrong, both of which reproduce the exact symptom in the title:

  • A zero effort dial. For an Inkling template _request_reasoning_kwargs runs its result through _coerce_reasoning_effort, which rewrites the "none" sentinel to numeric 0.0, so a string-only comparison read thinking as still on. Numeric zero now reads as off.
  • The launch default. A request that names no reasoning field sends no override, so the model answers on the default it was launched with. The Qwen3.5/3.6 Small tier is launched with --chat-template-kwargs {"enable_thinking": false}; the terminal branch returned True regardless. It now follows reasoning_default, which is what _think_parsing_expected already did.

Both gates now share one helper, so "same rule as _think_parsing_expected" holds by construction rather than by copy.

@NilayYadav

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Something went wrong. Try again later by commenting “@codex review”.

Provided git ref b59af700b2e32294ef2122bbcf4ce5c225c76ab7 does not exist
ℹ️ 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".

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. You're on a roll.

Reviewed commit: b59af700b2

ℹ️ 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

Before / after, end to end

Two isolated Studio installs from the two commits, one resident gemma-3-270m-it-GGUF each, same launch template, same prompt, real HTTP.

  • BEFORE: merge base fcaad20ef on :9004
  • AFTER: head b59af700b on :9005

Gemma rather than Qwen3 because Qwen3 will not emit a raw <think> token in an answer, and the tags reach the model from the launch template, not from the prompt: Studio neutralizes control markup in message content on the way in (#7066), so a user turn containing <think> arrives as < think>. The template also renders identically whether thinking is on or off - it reads enable_thinking only so Studio detects the style - so the model's own output is the same in every call below and the only thing that varies is whether the server splits it.

Controls, identical on both sides (or the pair proves nothing): reasoning_style enable_thinking, thinking_pill_active false, all three HTTP statuses 200, and the thinking-on control comes back split on both: control_thinking_on_reasoning "hi", control_thinking_on_content "Use in your prompt.". That last pair is the proof the model really typed the tags and that both installs can still parse them.

What moved - every predeclared API fact, and nothing else:

fact BEFORE AFTER
api_content "Use in your prompt." "Use <think>hi</think> in your prompt."
api_reasoning_content "hi" ""
api_shows_think_tags false true
responses_output_kinds ["reasoning", "message"] ["message"]
responses_shows_think_tags false true

So on /v1/chat/completions and /v1/responses the sentence now survives intact when the request turns thinking off.

The chat bubble does not move, and that is worth saying

before/after

ui_shows_think_tags is false on both sides and both bubbles read Use / Thought for 0 seconds / in your prompt. This is not a missed click - the Thinking pill reads false on both sides and the turn ran.

The cause is in the source, not inferred: the frontend runs its own splitter over the reply text. parseAssistantContent(raw: string) in studio/frontend/src/features/chat/utils/parse-assistant-content.ts:104 takes no gate argument and splits <think> unconditionally, so on the AFTER side the server hands the browser the intact sentence and the browser splits it again. On the BEFORE side the server had already split it and the client re-wraps the reasoning for rendering - which is why the two renders are identical.

That is a separate defect on a different layer and not something to fold in here: gating it means threading a per-turn "thinking was off" flag through the streaming adapter, the incremental parser and the recovery replay. This PR's claim is the server-side gate, and the table above is the evidence for it. Worth a follow-up for the client-side splitter.

@NilayYadav

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Something went wrong. Try again later by commenting “@codex review”.

Provided git ref 64292b7fa8635eac6f69ee00228fa272af7b4faf does not exist
ℹ️ 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".

@chatgpt-codex-connector

Copy link
Copy Markdown

🛡️ Codex Security Review · Automatically triggered

Security review completed. No security issues were found in this pull request.

Reviewed commit: 64292b7fa8

View security finding report

Only the user who started this review can view the report in Codex.

ℹ️ About Codex security reviews in GitHub

This is an experimental Codex feature. Security reviews are triggered when:

  • You comment "@codex security review"
  • A regular code review gets triggered (for example, "@codex review" or when a PR is opened), and you’re opted in so security review runs alongside code review

Once complete, Codex will leave suggestions, or a comment if no findings are found.

@danielhanchen

Copy link
Copy Markdown
Member

Confirmed the gate in studio/backend/routes/inference.py still returns true for any reasoning-capable backend at the responses path, so literal think tag text is cut out of the reply even when the request turns thinking off, and sharing one helper with _think_parsing_expected is the right shape. Noted your point that parse-assistant-content.ts still splits client side, so I will review that separately.

@NilayYadav

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. More of your lovely PRs please.

Reviewed commit: 64292b7fa8

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

@chatgpt-codex-connector

Copy link
Copy Markdown

🛡️ Codex Security Review · Automatically triggered

Security review completed. No security issues were found in this pull request.

Reviewed commit: 64292b7fa8

View security finding report

Only the user who started this review can view the report in Codex.

ℹ️ About Codex security reviews in GitHub

This is an experimental Codex feature. Security reviews are triggered when:

  • You comment "@codex security review"
  • A regular code review gets triggered (for example, "@codex review" or when a PR is opened), and you’re opted in so security review runs alongside code review

Once complete, Codex will leave suggestions, or a comment if no findings are found.

@Lyxot Lyxot self-assigned this Sep 10, 2026
…g controls

The safetensors/MLX branch of /v1/chat/completions split <think> markup whenever the template supported reasoning, so a literal <think> quoted in a thinking-off reply was moved into reasoning_content. Read only the dial the template branches on, prefer enable_thinking on hybrid templates, and keep the template default for transformers image turns, whose generator drops both reasoning fields.
@Lyxot

Lyxot commented Sep 10, 2026

Copy link
Copy Markdown
Collaborator

Pushed a follow-up commit that closes the same bug on the safetensors/MLX path.

/v1/chat/completions has a second gate for transformers and MLX models, and it still decided whether to split <think> markup from template capability alone. With enable_thinking: false, a reply of Use <think>hi</think> in your prompt. still came back as Use in your prompt.

What changed:

  • _sf_parse_think_markers applies the same rule as the GGUF gates and reuses _resolved_kwargs_think. Both raw fields reach the template here, so the gate reads only the setting the template actually branches on. A plain enable_thinking template ignores the effort, an effort-only ladder ignores the boolean, and a hybrid template sent both reads enable_thinking first, as Kimi-K3 does.
  • Transformers image turns keep the old behavior, because _generate_vision_response never forwards either reasoning field. MLX image turns follow the request, since MLX passes both into its processor render.
  • A request with no reasoning fields still splits the markup, the same as before.

Tests in test_safetensors_reasoning_stream.py cover the route for text, transformers image and MLX image turns, and cover the helper for each template style. Each branch was checked by breaking it and confirming a test fails.

@Lyxot

Lyxot commented Sep 10, 2026

Copy link
Copy Markdown
Collaborator

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

🛡️ Codex Security Review · Automatically triggered

Security review completed. No security issues were found in this pull request.

Reviewed commit: 4aa8a229ea

View security finding report

Only the user who started this review can view the report in Codex.

ℹ️ About Codex security reviews in GitHub

This is an experimental Codex feature. Security reviews are triggered when:

  • You comment "@codex security review"
  • A regular code review gets triggered (for example, "@codex review" or when a PR is opened), and you’re opted in so security review runs alongside code review

Once complete, Codex will leave suggestions, or a comment if no findings are found.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 4aa8a229ea

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

Comment thread studio/backend/routes/inference.py Resolved
@Lyxot

Lyxot commented Sep 10, 2026

Copy link
Copy Markdown
Collaborator

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for security reviews. Please try again later.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. More of your lovely PRs please.

Reviewed commit: 4aa8a229ea

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

@Lyxot Lyxot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. The think-tag gate now follows the request on both the GGUF and safetensors/MLX paths, the tests cover each branch, and CI is green apart from the Core HF=latest job that also fails on main.

@Lyxot
Lyxot merged commit 1ceffa7 into unslothai:main Sep 10, 2026
45 of 47 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants