Skip to content

Let a template's own thinking kwarg win over the value enableThinking sets - #1513

Merged
leehack merged 6 commits into
mainfrom
fix/750-template-thinking-kwargs
Oct 28, 2026
Merged

leehack merged 6 commits into
mainfrom
fix/750-template-thinking-kwargs

Conversation

@leehack

@leehack leehack commented Oct 28, 2026 •

Copy link
Copy Markdown
Owner

Summary

Part of #750 (the #1494 note that MiniMax-M3 and Hy3 map enableThinking to their own template settings).

Several handlers turn enableThinking into a template's own thinking switch: reasoning and skip_thinking for Cohere2 MoE (and Command R7B), reasoning_effort for Hy3, thinking_mode for MiniMax M3 and the other direct-Jinja formats. They put that value in the render context, which overrides chatTemplateKwargs, so a caller's own setting was silently replaced: {'reasoning_effort': 'low'} rendered Hy3 at high, {'reasoning_effort': 'none'} left Cohere2 MoE thinking, and {'thinking_mode': 'disabled'} left MiniMax M3 thinking. llama-server renders what the kwarg says.

renderTemplate now takes defaults that kwargs override, and those handlers pass the derived settings there. Cohere2 MoE leaves reasoning undefined when the caller sets reasoning_effort, since its template reads reasoning_effort only then. The mapping itself stays: enableThinking: false still turns thinking off on these templates, which llama-server's enable_thinking does not (they never read it); that divergence is recorded on #750 as intentional.

Production-readiness scope

  • User-facing scope: a template's own thinking kwarg renders as in llama-server.
  • Supported platforms/paths: template rendering, every backend.
  • Unsupported or intentionally unavailable paths: with enableThinking: false and a kwarg that opens the thought (for example Hy3 reasoning_effort: high), the kwarg reaches the template but llamadart still ends the thought the prompt leaves open, as documented on LlamaEngine.create.
  • Out of scope / follow-ups: None.

Completeness checklist

  • Declared scope is fully implemented, or explicitly reduced above.
  • Unsupported platform/option combinations fail loudly with actionable diagnostics or are clearly documented as unavailable.
  • Public API docs, README/website docs, examples, support matrices, and changelog entries are updated where relevant. (LlamaEngine.create dartdoc, llamadart-chat-streaming skill, changelog in both files.)
  • Regression coverage covers the original issue plus key negative/version-skew paths where relevant.
  • Public capability changes update the validation coverage registry with a pack or a reasoned, issue-linked exemption; inventory checks pass (or N/A with scope). N/A: no capability change.
  • Security/privacy review completed: no secrets, bearer tokens, signed URLs, or raw secret-bearing paths leak through logs, cache keys, metadata, errors, or snapshots.
  • Follow-up work that is useful but not required for this PR is tracked in GitHub Issues, or explicitly marked "None" above.

PR type guidance

  • Bugfix PR: root cause above. Regression: test/unit/core/template/thinking_template_kwargs_parity_test.dart renders 10 cases (Cohere2 MoE, Hy3, MiniMax M3, Kimi K3 as a control) against full prompts from llama.cpp 620d2225 (test/fixtures/thinking_template_kwargs_upstream.json), including three that pin enableThinking: false to upstream's render with the template's own off setting. Six fail on main.

Test Plan

  • dart run tool/prepare_workspace.dart
  • dart format --output=none --set-exit-if-changed .
  • dart analyze
  • dart test -p vm -j 1 --exclude-tags local-only (8971 passed, 123 skipped, at 34b66c3a0)
  • dart test -p chrome --exclude-tags local-only (3970 passed, 1 skipped)
  • Other targeted/local-only validation: render matrix and mutation check below.

Matrix Evidence

Matrix row Scope covered Platform / model / backend Result Evidence / notes
static-format-analyze format, analyze, platform boundaries macOS, Flutter 3.47.1 PASS
root-vm full VM suite macOS arm64 PASS
root-chrome full Chrome suite Chrome PASS
structured-output-adversarial input rendering with thinking kwargs, thinking on and off, history with an earlier thought, tools template-level PASS full-prompt parity with llama.cpp 620d2225; render matrix below
high-risk-exact-head-independent-qa independent blocking review of exact head fresh auditor session, exact head c0ca74a PASS CLEAR: 0 P1/P2 at audited head 34b66c3; later heads add only main merges; 10 fixtures byte-exact vs 620d2225, 102,648-render sweep changes only Cohere2MoE/Hy3 kwarg cases; P3s tracked as follow-up; evidence ../llamadart-evidence/pr-1513/audit/evidence-1513-5312835-accepted.json
release-metadata-verification N/A Not a release PR
litert-lm-json-schema N/A No LiteRT-LM change

Render matrix (#1494 audit harness, 94 templates, 15,792 renders, base 943d2acd5 vs head; its only kwarg is reasoning_effort: high): 51 renders change, prompt only, all enableThinking: false with that kwarg: Hy3 (30) now renders reasoning_effort:high in its system block, and Cohere2 MoE (21) opens the thought from the kwarg and llamadart ends it (<|END_THINKING|>\n). Every other render, and every enableThinking: true render, is unchanged; errors 264 on both sides.

Mutation check (test/unit/core/template, test/integration/core/template): 7 of 7 killed — kwargs merged before defaults; Cohere always defaulting reasoning; Hy3 reasoning_effort or thinking_mode back in the context; either default dropped; Cohere skip_thinking default dropped.

Review Notes

  • Independent review status: CLEAR at exact head c0ca74a by a fresh auditor session (0 P1, 0 P2).
  • Evidence (local): llamadart-evidence/pr-1513/ holds the oracle source, render matrix outputs and diff, and the mutation script.
  • CI status / head SHA: 34b66c3a0, CI pending.
  • Overlaps #1509 in command_r7b_handler.dart, the changelogs and the vendored-template README in different hunks; whichever lands second rebases.

High-risk regression review

  • Classification: high-risk (backendRuntime, structuredOutput)
  • Implementation task: DeepSeek V3.1 and Qwen thinking parity gaps against llama.cpp (thinking flag, escapes, repeated <think>) #750 per-family parity lane (0.17.0 plan #922)
  • Independent blocking QA task: fresh auditor session, CLEAR, 0 known PR-caused P1, 0 unresolved threads
  • Exact head / current base: c0ca74a / 3210277 (merge-tree clean)
  • Production-branch deletion, bypass, or miswire proof: mutation check above
  • Affected-family real-model/artifact evidence: none; rendering only, checked against upstream renders of the vendored templates
  • Explicit unavailable-family or other N/A evidence: Cohere2 MoE, Hy3 and MiniMax M3 weights unavailable; prompt rendering needs no model
  • Known PR-caused P1 regressions: 0
  • Unresolved review threads: 0

@leehack
leehack marked this pull request as ready for review October 28, 2026 07:40
@leehack
leehack merged commit 22a0c45 into main Oct 28, 2026
1 check failed
@leehack
leehack deleted the fix/750-template-thinking-kwargs branch October 28, 2026 07:40
@github-actions

Copy link
Copy Markdown
Contributor

Chat app preview removed for leehack/llamadart-chat-pr-1513.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant