Repository navigation
Keep thinking tags as content after a prompt that closes the thought - #1525
Merged
Merged
Conversation
This was referenced Oct 28, 2026
Closed
StepFun3.5-Flash always ends its prompt with `<think>\n`; with thinking off llamadart closes that thought, and the parse read the rewritten prompt as a closed one, turning the reasoning and `</think>` into content. llama.cpp 620d2225 keeps that thought open and parses it. The DeepSeek V3, Hermes and Qwen3-Coder XML handlers now report `LlamaChatTemplateResult.thinkingForcedClosed` from the template's render, before closing an open thought, and the stream and final parse use it instead of inspecting the prompt.
The template's closed thought now travels as an internal mark on the render result (`withThinkingForcedClosed` / `thinkingForcedClosedOf` in thinking_utils), not as a public `LlamaChatTemplateResult` field. Behavior is unchanged.
# Conflicts: # lib/src/core/template/chat_format_registry.dart # lib/src/core/template/handlers/hermes_handler.dart # lib/src/core/template/handlers/qwen3_coder_xml_handler.dart # lib/src/core/template/xml_tool_call_format.dart
Contributor
|
Chat app preview removed for |
12 of 13 tasks
This was referenced Nov 9, 2026
Closed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
<think></think>. llama.cpp620d2225then parses the reply as content and tool calls, thinking tags included. llamadart extracted<think>blocks as reasoning and, with thinking off, dropped them. Now the DeepSeek V3, Hermes and Qwen3-Coder XML parse and stream keep them in the content.enableThinkingor llamadart's rewritten prompt: the DeepSeek V3, Hermes and Qwen3-Coder XML handlers mark their result (internalwithThinkingForcedClosed/thinkingForcedClosedOfinthinking_utils.dart, anExpandolikemarkPromptExcludedFromPenalties) when the render ends with an empty start/end pair (isThinkingForcedClosed), before they close a thought the template left open. So templates that do not close the thought keep parsing a leading thought, as upstream does: Bielik, Reka, Spark's bare</think>, and StepFun3.5-Flash, whose template always ends<think>\n(llamadart appends</think>with thinking off; upstream keeps it open and parses the reasoning). Gated by a new registry traitclosedThoughtKeepsTagsAsContent(deepseekV3, hermes, qwen3CoderXml); a forced-open thought wins.ChatTemplateEngine.parsegainsthinkingForcedClosed(internal engine; not exported).Production-readiness scope
enableThinking: false(or a thinking-off kwarg) on these models, a<think>block the model still writes appears inchunk.text/ message content instead of vanishing.template-engine-internals.md).Plan\n</think>\n\nSunny.: a chunked stream emits the thought as content before the end tag (same on main; final parse and one-chunk stream giveSunny.). Forced-open verbatim parity is #1524; Cohere follow-ups are #1526. Remaining divergences are recorded on #750.Completeness checklist
template-engine-internals.md,chat-template-and-parsing.md,skills/llamadart-chat-streaming/SKILL.md, both changelogs. README/examples/support matrix: N/A.)PR type guidance
<think>whatever the prompt rendered; upstream's PEG parser has no reasoning rule after a closed thought. Tests: new upstream oracle fixturetest/fixtures/closed_thought_upstream.json(DeepSeek V3.1, Qwen3-4B, QwQ, Qwen3.5; 8 outputs each,enable_thinking = false) through parse, tool-free parse and whole/bytewise stream with tools on/off and a thinking-on kwarg; the mark survives required-tool and response-schema grammar and token counting; StepFun3.5-Flash (vendored template,open_thought_templates, 5 outputs with and without tools) keeps its reasoning and tool calls in parse and stream as upstream does; a registry-wide test that exactly the trait formats change; forced-open precedence in parse and stream; an unmarked result keeps reasoning. Platforms: all (Dart parse).Test Plan
dart run tool/prepare_workspace.dartdart format --output=none --set-exit-if-changed .dart analyzedart test -p vm -j 1 --exclude-tags local-only(+9330 ~5 at merged headd4aeac801, all passed); Chrometest/unit/core/template+ stream parser tests +1119 atd4aeac801dart test -p chrome --exclude-tags local-only(CI)./tool/testing/run_template_parity_suites.sh(all suites passed);dart test -p vm test/unit/tooling/package_skills_test.dart; oracle, sweep, render matrix and mutation runs below.Evidence (oracle built from llama.cpp
620d2225):22a0c4518)f51c9eb0f14f1e0bf2common_chat_sessionwhole + bytewise), 127,332 cases over 94 templates, thinking on/off, kwarg, tool choices; stream whole, bytewise, 3-char, every 2-chunk splitSPLIT2=1), 64,298 casesdeepseekV3210 -> 0,qwen3CoderXml1000 -> 580,hermes5194 -> 4354 (bytewise; rest pre-existing, e.g. thinking-off stream drops reasoning other formats parse)Mutants: engine ignores
thinkingForcedClosed, ignores forced-open precedence; stream does not keep tags as content, detects fromenableThinking, ignores the start tag, final parse not passed the flag; each handler ignores the flag; XML extraction always skipped; each registry trait off (hermes, deepseekV3, qwen3CoderXml). 13 of 13 killed. Two equivalent mutants (trait gating in the engine, the partial-parse argument) showed dead code, which was removed.Mutants at
14f1e0bf2(StepFun fix, internal mark): Qwen3-Coder XML marks from the rewritten prompt; stream sniffs the prompt again; stream ignores the mark; stream ignores forced-open precedence; each of the three handlers does not mark; the helper never marks; the renderer, required-tool and response-schema copies drop the mark. 11 of 14 killed. The 3 survivors drop the mark in copies only Ministral, generic/content-only and the content-only format switch reach, whose handlers never mark (equivalent). Oracle and sweep numbers above are from38847aa2d;14f1e0bf2reproduces them row for row on the StepFun, Qwen3.5, Qwen3-4B, DeepSeek V3.1 and Bielik subset (6,200 oracle rows identical; StepFun's 1,240 identical to base).Merged head
d4aeac801vs mainc91b35202(same auditor harness, both trees run fresh):c91b35202d4aeac801SPLIT2=1), 64,298 casesf89e8e982Matrix Evidence
static-format-analyzeroot-vmd4aeac801root-chromecoverage-libstructured-output-adversarial620d2225high-risk-exact-head-independent-qa/opt/UnitySrc/personal/llama/llamadart-evidence/pr-1525/audit/r2/evidence-1525-d4aeac8.jsondocs-sitegguf-chat-features-smokeReview Notes
c21f1c7ef(merge of main0615470fd).f51c9eb0fwas BLOCKED on a StepFun P2 (fixed in38847aa2d, internal mark in14f1e0bf2); delta re-audit CLEAR atd4aeac801(llamadart-evidence/pr-1525/audit/r2/evidence-1525-d4aeac8.json); main mergec21f1c7efdelta-checked (audit/r2/delta-c21f1c7ef.md). Follow-ups: Reasoning parity follow-ups from #1524/#1525 audit: mutants X2/X7, Ling <think> in args, partial-tag drop #1531, Streaming: small chunks emit an open thought as content before </think> arrives #1532, ci_workflow_selection_test 'Laya Tetris deploys only tested main commits' times out at 30 s on Windows CI #1538.High-risk regression review
620d2225for the affected templates.c91b35202is merged in with--no-ff(no rebase). Conflicts inchat_format_registry.dart,hermes_handler.dart_parse,qwen3_coder_xml_handler.dartparseWithToolsandxml_tool_call_format.dartresolved as the auditor's local mergef89e8e982(both traits kept; the verbatim forced-open branch is gated onextractsThought), plus the internal closed-thought mark.