[GH-ISSUE #1526] A </think> the model quotes while thinking still ends the reasoning (output side of #537) #612

Closed
opened 2026-11-04 01:44:29 +07:00 by bsakaguchi · 4 comments
Owner

Originally created by @BlueKingMuch on GitHub (Oct 8, 2026).
Original GitHub issue: https://github.com/Niko1221/Strata/issues/1526

Version: v0.1.40.3 and v0.1.40.4 (serve/ is the same in both), Qwen3.8-Flash-Next IQ3_S

#537 reported a literal </think> both in the prompt and in the model's output. c16f31f8 fixed the prompt side: the tag in message text is now encoded as text. The output side is still open: in OutputParser.feed the reasoning ends at the first </think> in the model's output (i = self.buf.find(THINK_END)), even when the model only quotes the tag while thinking.

Seen in practice. In agent runs with Oh My Pi, Claude Code and Codex CLI against v0.1.40.3 on Strata's own serve/ code, this happened 7 times in 4 of 6 runs, in all three harnesses. The model quoted, for example, RecordingPrompt(tok, "</think>\n\n2", ...) or prompt.endswith("</think>\n\n") from serve/test_server.py, `</think>` in prose, or text = ("</think>\n\n... in a code block. Then:

  • the rest of the thinking came back as content (up to about 25,000 characters in one reply), with the real </think> as visible text;
  • once, an example call from ToolCallTerminators that the model quoted later in its thinking was run as a real write call (the agent noticed and deleted the file);
  • once, the model stopped mid-thought; the reply already had content, so the client took the leaked thinking as the final answer and the run ended.

Reproduction (parser only, from the repo root):

from serve.frontend import OutputParser
p = OutputParser(thinking=True)
evs = p.feed('The mock engine returns "</think>\\n\\n2" here.\n</think>\n\nThe answer.') + p.finish()
for kind in ("reasoning", "content"):
    print(kind, repr("".join(e.text for e in evs if e.kind == kind)))
# reasoning 'The mock engine returns "'
# content '\\n\\n2" here.\n</think>\n\nThe answer.'

Proposed fix. A </think> written right after a quote or backtick and followed by anything but a line break is reasoning text. The end of the thinking is followed by a line break, so it still ends the reasoning. Until the character after such a tag arrives, the tag is held like a partial one, so streamed and whole outputs agree; if the turn ends right there, it was the end (a forced tool call still opens there, and the #1053 retry is not triggered, as before). This keeps all 7 cases above in the reasoning. A tag that does not directly follow a quote mark or backtick (for example "\n</think>\n\n" in code, or one alone on a line in a code block) still ends the thinking: the rule stays narrow so that a real end is not taken for a quote.

Branch (one commit on v0.1.40.4, 6 new tests, the full suite passes): https://github.com/BlueKingMuch/Strata/tree/quoted-think-end

Originally created by @BlueKingMuch on GitHub (Oct 8, 2026). Original GitHub issue: https://github.com/Niko1221/Strata/issues/1526 **Version:** v0.1.40.3 and v0.1.40.4 (`serve/` is the same in both), Qwen3.8-Flash-Next IQ3_S #537 reported a literal `</think>` both in the prompt and in the model's output. c16f31f8 fixed the prompt side: the tag in message text is now encoded as text. The output side is still open: in `OutputParser.feed` the reasoning ends at the first `</think>` in the model's output (`i = self.buf.find(THINK_END)`), even when the model only quotes the tag while thinking. **Seen in practice.** In agent runs with Oh My Pi, Claude Code and Codex CLI against v0.1.40.3 on Strata's own `serve/` code, this happened 7 times in 4 of 6 runs, in all three harnesses. The model quoted, for example, `RecordingPrompt(tok, "</think>\n\n2", ...)` or `prompt.endswith("</think>\n\n")` from `serve/test_server.py`, `` `</think>` `` in prose, or `text = ("</think>\n\n...` in a code block. Then: - the rest of the thinking came back as `content` (up to about 25,000 characters in one reply), with the real `</think>` as visible text; - once, an example call from `ToolCallTerminators` that the model quoted later in its thinking was run as a real `write` call (the agent noticed and deleted the file); - once, the model stopped mid-thought; the reply already had content, so the client took the leaked thinking as the final answer and the run ended. **Reproduction** (parser only, from the repo root): ```python from serve.frontend import OutputParser p = OutputParser(thinking=True) evs = p.feed('The mock engine returns "</think>\\n\\n2" here.\n</think>\n\nThe answer.') + p.finish() for kind in ("reasoning", "content"): print(kind, repr("".join(e.text for e in evs if e.kind == kind))) # reasoning 'The mock engine returns "' # content '\\n\\n2" here.\n</think>\n\nThe answer.' ``` **Proposed fix.** A `</think>` written right after a quote or backtick and followed by anything but a line break is reasoning text. The end of the thinking is followed by a line break, so it still ends the reasoning. Until the character after such a tag arrives, the tag is held like a partial one, so streamed and whole outputs agree; if the turn ends right there, it was the end (a forced tool call still opens there, and the #1053 retry is not triggered, as before). This keeps all 7 cases above in the reasoning. A tag that does not directly follow a quote mark or backtick (for example `"\n</think>\n\n"` in code, or one alone on a line in a code block) still ends the thinking: the rule stays narrow so that a real end is not taken for a quote. Branch (one commit on v0.1.40.4, 6 new tests, the full suite passes): https://github.com/BlueKingMuch/Strata/tree/quoted-think-end
Author
Owner

@Niko1221 commented on GitHub (Oct 10, 2026):

Fixed in v0.1.42, with the author's commit from BlueKingMuch's quoted-think-end branch kept under their name: a written right after a quote or backtick and followed by anything but a line break is reasoning text, and the real end of the thinking still ends it. Until the character after such a tag arrives it is held like a partial tag, so streamed and whole outputs agree; a turn that ends on it counts it as the end, so a forced tool call still opens there. Six new tests, one at the HTTP level.

<!-- gh-comment-id:6099601350 --> @Niko1221 commented on GitHub (Oct 10, 2026): Fixed in v0.1.42, with the author's commit from BlueKingMuch's quoted-think-end branch kept under their name: a </think> written right after a quote or backtick and followed by anything but a line break is reasoning text, and the real end of the thinking still ends it. Until the character after such a tag arrives it is held like a partial tag, so streamed and whole outputs agree; a turn that ends on it counts it as the end, so a forced tool call still opens there. Six new tests, one at the HTTP level.
Author
Owner

@47Hunter47 commented on GitHub (Oct 12, 2026):

The rule you proposed is in v0.1.42 and it does keep the quoted cases in the reasoning, as the maintainer wrote. The other half of that family is still open, and it is the one I hit: the turn ends inside the thinking with no tag written at all, so there is nothing to quote.

Measured today on 0.1.43 (RTX 3090, IQ3_XXS, 250K, --kv int8), asking the model to show how its closing thinking tag looks: 4 runs, 2 stopped mid-thinking with the turn-end token and no answer (384 and 63 tokens in). That is #1814. My PR #1840 reports that end (log line, totals.ended_inside_thinking in /metrics, and ended_inside_thinking: true on the response) and can close the thinking and continue up to twice so the client gets an answer. Opt-in via literal_think_guard.

So your case is "something closes the thinking early" and mine is "nothing closes it", and both surface as a stop with no answer. #1886 builds on the recovery in #1840 and ties the parser's transitions to the real token identity, which is closer to a general fix than either of our narrow rules: your rule reads the character after the tag, mine acts on the end.

<!-- gh-comment-id:6121175042 --> @47Hunter47 commented on GitHub (Oct 12, 2026): The rule you proposed is in v0.1.42 and it does keep the quoted cases in the reasoning, as the maintainer wrote. The other half of that family is still open, and it is the one I hit: the turn ends inside the thinking with no tag written at all, so there is nothing to quote. Measured today on 0.1.43 (RTX 3090, IQ3_XXS, 250K, `--kv int8`), asking the model to show how its closing thinking tag looks: 4 runs, 2 stopped mid-thinking with the turn-end token and no answer (384 and 63 tokens in). That is #1814. My PR #1840 reports that end (log line, `totals.ended_inside_thinking` in `/metrics`, and `ended_inside_thinking: true` on the response) and can close the thinking and continue up to twice so the client gets an answer. Opt-in via `literal_think_guard`. So your case is "something closes the thinking early" and mine is "nothing closes it", and both surface as a stop with no answer. #1886 builds on the recovery in #1840 and ties the parser's transitions to the real token identity, which is closer to a general fix than either of our narrow rules: your rule reads the character after the tag, mine acts on the end.
Author
Owner

@Niko1221 commented on GitHub (Oct 13, 2026):

Thanks for the report. To keep the tracker current we are closing issues older than three days: 0.1.44 is out with a long list of fixes, and many older reports are covered by it or by 0.1.43.1.

If this still happens on 0.1.44, please leave a comment here with your engine log (and the version line it prints), and we will reopen it. A new issue that links this one works too.

<!-- gh-comment-id:6156123953 --> @Niko1221 commented on GitHub (Oct 13, 2026): Thanks for the report. To keep the tracker current we are closing issues older than three days: [0.1.44](https://github.com/Niko1221/Strata/releases/tag/v0.1.44) is out with a long list of fixes, and many older reports are covered by it or by 0.1.43.1. If this still happens on 0.1.44, please leave a comment here with your engine log (and the version line it prints), and we will reopen it. A new issue that links this one works too.
Author
Owner

@47Hunter47 commented on GitHub (Oct 14, 2026):

The other half of this family — a turn that ends with no tag written at all — is still reproducible on 0.1.44 as it ships. I posted the log from a stock 0.1.44 run on #1814 and #1178 (the minimal input from #1178 was 8 of 8 empty with finish_reason: stop).

The rule you proposed is in 0.1.42 and it holds — a tag the model quotes while thinking stays reasoning. What is left is the end with nothing to quote, and that is what #1840's opt-in guard reports (ended_inside_thinking, log line, /metrics) and continues.

<!-- gh-comment-id:6160396731 --> @47Hunter47 commented on GitHub (Oct 14, 2026): The other half of this family — a turn that ends with no tag written at all — is still reproducible on 0.1.44 as it ships. I posted the log from a stock 0.1.44 run on #1814 and #1178 (the minimal input from #1178 was 8 of 8 empty with `finish_reason: stop`). The rule you proposed is in 0.1.42 and it holds — a tag the model quotes while thinking stays reasoning. What is left is the end with nothing to quote, and that is what #1840's opt-in guard reports (`ended_inside_thinking`, log line, `/metrics`) and continues.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Niko1221/Strata#612
No description provided.