mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-03 19:03:30 +07:00
[GH-ISSUE #4077] [Engine] A bare closing think tag inside the model's own reasoning ends the thinking; the rest of it streams out as the answer #1771
Labels
No labels
needs-format
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
Niko1221/Strata#1771
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @ackalker on GitHub (Oct 25, 2026).
Original GitHub issue: https://github.com/Niko1221/Strata/issues/4077
Area
[Engine] (speed, kernels, models, the server and API)
Engine (
serve/), run from source:serve/server.pystarted aspython serve/server.py --engine strata --config strata-iq3_s.json.Desktop app, Terminal or source?
Source (START-HERE.bat, setup.sh or a build)
Reproduction status
Reproduced locally - deterministic at parser level (the attached script
feeds
serve.frontend.OutputParserin 7-character deltas, like a real server feed; no model, noGPU). The symptom was also seen end to end in an agent session on 2026-10-25: the second half of a
model's reasoning appeared as the visible answer.
What happened
A closing think tag that the model writes inside its own reasoning ends the thinking block, and
everything after it is streamed out as ordinary answer
content. Half a chain of thought appears inthe answer, with the tag itself visible in the middle of it.
#537handled the case where the model quotes the tag -_quoted_think_end()(
serve/frontend.py:1093) recognises the form where the closer sits directly after a quote or abacktick and is followed by non-newline text, and keeps it as reasoning
(
serve/frontend.py:1349-1352). Every other position ends the thinking(
serve/frontend.py:1353-1357): the state switches tocontentand the rest of the reasoning isdelivered as the answer. In particular a closer at the start of a line - which is what a model
writes when it is reasoning about the chat format itself - always ends it.
This is not an unusual thing for these models to reason about: the request's own system text shows
them the call format, tags included (
serve/chat_template.jinja:83), andserve/chat_template.jinja:119replays earlier turns' reasoning with the tags in place.It also feeds itself, which is why one bad turn turns into a run of bad turns: the leaked text comes
back as assistant content, and
mark_think_literals()deliberately leaves call markup inside anassistant message exactly as written (
serve/frontend.py:362and:366; the reasoning for that isthe #2026 comment at
serve/frontend.py:266-273). So if a leak carries an opening call tag, thenext request hands the model the real call token in an assistant turn, and the next turn drifts
further. The input side is already masked for reasoning (
repro.pycase 5 shows a literal closerinside
reasoning_contentbeing replaced by its mark), so this is about the output side and aboutwhat the leak then carries.
Two facts that bear on a fix, both reproduced:
repro.pycase 1) - that is #537working, and the case that does not reproduce.
content, a later closer is emitted inside the answer rather than changing state. So "the closerthat ends the thinking" is a single decision made at the first bare occurrence.
Expected
Either do not end the reasoning at a bare closer that is followed by more reasoning-shaped text
(the model was quoting the tag, as it does for #537's quoted form, just without the quote mark), or
mask/document it the way the input side does, so a model that talks about its own format does not
leak its reasoning into the answer.
Smallest steps or command that reproduce it
repro.py(attached below) runs every case against a checkout; from the repository root:Case 1 is the #537 control (stays reasoning, does not reproduce). Case 2 is this problem:
reasoning, a bare closer at the start of a line, more reasoning text, then the answer. The script
prints the reasoning text, the answer text and the counters for each case. In the script the markup
strings are built at runtime from
chr(60)/chr(62)and are never written literally in the file,so reading the script cannot inject markup into a session or an editor buffer.
In prose, case 2's input is: open tag,
first part of the reasoning, newline, a bare closer,second part of the reasoning leaks into the answer, another closer, blank line,the answer.Observed split: reasoning stops after the first part; the answer is the second part, the visible
closer, and then the answer text.
Strata version
v0.2.4.2-6-g7dd5cf18(source checkout,git describe), engine 0.1.49.1.Re-verified against
mainas fetched on 2026-10-25 (fa663fab, 136 commits newer):git diff 7dd5cf18 fa663fab -- serve/is empty and case 2 reproduces identically there.Graphics card, memory and system
RTX 5080 16 GB · 60 GB RAM · Linux (CachyOS, kernel 7.3.0-5), Python 3.13. The parser reproduction
needs no GPU, no model file and no server.
Model, size and settings
Where it was seen end to end: Qwen3.8-Flash-Next GGUF IQ3_XXS and IQ3_S, 131072 context, behind
llama-swap with
metadata.reasoning = {format: qwen3.8, levels: [low, medium, xhigh]}, reasoningreplayed (
preserve_thinking: true, which is also the template's own default,serve/chat_template.jinja:119). The parser case needs none of that:thinking=Trueis enough.Logs
Nothing is logged when the thinking ends early - the counters (
unread,rescued,refused) allstay 0, and there is no
[strata]line for it.Related issues
spelling of the same tag and it is not covered.
a different layer.
Attached: repro.py (self-contained; the markup strings are built at runtime, never literal in the file)
@github-actions[bot] commented on GitHub (Oct 25, 2026):
Thanks for the issue. To keep the tracker readable, every item needs an area prefix in the title and the parts of the issue form filled in. This one is missing:
Edit the issue (title and description) and this note goes away on its own. If it is still missing parts in 5 days it will be closed, which is not a rejection: fix it and comment
/reopen.Details: CONTRIBUTING.md
@Tsury commented on GitHub (Oct 25, 2026):
Reproduced on hardware, v0.2.6 build (engine 0.1.51; downstream patches do not touch reasoning parsing), RTX 5090 Laptop GPU, Qwen3.8 Flash-Next IQ3_S, thinking on at LOW effort.
The prompt asked for one
write_filecall whose content isreasoning sample:\n</think>\nanswer sample. While thinking, the model quoted that text, so a bare</think>line appeared in the reasoning. Reasoning ended there (127–163 characters). The rest of the reasoning, the model's real closing tag and its complete, correct<tool_call>block all arrived as assistant content, so the client got no tool call. Same result on Chat, Chat streaming and streaming Responses (3 of 3; finishstop/completed).@github-actions[bot] commented on GitHub (Oct 28, 2026):
Thanks, this follows the format now.
@ackalker commented on GitHub (Oct 28, 2026):
Independent parser-level check on the current release, plus where a fix would have to go. My own runs only: no model, no GPU, no live server. Tags below are written as
«think»,«/think»and so on; the script in #4078's comment builds them at runtime fromchr(60)/chr(62)and never contains them literally.Revision and environment.
mainat5e8a4cca(v0.2.7, engine 0.1.52), checkout with no local modifications. Linux (CachyOS, kernel 7.3.0-5), Python 3.14.8, 60 GB RAM.Passed - the leak reproduces on released v0.2.7. Reasoning, a newline, a bare
«/think»at the start of a line, more reasoning text: the reasoning events stop at the closer and everything after it arrives ascontent, the closer itself visible inside that content. Countersunread,rescuedandrefusedstay 0 and no[strata]line is printed, exactly as the report says. The#537control still behaves: a closer quoted after a backtick, followed by more text, stays inreasoning.Passed - nothing has touched this path since the report. No commit in the repository mentions this issue, and
serve/frontend.pychanged infa663fab..5e8a4ccaonly infd8d37e9(#3972 namespaced tool spellings),11237f83(#3395 tool-result order) and805ebe17(#3796 undeclared-name wording and the collapsedmcp__a__balias)._quoted_think_end()and the state switch at the bare closer are unchanged.Passed - PR #4132 does not fix this issue. I ran the same case against that branch (
git fetch origin pull/4132/head,831bb12b): the reasoning still ends at the bare closer and the rest still arrives ascontent. That matches the note in the PR's own Limits section.Not run. No model and no GPU, so no end-to-end confirmation from me here; the hardware case is already in a comment above (RTX 5090 Laptop GPU, Qwen3.8 Flash-Next IQ3_S, 3 of 3 routes).
Two things that could shape a fix, both seen in the code rather than measured, so treat them as unconfirmed static analysis:
content, a later closer in the same turn is emitted inside the answer rather than changing state. So a rule can look at what follows the closer without any lookahead budget across turns.reasoning_content(mark_think_literals()), but not call markup inside an assistant message (serve/frontend.pyaround line 366, the #2026 note). A leak that carries an opener therefore comes back in the next request as a real opener, which is the self-feeding part of the report.@shi1090 commented on GitHub (Oct 29, 2026):
Another shape of the same leak: the quoted closer is inside inline code, not at the start of a line. A fix that only covers the line-start case would leave this one.
Environment.
mainat46c152a1(v0.2.7, engine 0.1.52), Linux source checkout, no local modifications.python serve/server.py --engine strata --config strata-iq3_s.json --port 8081 --parallel 1. Qwen3.8-Flash-Next IQ3_S on one RTX 4090, thinking on withthinking.budget_tokens16384, Anthropic endpoint, OpenCode client.Seen end to end. The turn's task was to investigate thought/output mixing. The reasoning contained the inline-code example
(`<think>...</think>`). The stored message cuts the reasoning at that inner closer and streams the rest as content:…the streaming parse for reasoning (`<think>…`), the DSML / dsml.py, split.py, …and later the real</think>as visible text.The server log for the same turn shows the state change:
thinking: 62 of budget 16384thenanswering: 145 ….Parser-only reproduction.
Output:
_quoted_think_end()only checks the character immediately before the closer. Here that character is.(the ellipsis in<think>...), so the closer ends the thinking even though it is inside inline code. Counting the fence/inline-code state up to the closer (the parser already tracksfence,ticksandlinefor<tool_call>) would cover this and the fenced-code shape in #2794.Not tested. Release binaries, other models, or non-Anthropic dialects. The parser reproduction is deterministic; the transcript and log are from one turn on the machine above. I can share the stored message JSON if that helps.
@Niko1221 commented on GitHub (Oct 29, 2026):
Partly fixed on our side; the fix ships in the next update (0.2.8). When the reasoning has ended at a closing think tag and another one stands at the start of a line later in the answer, the second is dropped as a stray and the answer's code tracking starts over, so a call after it is no longer mistaken for a quote by a fence the reasoning left open (that is how the call was lost).
Not fixed: the reasoning between the two tags has already been sent as answer text when the second tag shows up, and a stream cannot take it back. A client sees some reasoning as answer text, but no call is lost.
@ackalker commented on GitHub (Oct 29, 2026):
Thanks for looking into this.
@Niko1221 commented on GitHub (Nov 6, 2026):
0.2.11 fixes part of this: a stray closing think tag, damaged arguments and a missing
</function>no longer cost the call. Reasoning text between the tags can still end thinking early, so I'm keeping this open for that part.