Skip to content

Studio: validate the reasoning controls instead of coercing them - #9595

Merged
danielhanchen merged 31 commits into
unslothai:mainfrom
Apoze:fix/qwen-thinking-sampling-defaults
Sep 22, 2026
Merged

danielhanchen merged 31 commits into
unslothai:mainfrom
Apoze:fix/qwen-thinking-sampling-defaults

Conversation

@Apoze

@Apoze Apoze commented Aug 23, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Normalize the reasoning controls once per request, with real validation, and share that one result across every surface that renders a chat template: /v1/chat/completions, /v1/responses, /v1/messages, /chat/count_tokens and the MLX token counter.

  • Lift validated enable_thinking, reasoning_effort and preserve_thinking out of OpenAI extra_body.chat_template_kwargs, and consume the keys so the lift is a fixed point.
  • Accept the named effort levels the templates understand (none, minimal, low, medium, high, max, xhigh); ignore an invalid nested type rather than coercing it.
  • Keep explicit typed controls authoritative and drop a contradictory derived effort instead of letting it ride along into generation.
  • Map the Anthropic thinking block onto the boolean without recording it as an explicit field, so route precedence still ranks it below the nested controls.

Why

The old helper coerced whatever arrived in extra_body.chat_template_kwargs.enable_thinking with bool(). bool("false") is True, so a client asking for thinking to be off with a JSON string turned it on. Nested reasoning_effort was ignored outright, including the named levels such as medium and xhigh that some OpenAI-compatible clients send.

Conflicting controls were the other half of it: a request carrying enable_thinking=false alongside reasoning_effort="high" reasoned at high effort while the boolean said off. The effort is now dropped when it contradicts the boolean, before the model-specific translation runs, so this applies to every family and not only to the one that prompted it.

Worth stating plainly, since the summary could be read the other way: a nested control that is not a real JSON boolean is ignored, not honored. A client sending "false" no longer flips thinking on, but it does not turn it off either. The ignored value falls through to whatever mode the model was launched in, so such a client still ends up thinking on a template that reasons by default. Sending a real JSON false is what turns it off.

That rule is symmetric, and one case moves the other way: bool(0) is False, so a client sending {"enable_thinking": 0} for "off" used to get thinking off, by accident of the coercion being removed. It is now ignored like any other non-boolean type and falls through to the launch default. Same for 1, null, a list or an object. Only a real JSON boolean steers the template, in either direction.

This half changes no sampling default. A request that selects no reasoning mode resolves exactly as it did before.

Follow-up to #9372.

What is not here

This PR previously also made per-request sampling follow the reasoning mode and moved the Qwen3.8 Chat UI row onto its model card. That changed defaults for anyone already serving a Qwen3.8, so it has been taken out and left for a separate change. What remains is independent of any model family.

Validation

  • Backend: 2172 passed, 71 skipped across the sampling, thinking, Anthropic, Responses, OpenAI passthrough, auto-switch and MLX suites.
  • Frontend: 8165 passed, 0 failed.
  • Ruff clean on every changed Python file.
  • Real raw API conflict probes: explicit false + high produced no reasoning, explicit true + none preserved reasoning, and nested enable_thinking: "false" was ignored while a valid nested reasoning_effort: "none" disabled reasoning.
  • Real DeepSeek Harness calls against Qwen3.8 27B passed for off, medium and xhigh; final answers were correct and completion usage rose from 2 to 74 to 160 tokens.
  • Normalizing twice cannot change the answer: 576 request shapes checked, 0 drift.

@Apoze
Apoze requested a review from danielhanchen as a code owner August 23, 2026 20:55
@Apoze
Apoze force-pushed the fix/qwen-thinking-sampling-defaults branch 2 times, most recently from f70b0cc to fe247ac Compare August 23, 2026 22:56
chatgpt-codex-connector[bot]

This comment was marked as resolved.

@Apoze
Apoze force-pushed the fix/qwen-thinking-sampling-defaults branch 3 times, most recently from a62ebdb to cc8c05f Compare August 24, 2026 17:17
chatgpt-codex-connector[bot]

This comment was marked as resolved.

@oobabooga

Copy link
Copy Markdown
Member

Reproduced each path against a loaded Qwen3.8-27B configuration. The three Codex items are real and are resolved at 7a6bdb8:

  • reasoning_effort: "none" alone now resolves to the non-thinking row (0.7 / 0.8 / presence_penalty 1.5) and _request_reasoning_kwargs emits {"enable_thinking": false}, so sampling and generation stop disagreeing. "xhigh" alone gives the thinking row with {"enable_thinking": true, "reasoning_effort": "xhigh"}.
  • Responses forwards nested reasoning_effort and preserve_thinking, and the native reasoning field still takes precedence.
  • /chat/count_tokens emits {"enable_thinking": false} for a nested reasoning_effort: "none" where it previously emitted nothing and priced the prompt in whatever mode the model was loaded in.

The sampling_modes values match the Qwen3.8-27B card, and load_inference_config rebuilds its result from a fixed key list, so the new block never reaches the .inference payload.

Two things I want settled before this goes in.

The undeclared request is still split. _normalized_sampling_thinking_mode returns None when a request carries no reasoning control, so resolution falls back to the flat family block, which is the instruct row with presence_penalty 1.5. Generation goes the other way: llama_cpp.py:18807-18827 sets thinking_default = True for every reasoning model, and the <= 9B carve-out only covers qwen3.5 and qwen3.6, so Qwen3.8-27B launches with enable_thinking: true and a request that sends no template kwargs inherits it. A plain OpenAI SDK call therefore generates in thinking mode while sampling with the presence penalty the card warns can cause language mixing. That is not a regression, main did it for every request, but it is the request shape most external clients send and it is the case the summary is about. reasoning_always_on and reasoning_default are already public on the backend and llama_backend is in scope immediately above the sampling fill in openai_chat_completions, so resolving the undeclared case against the loaded model is local rather than a plumbing change. Do you intend to cover it here, or leave the flat fallback as the compatibility guard? It changes the effective defaults for every existing client, so I would rather that were a stated choice than a leftover.

7a6bdb8 moved the backend off the UI table. Before that commit sampling_modes.thinking was 0.6 / 0.95 / 20 / 0.0 / presence_penalty 1.5, which is exactly what resolveQwenThinkingParams returns for this family. It is now 1.0 / 0.95 / 20 / 0.0 / presence_penalty 0.0. apply-inference-status-to-store.ts:670-683 layers resolveQwenThinkingParams over mergeBackendRecommendedInference, so on a builtin-default preset the frontend table wins over the .inference block, and the Chat UI keeps 0.6 / presence_penalty 1.5 for the same model and mode the API now answers with 1.0 / 0.0.

The card is right and the frontend row is wrong, so I do not want this PR to move back to match it. It is also not specific to Qwen3.8: the Qwen3.6-27B card carries the same thinking / non-thinking split, Qwen3.5-9B differs again, and resolveQwenThinkingParams serves one row to all three. That is a frontend change across the tier and it should not ride along in a backend PR, so please leave it out of this one. test_recommendation_matches_ui_source currently only exercises thinking_mode=None, so extending it to the mode branches belongs with that change rather than here.

Smaller points:

  • The body describes _resolve_reasoning_controls as discarding a contradictory derived effort, which undersells it. enable_thinking: true with reasoning_effort: "none" used to reach _request_reasoning_kwargs intact, where thinking_off turned thinking off and the explicit boolean lost. It now resolves to {"enable_thinking": true} with no effort key, so the template default applies, which for this family is xhigh. Honoring the typed boolean is the precedence the request model documents and I think it is the right call, but it changes /v1/messages, /v1/chat/completions, /v1/responses and chat_count_tokens at once, so state it in the body instead of leaving it to the test_anthropic_messages.py diff.
  • _chat_template_reasoning_kwargs requires a real JSON boolean, so {"enable_thinking": "false"} is ignored rather than coerced true. That is better than bool("false"), though a client sending that string still ends up thinking, since the ignored value falls through to the launch default. Worth a sentence so nobody reads the summary as saying the string form now works.

Both CI failures are unrelated to the change. Repo tests (CPU) is the README launch-section assertion in tests/sh/test_install_host_defaults.sh; merging this head into current main and running that script passes 45 of 45. Chat UI Tests (banner) lost libcurl4-openssl-dev to an apt mirror 404 and then vite exited 127. I will re-run both.

chatgpt-codex-connector[bot]

This comment was marked as resolved.

@Apoze
Apoze force-pushed the fix/qwen-thinking-sampling-defaults branch from 870cf61 to 24da80e Compare August 26, 2026 17:19
@Apoze

Apoze commented Aug 27, 2026

Copy link
Copy Markdown
Contributor Author

Addressed in a64e780: the Qwen3.8 Chat UI thinking row now matches the backend table (temperature 1.0, presence_penalty 0.0). The change is scoped to Qwen3.8 thinking mode; Qwen3.5, Qwen3.6, generic Qwen3, and all non-thinking defaults remain unchanged. A frontend/backend parity regression test was added. Local validation: 5387 frontend tests passed, plus typecheck, production build, bundle budget, focused ESLint, Prettier, and diff checks.

@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Aug 31, 2026
The third surface this branch deliberately leaves mode-blind, after
/v1/completions and the load/status .inference block. A transformers or MLX load
has no recorded launch mode: Studio picks the llama.cpp one itself and stores it
as reasoning_default, while detect_reasoning_flags only ever says whether a
template CAN reason, never what it does when the kwarg is absent, and
apply_chat_template_for_generation omits the kwarg entirely in that case. So a
silent request there keeps the historical flat row, and an explicit control still
reaches the mode row on the same load.

Giving that path a real mode means declaring a per-family default (the shape
external providers already use with thinking_default_on) or teaching the
classifier to read the template's own, both of which change behaviour for every
reasoning family. Test so the current answer has to be changed on purpose.

107 passed in test_sampling_resolution.py.
danielhanchen pushed a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Sep 21, 2026
The migration recognized the previously generated Qwen3.8 thinking row by
asking whether the row the session currently resolves to has presence
penalty zero. That is only true in thinking mode. A Studio that came up
with Think off resolved the non-thinking row, whose presence penalty is
1.5, so the guard rejected the snapshot and left temperature 0.6 / top_p
0.95 in place against the 0.7 / 0.8 the non-thinking row now asks for.
It repaired itself only if the user happened to toggle Think.

Ask the model instead: the family whose thinking row carries zero presence
penalty is Qwen3.8 alone, and that answer does not move with the mode. The
replacement row is still whichever one the session resolves, so a Think-off
startup migrates to 0.7 / 0.8 and a Think-on startup to 1.0 / presence 0.

The same substitution is made for the global snapshot, which had the
identical guard.
Comment-only pass over the lines this PR adds: 61 comment lines removed, none
of the facts. What survives is the invariant the code does not state (the lift
has to be a fixed point, the id must match before the launch state may be read,
the .inference block is not mode-aware, String.match takes the leftmost),
one line each instead of a paragraph. Rationale that belongs in the PR
description rather than the source is gone.

Verified comment-only by comment_tools.py check (8/8, --strict-ext
--allow-docstring-edits). Backend 117 passed, frontend 8169 passed.
Leaves only the fix that is independent of any model family: the validated
merge of typed and nested reasoning controls, shared by /v1/chat/completions,
/v1/responses, /v1/messages, /chat/count_tokens and the MLX token counter.
The headline case is a client sending the JSON string "false" for
extra_body.chat_template_kwargs.enable_thinking, which the old bool() lift
turned into True and so switched thinking on when it was asked to be off.

Removed, to be considered separately:

  - the sampling_modes block in inference_defaults.json and the thinking_mode
    argument threaded through load_inference_config, _recommended_sampling and
    resolve_effective_sampling
  - _sampling_thinking_mode, _normalized_sampling_thinking_mode and
    _loaded_llama_backend_for, plus the two call sites that priced a request on
    the mode generation would run in
  - the frontend Qwen3.8 table change and its stored-defaults migration

Those changed sampling defaults for anyone already serving a Qwen3.8; this
half changes no default and only makes the reasoning controls mean what they
say. The two tests that asserted both halves now assert only the controls.

Backend 2172 passed, 71 skipped. Frontend 8165 passed. Ruff clean.
@shimmyshimmer shimmyshimmer changed the title Studio: apply Qwen3.8 sampling defaults by reasoning mode Studio: validate the reasoning controls instead of coercing them Sep 21, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 22, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 22, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 22, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 22, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 22, 2026
@unslothai unslothai deleted a comment from oobabooga Sep 22, 2026
@unslothai unslothai deleted a comment from oobabooga Sep 22, 2026
@unslothai unslothai deleted a comment from oobabooga Sep 22, 2026
@unslothai unslothai deleted a comment from oobabooga Sep 22, 2026
@unslothai unslothai deleted a comment from Apoze Sep 22, 2026
@danielhanchen

Copy link
Copy Markdown
Member

Scope narrowed

This PR now contains only the reasoning-control validation. The mode-aware sampling work has been removed, at 757b6b721.

Gone from the diff:

  • the sampling_modes block in inference_defaults.json, and the thinking_mode argument threaded through load_inference_config, _recommended_sampling and resolve_effective_sampling
  • _sampling_thinking_mode, _normalized_sampling_thinking_mode and _loaded_llama_backend_for, with the two call sites that priced a request on the mode generation would run in
  • the frontend Qwen3.8 table change and its stored-defaults migration

inference_config.py and every frontend file are back to main byte for byte. The diff is 9 files, +678 / -56, all backend.

What remains is the validated merge of typed and nested reasoning controls, shared by /v1/chat/completions, /v1/responses, /v1/messages, /chat/count_tokens and the MLX token counter: the bool("false") == True lift is gone, nested reasoning_effort is honored at its named levels, and a contradictory effort is dropped rather than riding along into generation. None of that changes a sampling default.

This answers two things raised above rather than deferring them.

@oobabooga asked for the frontend row to be left out: "That is a frontend change across the tier and it should not ride along in a backend PR, so please leave it out of this one." It is out. The Qwen3.6 and Qwen3.5 rows you noted carry the same thinking / non-thinking split, so that change belongs with a table-wide one.

@Imagineer99 noted that Studio's Qwen defaults intentionally differ from the HF card and that this PR changed that alignment. It no longer does. No recommended sampling value moves in this PR.

Two review threads above are now about code that is not in the diff: the qwen-params.ts matcher item and the qwen-sampling-table.ts family item. They are left in place as the record of how they were settled, but they do not describe this PR any more. The routes/inference.py thread about the MLX and transformers gap is likewise moot here, since nothing in this PR resolves sampling against the loaded backend.

Verification on the current head

  • Backend 2172 passed, 71 skipped across the sampling, thinking, Anthropic, Responses, OpenAI passthrough, auto-switch and MLX suites.
  • Frontend 8165 passed, 0 failed.
  • Ruff clean, and every changed Python file is a fixed point of the pinned ruff-format-with-kwargs hook.
  • Normalizing twice cannot change the answer: 576 request shapes, 0 drift.

Full CI on a staging mirror is green apart from five failures that reproduce unchanged on main: four tests/studio source-text contract tests, and test_source_read_encoding naming studio/backend/tests/test_reset_password_command.py:165, a file this PR does not contain.

danielhanchen and others added 2 commits September 22, 2026 11:32
The body of this PR discloses that the string form is ignored rather than
honored, and the suite covers "false". The same rule applies to every
non-boolean JSON type, and one of them changes an answer in the other
direction: on main bool(0) is False, so a client sending

    "chat_template_kwargs": {"enable_thinking": 0}

for "off" got thinking off, by accident of the coercion this PR removes.
It is now ignored and falls through to the mode the model was launched in,
exactly as "false" does. That is the right rule, but it was untested, so
nothing would have caught it changing again.

Three tests:

- a nested enable_thinking that is not a JSON boolean is ignored, over
  "false", "true", 0, 1, null, [], {} and the empty string, and is consumed
  either way so no render sees a value the validation just refused;
- the same for preserve_thinking;
- the property the other two are instances of: an ignored nested control
  resolves exactly as omitting the key would, so "ignored" cannot become a
  third outcome that still steers generation. A valid control sent beside an
  invalid one is still honored.

Restoring main's bool() coercion fails 9 of the 16 added cases.
@danielhanchen

Copy link
Copy Markdown
Member

Review record for #9595, carried over from the mirror it was reviewed on: danielhanchen/unsloth-staging-review#61.

Findings are quoted as posted and attributed to the account that posted them. The reactions shown are the triage recorded on the mirror; none were re-applied here.

The mirror was built as a single squashed replay of this PR onto current upstream main, so its commit SHA has no counterpart here by construction. Mirror 32e3804da is this PR at f801c89b9, tree for tree.

Round 1 — reviewed mirror 32e3804da, which is this PR at f801c89b9

chatgpt-codex-connector[bot] (on the mirror)

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

Reviewed commit: 32e3804da2

Nothing to triage: the round produced no inline items.

Verdict

The round converged at mirror 32e3804da, this PR at f801c89b9. Nothing has been pushed to this PR since.

This is the review as it stood at that commit. Anything pushed to this PR afterwards was not part of it.

@unslothai unslothai deleted a comment from shimmyshimmer Sep 22, 2026
@danielhanchen
danielhanchen merged commit 3ace662 into unslothai:main Sep 22, 2026
53 of 56 checks passed
@danielhanchen

Copy link
Copy Markdown
Member

CI status on f801c89b9

One check is red, Repo tests (CPU, studio), and it is not this PR's. Both failures in it are the Docker Hub organization-token tests:

FAILED tests/python/test_docker_credential_probe.py::test_the_delete_uses_the_namespace_route_the_org_token_is_allowed_on
FAILED tests/python/test_docker_hub_readme.py::test_the_sync_patches_the_readme_and_confirms_it
  AssertionError: the organization token authenticates as the org

Neither file is in this diff, and both fail the same way on current main at ed1530922 run locally, so this is the org credential not reaching a fork-head PR rather than anything the branch changed.

The other two reds cleared on a re-run and were infrastructure: connection (dsh, stable) was npm error code ETARGET, No matching version found for @deepseek-ai/dsh-client-ui-sidebar-documentpreview@^0.1.5-rc.3, and (Python 3.13, l-r) was the wall-clock assertion in test_a_load_that_stalls_times_out_one_timeout_after_its_last_work, which passes on both main and this branch when run off a loaded runner.

Everything else is green, including pre-commit.ci.

shaojun pushed a commit to shaojun/unsloth that referenced this pull request Sep 29, 2026
…lothai#9595)

* Studio: apply Qwen3.8 sampling defaults by reasoning mode

* Studio: honor nested reasoning request controls

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Studio: complete nested reasoning request paths

* Studio: align Qwen3.8 thinking sampling with model card

* Resolve the reasoning mode from the same sentinels generation uses

* Studio: align Qwen3.8 frontend thinking defaults

* Tighten the comments on the reasoning-control paths

* Price a silent request on the mode llama-server was launched in

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Pick sampling from the resolver generation already uses

* Trust a backend that reports no reasoning, and drop an unknown effort

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Migrate prior Qwen3.8 thinking defaults

* Say what is and is not mode-aware, and pin both

Two claims in this branch were wider than the code.

_sampling_thinking_mode said the Chat UI "already seeds itself this way" and
pointed at apply-inference-status-to-store.ts. The UI does land on the same row,
but not through the .inference block of load/status: that block is
load_inference_config with no mode, and for a thinking-default Qwen3.8 it still
answers temperature 0.7 / presence_penalty 1.5. The UI matches because
resolveQwenThinkingParams is layered over mergeBackendRecommendedInference, so
any other reader of /inference/status sees the flat row. Reworded to say that,
and pinned by test_the_status_inference_block_is_not_the_mode_aware_one.

/v1/completions was left on the flat row with no reason given, which reads as an
oversight next to the chat path. It is not: the raw endpoint renders no chat
template, so the launch --chat-template-kwargs that decide whether a chat
request reasons never apply to it, and pricing a raw continuation on the launch
mode would re-price it on the strength of how the model happens to be loaded.
The two endpoints therefore answer with different sampling for one loaded model
on purpose. Stated in the docstring and pinned by
test_raw_completions_are_never_priced_on_the_launch_mode, which fails if that
call is ever made mode-aware.

No behaviour change: 93 passed in test_sampling_resolution.py, 91 of them the
existing cases, unchanged.

* Make the reasoning lift a fixed point and settle the family on 3.8

Two defects found while enumerating this branch against main.

The lift was not idempotent. It writes its result onto the typed fields, so a
second call reads a typed effort of None where the first read the client's,
takes the nested-effort rescue the first deliberately skipped, and hands
generation a level the request had already lost the right to:

  typed {enable_thinking: true, reasoning_effort: "none"}
  nested {reasoning_effort: "high"}
     pass 1 -> (True, None)      pass 2 -> (True, "high")

36 of 576 typed x nested shapes drifted. /v1/responses is the live double call:
_build_chat_request normalizes the request it builds and the chat route
normalizes it again. It is inert today only because that rebuild drops the
nested dict, so one line forwarding chat_template_kwargs would make it real.
The lift now consumes the three reasoning keys it takes, rebinding a filtered
copy rather than popping in place, since the dict comes from the parsed body.
0 of 576 shapes drift after it.

resolveQwenThinkingParams picked the family from the leftmost regex match, so an
id naming two Qwen families answered with the wrong one:

  Qwen3.5-Draft/Qwen3.8-27B-Q4_K_M.gguf   UI 0.6 / p1.5   API 1.0 / p0.0
  /models/qwen3.6/qwen3.8-27b.gguf        UI 0.6 / p1.5   API 1.0 / p0.0

The backend strips the org prefix and scans its family patterns longest-first,
so qwen3.8 wins wherever it appears. Before this branch gave the families
different rows the divergence was invisible; a draft pairing or a per-family
directory is enough to hit it. The 3.8 test is now its own boundary-anchored
pattern, so position stops deciding. Qwen3.80 and Qwen3.8B are still not
Qwen3.8, and the other 18 cells of the id x mode matrix are unchanged.

Also drops a stale parity claim from _recommended_sampling's docstring for the
same reason as the previous commit.

Verified: the 232-cell base-vs-head differential is unchanged by these fixes, so
no first-pass behaviour moved. studio/backend 2231 passed, 71 skipped;
studio/frontend 8167 passed, 0 failed; build clean. Each fix reverted on its own
fails the test added with it.

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Pin the non-GGUF silent request on the flat row

The third surface this branch deliberately leaves mode-blind, after
/v1/completions and the load/status .inference block. A transformers or MLX load
has no recorded launch mode: Studio picks the llama.cpp one itself and stores it
as reasoning_default, while detect_reasoning_flags only ever says whether a
template CAN reason, never what it does when the kwarg is absent, and
apply_chat_template_for_generation omits the kwarg entirely in that case. So a
silent request there keeps the historical flat row, and an explicit control still
reaches the mode row on the same load.

Giving that path a real mode means declaring a per-family default (the shape
external providers already use with thinking_default_on) or teaching the
classifier to read the template's own, both of which change behaviour for every
reasoning family. Test so the current answer has to be changed on purpose.

107 passed in test_sampling_resolution.py.

* Recognize the prior Qwen3.8 snapshot regardless of the startup mode

The migration recognized the previously generated Qwen3.8 thinking row by
asking whether the row the session currently resolves to has presence
penalty zero. That is only true in thinking mode. A Studio that came up
with Think off resolved the non-thinking row, whose presence penalty is
1.5, so the guard rejected the snapshot and left temperature 0.6 / top_p
0.95 in place against the 0.7 / 0.8 the non-thinking row now asks for.
It repaired itself only if the user happened to toggle Think.

Ask the model instead: the family whose thinking row carries zero presence
penalty is Qwen3.8 alone, and that answer does not move with the mode. The
replacement row is still whichever one the session resolves, so a Think-off
startup migrates to 0.7 / 0.8 and a Think-on startup to 1.0 / presence 0.

The same substitution is made for the global snapshot, which had the
identical guard.

* Cut the commentary this PR added down to the load-bearing lines

Comment-only pass over the lines this PR adds: 61 comment lines removed, none
of the facts. What survives is the invariant the code does not state (the lift
has to be a fixed point, the id must match before the launch state may be read,
the .inference block is not mode-aware, String.match takes the leftmost),
one line each instead of a paragraph. Rationale that belongs in the PR
description rather than the source is gone.

Verified comment-only by comment_tools.py check (8/8, --strict-ext
--allow-docstring-edits). Backend 117 passed, frontend 8169 passed.

* Narrow this PR to the reasoning-control validation

Leaves only the fix that is independent of any model family: the validated
merge of typed and nested reasoning controls, shared by /v1/chat/completions,
/v1/responses, /v1/messages, /chat/count_tokens and the MLX token counter.
The headline case is a client sending the JSON string "false" for
extra_body.chat_template_kwargs.enable_thinking, which the old bool() lift
turned into True and so switched thinking on when it was asked to be off.

Removed, to be considered separately:

  - the sampling_modes block in inference_defaults.json and the thinking_mode
    argument threaded through load_inference_config, _recommended_sampling and
    resolve_effective_sampling
  - _sampling_thinking_mode, _normalized_sampling_thinking_mode and
    _loaded_llama_backend_for, plus the two call sites that priced a request on
    the mode generation would run in
  - the frontend Qwen3.8 table change and its stored-defaults migration

Those changed sampling defaults for anyone already serving a Qwen3.8; this
half changes no default and only makes the reasoning controls mean what they
say. The two tests that asserted both halves now assert only the controls.

Backend 2172 passed, 71 skipped. Frontend 8165 passed. Ruff clean.

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Studio: pin that a nested reasoning control must be a real JSON boolean

The body of this PR discloses that the string form is ignored rather than
honored, and the suite covers "false". The same rule applies to every
non-boolean JSON type, and one of them changes an answer in the other
direction: on main bool(0) is False, so a client sending

    "chat_template_kwargs": {"enable_thinking": 0}

for "off" got thinking off, by accident of the coercion this PR removes.
It is now ignored and falls through to the mode the model was launched in,
exactly as "false" does. That is the right rule, but it was untested, so
nothing would have caught it changing again.

Three tests:

- a nested enable_thinking that is not a JSON boolean is ignored, over
  "false", "true", 0, 1, null, [], {} and the empty string, and is consumed
  either way so no render sees a value the validation just refused;
- the same for preserve_thinking;
- the property the other two are instances of: an ignored nested control
  resolves exactly as omitting the key would, so "ignored" cannot become a
  third outcome that still steers generation. A valid control sent beside an
  invalid one is still honored.

Restoring main's bool() coercion fails 9 of the 16 added cases.

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: oobabooga <[email protected]>
Co-authored-by: Daniel Han <[email protected]>
Co-authored-by: danielhanchen <[email protected]>
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.

4 participants