Skip to content

[Bug] Studio forces preserve_thinking=true at llama-server launch, which overrides a user-supplied chat template and makes --no-reasoning-preserve a no-op #15115

Closed

Description

@oh-codes

Environment

  • Unsloth Studio 2026.10.8, Windows 11, desktop app (unsloth studio --api-only -H 127.0.0.1 -p 8888)
  • llama-server b11798-ec0da70e9 (bundled, ~/.unsloth/llama.cpp/build/bin/Release/llama-server.exe)
  • Model: unsloth/Qwen3.8-27B-GGUF:UD-Q5_K_S, custom chat template set through
    app_settings.openai_api_auto_switch_overrides["unsloth/Qwen3.8-27B-GGUF:UD-Q5_K_S"].chat_template_override
  • Client: opencode 2.1.4 against http://127.0.0.1:8888/v1 (an ordinary API client, not the Studio chat UI)

Summary

For any model whose identifier matches qwen3.8, Studio appends --chat-template-kwargs {"preserve_thinking": true} to the llama-server launch line (core/inference/llama_cpp.py:3182, :3369, :31922-31924). Because that value is part of the launch default template kwargs, llama-server defines preserve_thinking for every request on that port. Consequences:

  1. A user-supplied chat_template_override that decides for itself — e.g. {%- if preserve_thinking|default(false) or loop.index0 > ns.last_query_index %} — can never take its own default, because the variable is always defined. The template is silently neutralised.
  2. --no-reasoning-preserve (the documented llama.cpp knob, and the one the server itself tells you to use: "disable via --no-reasoning-preserve") has no effect. Passing it through llama_extra_args changes nothing.
  3. There is no Studio setting to turn the launch default off: preserve_thinking_default is derived only from the model-name regex, and the chat-side preserveThinking preference is forwarded per request by the Studio frontend, so it never reaches API clients.

Net effect for agent clients: every request re-sends the reasoning of all previous turns. In a coding agent this grew the prompt from 41k → 79k → 88k tokens within one session and forced auto-compaction (measured: a 409 s compaction pass with cache.read=0).

I understand this default is deliberate — #9096 follows Qwen's documented default for Qwen3.8 — so this is not a request to change the default. It is a request to make it overridable and to stop it from silently beating the user's own template.

Reproduction

  1. Set a custom template on a qwen3.8 model containing the line above (preserve_thinking|default(false)), and reload the model.
  2. Confirm the launch line carries both --chat-template-kwargs {"preserve_thinking": true} and (optionally) --no-reasoning-preserve; the server logs chat template supports preserving reasoning, it is enabled by default.
  3. Render a prompt with a historical assistant turn carrying reasoning_content:
POST http://127.0.0.1:<port>/apply-template
{"messages": [
  {"role": "user", "content": "q1"},
  {"role": "assistant", "content": "a1", "reasoning_content": "MARKER"},
  {"role": "user", "content": "q2"}
]}

body                                                 -> MARKER present: True  (len 142)
+ chat_template_kwargs {"preserve_thinking": false}  -> MARKER present: False (len 117)
+ chat_template_kwargs {"preserve_reasoning": false} -> MARKER present: True  (len 142, ignored)
+ chat_template_kwargs {"preserve_reasoning": "false"} -> MARKER present: True (len 142, ignored)

The template itself is correct: rendered offline with the sandboxed Jinja environment, the same messages produce no <think> block with no kwarg, and block(s) with preserve_thinking=true.

--no-reasoning-preserve writes preserve_reasoning (common/arg.cpp:3793-3805 → caps_apply_preserve_reasoning, common/chat.cpp:993), but common_chat_template_direct_apply_impl then calls jinja::global_from_json(ctx, inp) after that, which re-applies preserve_thinking: true from --chat-template-kwargs (common/chat.cpp:993-1009). So a launch-time chat_template_kwargs entry always wins over --no-reasoning-preserve.

Suggested fix (any one of these)

  • Prefer the user's template: when chat_template_override is set by the user, do not emit preserve_thinking in --chat-template-kwargs, and let the template decide its own default.
  • Or expose a per-model preserve_thinking key in the launch overrides (openai_api_auto_switch_overrides, next to custom_context_length / reasoning_budget), keeping the Qwen3.8 default as the initial value.
  • Or make the chat-surface preserveThinking preference also drive the launch default for that model, instead of being a per-request value only.

Workaround (for anyone hitting this now)

Every API client must send the override per request:

// opencode.json, per model
"body": { "chat_template_kwargs": { "preserve_thinking": false } }

chat_template_kwargs is honoured on the chat-completions routes (_normalize_chat_reasoning_controls, routes/inference.py:32444), so this reaches llama-server — verified above. Clients that cannot send extra body fields are stuck with the default.

Activity

  1. debojyoti-dev commented on Oct 24, 2026

    @debojyoti-dev
    Contributor

    I'm working on this. Plan: honour --reasoning-preserve / --no-reasoning-preserve (and LLAMA_ARG_REASONING_PRESERVE) when building the launch preserve_thinking kwarg, and stop forcing the Qwen3.8 default onto a chat_template_override so it falls back to the off default.

  2. danielhanchen commented on Oct 25, 2026

    @danielhanchen
    Member

    Fixed! Studio's launch-time preserve_thinking value now follows --no-reasoning-preserve / --reasoning-preserve in your extra args (or LLAMA_ARG_REASONING_PRESERVE), and a custom chat template gets the default its own text sets, so your preserve_thinking|default(false) template no longer replays old reasoning to API clients. Fixed in #15170.
    To update: Unsloth Desktop will have an update banner. For Studio, use unsloth studio update. For Docker, use docker exec <container> unsloth-studio-update. Reopen if it still happens.

  3. added a commit that references this issue on Oct 25, 2026
    808515e
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions