Skip to content

Default preserve thinking on for Qwen3.8 - #9096

Merged
oobabooga merged 7 commits into
unslothai:mainfrom
Imagineer99:fix/qwen38-preserve-thinking-default
Aug 19, 2026
Merged

oobabooga merged 7 commits into
unslothai:mainfrom
Imagineer99:fix/qwen38-preserve-thinking-default

Conversation

@Imagineer99

Copy link
Copy Markdown
Member

Summary

  • default preserve_thinking on for Qwen3.8 models whose chat template supports it
  • advertise the resolved model-family default through load and status responses
  • hydrate normal, adopted, auto-loaded, and queued chat runtimes from the backend default
  • keep Qwen3.6, Gemma 4, unsupported templates, and unrelated model families default-off
  • preserve an explicit user choice when reloading the same model

Why

Qwen3.8 enables preserve_thinking by default for all workloads, and its official template retains historical reasoning when the option is omitted or true:

Studio initialized preserveThinking to false globally and sent that value on every supported chat request. The llama.cpp launch path also explicitly set the option to false. Together, those overrides made Qwen3.8 forget prior reasoning despite the model's documented default.

Implementation

The backend now resolves preserve_thinking_default from both the model identifier and actual template support. Only a bounded Qwen3.8 family match opts in. The value is exposed on load/status responses and consumed by each frontend model-load and status-adoption path, including queued empty-model auto-loads.

Validation

  • 54 passed — focused safetensors capability and template A/B tests
  • 417 passed — inference status, GGUF loading, Gemma 4, OpenAI passthrough, tunnel, and active-generation tests
  • 3490 passed — complete frontend Node test suite
  • frontend TypeScript typecheck passed
  • git diff --check passed
  • isolated Chromium Playwright A/B passed:
    • BEFORE a41f77853: Qwen3.8 Preserve thinking unchecked
    • AFTER e2bdf0502: Qwen3.8 Preserve thinking checked
    • identical mocked Qwen3.8 status on both sides, two status reads each, zero page or console errors

Copy link
Copy Markdown
Member Author

Playwright A/B evidence

Both isolated Studio sides received the same mocked Qwen3.8 status (supports_preserve_thinking: true, preserve_thinking_default: true).

  • BEFORE (a41f77853): Preserve thinking unchecked
  • AFTER (e2bdf0502): Preserve thinking checked
  • 2 status reads per side; 0 page errors; 0 console errors

Playwright A/B showing Preserve thinking OFF before and ON after

@Imagineer99
Imagineer99 marked this pull request as ready for review August 17, 2026 12:03

@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: a6b4132bc4

ℹ️ 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 on lines +348 to +350
...(hydratingExistingModel && {
preserveThinking: preserveThinkingDefault,
}),

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Fence the model default against settings hydration

When a model status/load races the asynchronous hydratePersistedSettings() call, this direct setState does not advance the scalar-setting mutation version, while the hydration loop can independently assign the stored preserveThinking value. Consequently, on startup with a resident Qwen3.8 model and any previously stored value, whichever request finishes last wins: hydration may turn the advertised default back off, or a later status may overwrite the user's saved choice. Coordinate this model-default update with the hydration fence or apply it only after hydration so the result is deterministic.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Confirmed and fixed in 2743bd8. Reproduced against the real store: with a stored preserveThinking: false the settings GET and /api/inference/status race on a cold boot with a resident Qwen3.8, and the raw setState here advanced no scalar mutation version, so whichever landed last won.

Both writers now go through resolvePreserveThinkingOnLoad in chat-runtime-store, which returns the installation's stored answer when there is one and the advertised family default only when there is none. That makes the two orderings agree: a status that overtakes hydration seeds the default and hydration then applies the stored value through the existing fence, and a status that lands after hydration no longer overwrites it. Same rule resolveToolsEnabledOnLoad already applies to the tool pills.

Covered by studio/frontend/tests/preserve-thinking-user-preference.test.ts, which drives the real store through the held settings GET.

@danielhanchen

Copy link
Copy Markdown
Member

Confirmed the launch path in studio/backend/core/inference/llama_cpp.py still forces preserve_thinking to false, so a Qwen3.8 load never matches the model's own template default, and the resolved value now reaches the frontend through load and status. Could you get the lint and backend CPU test failures green so this can be reviewed?

@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: a17ded8ce3

ℹ️ 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 on lines +1693 to +1696
preserveThinking:
reloadingSameModel && supportsPreserveThinking
? stateBeforeUnload.preserveThinking
: preserveThinkingDefaultFromLoad(loadResponse),

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Preserve the user's setting when returning to Qwen3.8

After settings hydration, switching away from Qwen3.8 and later loading it again makes reloadingSameModel false, so this replaces an explicitly persisted preserveThinking: false with the advertised true default. The direct setState does not update persistence, leaving the current session enabled even though the saved preference remains disabled, and subsequent requests include prior reasoning contrary to the user's choice. Apply the family default only when no user preference exists, rather than on every cross-model load.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Confirmed and fixed in 2743bd8. With reloadingSameModel false this branch published the family default unconditionally, so leaving Qwen3.8 and coming back replaced a persisted preserveThinking: false with true in the store while the saved preference stayed false. The same expression also forced the switch off on every cross-family load, which discarded a preference the user had turned on.

It now calls resolvePreserveThinkingOnLoad, so the family default applies only when the installation has never answered; a stored preference and a toggle made this session both win. The regression test covers the away-and-back path and the toggle case.

@oobabooga

Copy link
Copy Markdown
Member

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 👍

Reviewed commit: 2743bd8af5

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

@oobabooga

Copy link
Copy Markdown
Member

@codex review

@oobabooga
oobabooga merged commit 6fa27e2 into unslothai:main Aug 19, 2026
39 of 45 checks passed
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 🎉

Reviewed commit: 78b138eb18

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

meefs pushed a commit to meefs/unsloth that referenced this pull request Oct 25, 2026
…ff the Qwen3.8 preserve_thinking default (unslothai#15170)

Fixes unslothai#15115

Before: on a Qwen3.8 GGUF, Studio always launched llama-server with `--chat-template-kwargs {"preserve_thinking": true}`. llama-server applies that kwarg after `--[no-]reasoning-preserve`, so passing `--no-reasoning-preserve` through `llama_extra_args` did nothing, and a user's `chat_template_override` written as `preserve_thinking|default(false)` was overruled. API clients that can't send `chat_template_kwargs` per request re-sent every past turn's reasoning.

After:
- The launch `preserve_thinking` value follows an explicit `--reasoning-preserve` / `--no-reasoning-preserve` in the extra args (last flag wins, as in llama.cpp's parser), else an inherited `LLAMA_ARG_REASONING_PRESERVE`.
- A `chat_template_override` gets the default its own text renders: Studio renders the override once in a sandboxed Jinja environment with `preserve_thinking` omitted and checks whether an earlier turn's reasoning survives. A copy of Qwen3.8's own template (`preserve_thinking is undefined or ...`) keeps the on default; a `|default(false)` template gets off; a template that does not render falls back to off.
- The Qwen3.8 default with its own GGUF template is unchanged (unslothai#9096).
- `_preserve_thinking_default` is updated too, so `/load`, `/status`, the Studio toggle and the `/v1/messages` replay path report the value the server actually runs with.

Testing:
- `TestThePreserveThinkingLaunchDefault` in `tests/test_launch_reasoning_flag.py` drives the real `load_model` with a faked `Popen`: 13 cases, 9 fail on the merge base and all pass here. Reverting the render step to a plain off default fails the two "override that keeps reasoning stays on" cases.
- Related suites (`test_launch_reasoning_flag`, `test_gemma4_chat_template_override`, `test_external_preserve_thinking`, `test_anthropic_messages`, `test_safetensors_capability_advertise`, `test_llama_thinking_budget`, `test_managed_engine_reasoning`, `test_openai_auto_switch`): 1738 passed; the 5 `test_openai_auto_switch` MCP cache failures are identical on the merge base.
- `test_launch_reasoning_flag.py` on Linux, macOS (Apple Silicon) and Windows: 97 passed on each.
- Live llama-server (b11869, CPU, tiny GGUF) `/apply-template` with a historical `reasoning_content` marker, using the reporter's template: the old launch argv keeps the marker even with `--no-reasoning-preserve`; the new argv drops it, and `--reasoning-preserve` brings it back. With Qwen3.8's own template as the override, the marker stays.
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