[GH-ISSUE #1053] A reply that ends inside <think> (no </think>) comes back empty with finish_reason: "stop", and the agent stops — close the thinking and continue once #448

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

Originally created by @davidsheridan77-dot on GitHub (Oct 6, 2026).
Original GitHub issue: https://github.com/Niko1221/Strata/issues/1053

Summary

With thinking on, Qwen3.8-Flash-Next sometimes writes one sentence of reasoning and then <|im_end|>, without
closing </think> and without a tool call
. OutputParser is still in the reasoning state, so the whole reply is
reasoning_content, content is empty and finish_reason is stop. An agent harness sees an empty turn right
after a tool result and stops (ours, OpenClaw, then runs a tools-off "finalization" pass, so the model can only
reply that it cannot do the edit).

This is the same family as #804 and #843, but a different shape: there is no <tool_call> inside the thinking
(so #970 / the rcall state don't catch it), and no earlier empty turns in the history (fresh session).

Strata already has the machinery for this: the #123 thinking-budget wrap-up closes the thinking and continues from
the held prefix. Doing the same once when the model stops inside its thinking fixes it here: 20/20 vs ~15% failures.

Environment

GPU      AMD RX 9060 XT 16 GB (gfx1200), PCIe 3.0
CPU/RAM  Ryzen 5 5500, 64 GB DDR4
OS       Ubuntu 24.04, ROCm (system /opt/rocm), HIP engine built by setup
Strata   v0.1.39 (6f32ec0)
Model    Qwen3.8-Flash-Next GSQ-RCO Q2_0, --kv int8, --spec 4 --spec-min-p 0.5, MTP, 32K and 64K context
Client   OpenClaw agent, OpenAI Chat Completions, streaming, reasoning_effort "low", 16 tools

What the model generated

Task: "One of the files in configs/ has debug turned on. Turn it off, then create changelog.md with one line saying
which file you changed." The agent globs, greps (finds b.conf: debug = true), reads b.conf. The next reply is
13 tokens. STRATA_DEBUG=1 (set on the server process — in the config's "env" block it only reaches the
engine child, so nothing is printed) shows, identical in all 3 failing runs:

[strata] done: 13 tokens in 2 s (50.5 tok/s) (stop, cancel=False), expert cache 90.5% hit ...
[strata] raw: 'I need to investigate further. Let me check the details.<|im_end|>'

OutputParser(thinking=True).feed(...) on that text gives only a reasoning event — no content, no call.

Frequency (same task, fresh session per run)

Run Engine / server Result
A 0.1.39, stock server 9/10 pass, 1 empty-stop turn
B 0.1.39, stock server, STRATA_DEBUG=1 17/20 pass, 3 empty-stop turns (raw text above)
C 0.1.39 + the patch below 20/20 pass; the patch fired 2x, 0 empty turns

In run C, after the inserted </think> the model wrote the correct call both times (tool name and path shortened):

[strata] raw: 'I need to investigate further. Let me check the details.<|im_end|>\n</think>\n\n<tool_call>\n<function=edit_file>\n<parameter=file_path>\n.../configs/b.conf\n</parameter>\n<parameter=old_string>\ndebug = true\n</parameter>\n<parameter=new_string>\ndebug = false\n</parameter>\n</function>\n</tool_call><|im_end|>'

(The <|im_end|> before </think> is only in raw_ids; the continuation prompt is prompt + seg + close, without
the stop token.)

A full 24-task agent ladder on the patched server: 24/24, decode 45.0 tok/s (44.7 unpatched) — no regressions seen.
python -m unittest serve.test_server serve.test_responses: same result as unpatched (1 pre-existing error,
test_json_schema_text_format, also without the patch).

Proposed change

On a stop token while parser.state == "reasoning" (and nothing held back), append "\n</think>\n\n" and continue
once, the same way the #123 budget wrap-up does. Opt-out: STRATA_STOP_IN_THINKING=0. Once per reply, so a model
that stops again after the close ends normally (its text is then content).

Against v0.1.39; on current main the stop-token branch in Service.run is unchanged, so it should port directly
(there it would also want to skip the rcall state).

--- a/serve/server.py
+++ b/serve/server.py
@@ -76,6 +76,9 @@
 REASONING_WRAP_UP = "\n\nI have thought about this long enough; time to give my answer.\n</think>\n\n"
+# A reply that stops while still thinking (no </think>, so no answer and no tool call) is closed and continued
+# once, the way #123 closes a thinking budget.  STRATA_STOP_IN_THINKING=0 turns it off.
+STOP_IN_THINKING_CLOSE = "\n</think>\n\n"
@@ -2292,10 +2295,12 @@ class Service:
                     prompt, thought = ids, 0            # thought: the reasoning tokens so far (the budget's count)
+                    stop_close = thinking and os.environ.get("STRATA_STOP_IN_THINKING", "1") != "0"
                     while True:
                         ...
                         seg, wrap, leaving = [], False, False   # this pass's tokens; the budget is reached; closed
+                        resume = False                          # stopped while still thinking
@@ -2309,6 +2314,9 @@ class Service:
                                 if t in self.stop_ids:
                                     finish = "stop"
                                     raw_ids.append(t)
+                                    if stop_close and parser.state == "reasoning" and not parser.buf \
+                                            and not detok.pending():
+                                        resume = True   # no </think> yet = no answer, no tool call
                                     break
@@ -2350,6 +2358,22 @@ class Service:
+                        if resume and not cancel.is_set():
+                            stop_close = False          # once per reply
+                            extra = self.tok.encode(STOP_IN_THINKING_CLOSE, parse_special=True)
+                            if max_new - n - len(extra) >= 1:
+                                print("[strata] the reply stopped inside its thinking (no answer, no tool call): "
+                                      "closing the thinking and letting it answer", flush=True)
+                                for t in extra:
+                                    n += 1
+                                    raw_ids.append(t)
+                                    evs = parser.feed(detok.push(t))
+                                    self._note(n, evs, st, rate)
+                                    for ev in evs:
+                                        yield "event", ev
+                                finish = "length"
+                                prompt = prompt + seg + extra
+                                continue
                         if not wrap or cancel.is_set():
                             break

Open questions for you:

  • Default on or opt-in? We run it on; it only acts on a reply that would otherwise be empty.
  • Worth a /metrics counter like #970's implicit_reasoning_ends?
  • Only tested with one request at a time (no --batch / parallel).

Happy to turn this into a PR against main with a mock-engine test (stop inside thinking → continued; switch off →
unchanged; normal answer → untouched; stops twice → closed once).

Originally created by @davidsheridan77-dot on GitHub (Oct 6, 2026). Original GitHub issue: https://github.com/Niko1221/Strata/issues/1053 ## Summary With thinking on, Qwen3.8-Flash-Next sometimes writes one sentence of reasoning and then `<|im_end|>`, **without closing `</think>` and without a tool call**. `OutputParser` is still in the `reasoning` state, so the whole reply is `reasoning_content`, `content` is empty and `finish_reason` is `stop`. An agent harness sees an empty turn right after a tool result and stops (ours, OpenClaw, then runs a tools-off "finalization" pass, so the model can only reply that it cannot do the edit). This is the same family as #804 and #843, but a different shape: there is **no `<tool_call>` inside the thinking** (so #970 / the `rcall` state don't catch it), and no earlier empty turns in the history (fresh session). Strata already has the machinery for this: the #123 thinking-budget wrap-up closes the thinking and continues from the held prefix. Doing the same once when the model **stops** inside its thinking fixes it here: 20/20 vs ~15% failures. ## Environment ```text GPU AMD RX 9060 XT 16 GB (gfx1200), PCIe 3.0 CPU/RAM Ryzen 5 5500, 64 GB DDR4 OS Ubuntu 24.04, ROCm (system /opt/rocm), HIP engine built by setup Strata v0.1.39 (6f32ec0) Model Qwen3.8-Flash-Next GSQ-RCO Q2_0, --kv int8, --spec 4 --spec-min-p 0.5, MTP, 32K and 64K context Client OpenClaw agent, OpenAI Chat Completions, streaming, reasoning_effort "low", 16 tools ``` ## What the model generated Task: "One of the files in configs/ has debug turned on. Turn it off, then create changelog.md with one line saying which file you changed." The agent globs, greps (finds `b.conf: debug = true`), reads `b.conf`. The next reply is 13 tokens. `STRATA_DEBUG=1` (set on the **server** process — in the config's `"env"` block it only reaches the engine child, so nothing is printed) shows, identical in all 3 failing runs: ```text [strata] done: 13 tokens in 2 s (50.5 tok/s) (stop, cancel=False), expert cache 90.5% hit ... [strata] raw: 'I need to investigate further. Let me check the details.<|im_end|>' ``` `OutputParser(thinking=True).feed(...)` on that text gives only a `reasoning` event — no content, no call. ## Frequency (same task, fresh session per run) | Run | Engine / server | Result | | --- | --- | --- | | A | 0.1.39, stock server | 9/10 pass, 1 empty-stop turn | | B | 0.1.39, stock server, `STRATA_DEBUG=1` | 17/20 pass, 3 empty-stop turns (raw text above) | | C | 0.1.39 + the patch below | **20/20 pass**; the patch fired 2x, 0 empty turns | In run C, after the inserted `</think>` the model wrote the correct call both times (tool name and path shortened): ```text [strata] raw: 'I need to investigate further. Let me check the details.<|im_end|>\n</think>\n\n<tool_call>\n<function=edit_file>\n<parameter=file_path>\n.../configs/b.conf\n</parameter>\n<parameter=old_string>\ndebug = true\n</parameter>\n<parameter=new_string>\ndebug = false\n</parameter>\n</function>\n</tool_call><|im_end|>' ``` (The `<|im_end|>` before `</think>` is only in `raw_ids`; the continuation prompt is `prompt + seg + close`, without the stop token.) A full 24-task agent ladder on the patched server: 24/24, decode 45.0 tok/s (44.7 unpatched) — no regressions seen. `python -m unittest serve.test_server serve.test_responses`: same result as unpatched (1 pre-existing error, `test_json_schema_text_format`, also without the patch). ## Proposed change On a stop token while `parser.state == "reasoning"` (and nothing held back), append `"\n</think>\n\n"` and continue once, the same way the #123 budget wrap-up does. Opt-out: `STRATA_STOP_IN_THINKING=0`. Once per reply, so a model that stops again after the close ends normally (its text is then `content`). Against v0.1.39; on current `main` the stop-token branch in `Service.run` is unchanged, so it should port directly (there it would also want to skip the `rcall` state). ```diff --- a/serve/server.py +++ b/serve/server.py @@ -76,6 +76,9 @@ REASONING_WRAP_UP = "\n\nI have thought about this long enough; time to give my answer.\n</think>\n\n" +# A reply that stops while still thinking (no </think>, so no answer and no tool call) is closed and continued +# once, the way #123 closes a thinking budget. STRATA_STOP_IN_THINKING=0 turns it off. +STOP_IN_THINKING_CLOSE = "\n</think>\n\n" @@ -2292,10 +2295,12 @@ class Service: prompt, thought = ids, 0 # thought: the reasoning tokens so far (the budget's count) + stop_close = thinking and os.environ.get("STRATA_STOP_IN_THINKING", "1") != "0" while True: ... seg, wrap, leaving = [], False, False # this pass's tokens; the budget is reached; closed + resume = False # stopped while still thinking @@ -2309,6 +2314,9 @@ class Service: if t in self.stop_ids: finish = "stop" raw_ids.append(t) + if stop_close and parser.state == "reasoning" and not parser.buf \ + and not detok.pending(): + resume = True # no </think> yet = no answer, no tool call break @@ -2350,6 +2358,22 @@ class Service: + if resume and not cancel.is_set(): + stop_close = False # once per reply + extra = self.tok.encode(STOP_IN_THINKING_CLOSE, parse_special=True) + if max_new - n - len(extra) >= 1: + print("[strata] the reply stopped inside its thinking (no answer, no tool call): " + "closing the thinking and letting it answer", flush=True) + for t in extra: + n += 1 + raw_ids.append(t) + evs = parser.feed(detok.push(t)) + self._note(n, evs, st, rate) + for ev in evs: + yield "event", ev + finish = "length" + prompt = prompt + seg + extra + continue if not wrap or cancel.is_set(): break ``` Open questions for you: - Default on or opt-in? We run it on; it only acts on a reply that would otherwise be empty. - Worth a `/metrics` counter like #970's `implicit_reasoning_ends`? - Only tested with one request at a time (no `--batch` / `parallel`). Happy to turn this into a PR against `main` with a mock-engine test (stop inside thinking → continued; switch off → unchanged; normal answer → untouched; stops twice → closed once).
Author
Owner

@justxiami commented on GitHub (Oct 7, 2026):

Data point from a 4×V100 (sm_70) box: both shapes showed up today in the same session with Qwen3.8-Flash-Next IQ3_XXS — the unclosed-thinking shape is not rare, and the literal-marker shape (#537) still reproduces on 0.1.40.1.

Environment

  • Engine: v0.1.40.1 base + #1091 + #1107 + #1020, built -DCMAKE_CUDA_ARCHITECTURES=70, CUDA 12.8; 4× Tesla V100-SXM2-16GB (NVLink pair mesh), --layer-split 12,24,36 --split-device 1,2,3 --kv int8 --spec 3 --vision --max-context 262144, STRATA_SPEC_COUPLED=1, reasoning_budget_tokens: 8192.
  • serve: 0.1.40 serve/server.py plus local patches (admission #1012, engine death note #997/#890, tool_call_recovery #1172); the output parser is the stock OutputParser.
  • Client: an OpenAI-compatible agent harness (pi) that resends the previous reply's reasoning as assistant.reasoning_content; template kwargs enable_thinking and reasoning_effort (no preserve_thinking).

Shape A — the reply ends inside <think> (this issue)

  • 15:36:32 CST (07:36:32Z): reasoning_content 3536 characters, content empty, finish_reason: "stop" after 1159 generated tokens. The engine-side summary is done: 1159 tokens in 15 s (stop, cancel=False); the parser was still in the reasoning state when the model stopped. No <tool_call> anywhere in the turn — same shape you describe (no rcall state to catch it).
  • The turn before it (07:34:34Z) is the mirror image: content 138 characters that stop inside a code span, with the remaining 2153 characters in reasoning_content.

Shape B — a literal marker in the model's own reasoning (#537, second half)

  • 07:33:36Z / 07:33:54Z / 07:34:05Z: content is the reasoning (1969 / 301 / 1300 characters) and ends with a literal </think>.
  • 07:34:34Z / 07:35:43Z: content stops 138 / 1184 characters in, mid-backtick, and the rest is reasoning_content (2153 / 840 characters).
  • The trigger was the topic itself: the turn was about the template's own thinking markers, so the model quoted them inside its reasoning. That is the "not only a literal marker in the prompt" case @fenrir-labs76 described on #537: the encode side is fixed (mark_think_literals / unmark_think_literals, serve/frontend.py), the parse side still splits on text (OutputParser states reasoning / rcall / content, frontend.py).
  • Consequences beyond the first reply: the mixed channels are stored per turn and the client resends the reasoning, so the conversation keeps the swapped boundaries on every later turn.

It is not serve-side truncation

Over the 11.5-hour run of that serve process: 0 length finishes, 0 cancel=True, 0 thinking budget reached (budget 8192), and every request ends (stop, cancel=False). So the empty turn is the model's own end-of-turn inside the reasoning span, as in your analysis.

Suggestion

  • As in this issue: reuse #123's wrap-up once (close the thinking, continue from the held prefix) when a turn ends in the reasoning state with no tool call.
  • For the literal-marker half, a text parser cannot decide whether </think> is quoted or real. Our engine knows the turn's role markers as control tokens, so a token-id boundary (rather than text matching) would remove that ambiguity on the output side too.
  • Happy to build and A/B a patch here (4×V100 sm_70, fresh restarts, paired windows) if a Volta data point helps.
<!-- gh-comment-id:6033476994 --> @justxiami commented on GitHub (Oct 7, 2026): Data point from a 4×V100 (sm_70) box: both shapes showed up today in the same session with **Qwen3.8-Flash-Next IQ3_XXS** — the unclosed-thinking shape is not rare, and the literal-marker shape (#537) still reproduces on 0.1.40.1. ## Environment - **Engine**: v0.1.40.1 base + #1091 + #1107 + #1020, built `-DCMAKE_CUDA_ARCHITECTURES=70`, CUDA 12.8; 4× Tesla V100-SXM2-16GB (NVLink pair mesh), `--layer-split 12,24,36 --split-device 1,2,3 --kv int8 --spec 3 --vision --max-context 262144`, `STRATA_SPEC_COUPLED=1`, `reasoning_budget_tokens: 8192`. - **serve**: 0.1.40 `serve/server.py` plus local patches (admission #1012, engine death note #997/#890, `tool_call_recovery` #1172); the output parser is the stock `OutputParser`. - **Client**: an OpenAI-compatible agent harness (pi) that resends the previous reply's reasoning as `assistant.reasoning_content`; template kwargs `enable_thinking` and `reasoning_effort` (no `preserve_thinking`). ## Shape A — the reply ends inside `<think>` (this issue) - 15:36:32 CST (07:36:32Z): `reasoning_content` 3536 characters, `content` **empty**, `finish_reason: "stop"` after 1159 generated tokens. The engine-side summary is `done: 1159 tokens in 15 s (stop, cancel=False)`; the parser was still in the `reasoning` state when the model stopped. No `<tool_call>` anywhere in the turn — same shape you describe (no `rcall` state to catch it). - The turn before it (07:34:34Z) is the mirror image: `content` 138 characters that stop inside a code span, with the remaining 2153 characters in `reasoning_content`. ## Shape B — a literal marker in the model's own reasoning (#537, second half) - 07:33:36Z / 07:33:54Z / 07:34:05Z: `content` **is** the reasoning (1969 / 301 / 1300 characters) and ends with a literal `</think>`. - 07:34:34Z / 07:35:43Z: `content` stops 138 / 1184 characters in, mid-backtick, and the rest is `reasoning_content` (2153 / 840 characters). - The trigger was the topic itself: the turn was about the template's own thinking markers, so the model quoted them inside its reasoning. That is the "not only a literal marker in the prompt" case @fenrir-labs76 described on #537: the **encode** side is fixed (`mark_think_literals` / `unmark_think_literals`, `serve/frontend.py`), the **parse** side still splits on text (`OutputParser` states `reasoning` / `rcall` / `content`, `frontend.py`). - Consequences beyond the first reply: the mixed channels are stored per turn and the client resends the reasoning, so the conversation keeps the swapped boundaries on every later turn. ## It is not serve-side truncation Over the 11.5-hour run of that serve process: 0 `length` finishes, 0 `cancel=True`, 0 `thinking budget reached` (budget 8192), and every request ends `(stop, cancel=False)`. So the empty turn is the model's own end-of-turn inside the reasoning span, as in your analysis. ## Suggestion - As in this issue: reuse #123's wrap-up once (close the thinking, continue from the held prefix) when a turn ends in the `reasoning` state with no tool call. - For the literal-marker half, a text parser cannot decide whether `</think>` is quoted or real. Our engine knows the turn's role markers as control tokens, so a token-id boundary (rather than text matching) would remove that ambiguity on the output side too. - Happy to build and A/B a patch here (4×V100 sm_70, fresh restarts, paired windows) if a Volta data point helps.
Author
Owner

@eamars commented on GitHub (Oct 7, 2026):

Another data point for the "literal marker in the model's own reasoning" shape (#537, second half): it reproduces on 0.1.39 with a single request, and the leaked replies share a structure that the parser could fix.

Environment

  • Strata 0.1.39, through the NVFP4 fork sergqwer/strata-nvfp4 v0.1.39-nvfp4.3. serve/frontend.py (OutputParser, mark_think_literals) is the 0.1.39 code.
  • Qwen3.8-Flash-Next, ModelOpt NVFP4. RTX 5090, Windows 11, 262144 context, --kv int8, MTP --spec 4 --spec-min-p 0.5, conversation cache with 16 slots, vision on.
  • Direct /v1/chat/completions, non-streaming, one request at a time, thinking on (default effort).

Minimal repro: 6/6 seeds

curl -s http://127.0.0.1:1919/v1/chat/completions -H 'Content-Type: application/json' -d '{
  "model": "<model>", "stream": false, "max_tokens": 4096, "temperature": 0.7, "top_p": 0.95, "seed": 1,
  "messages": [
    {"role": "system", "content": "你是小满,一个在QQ群里聊天的女孩子。说话简短、口语化,一次只回一两句。"},
    {"role": "user", "content": "[群主] 你今天被白嫖算力了你知道么\n(对了你上一句末尾怎么冒出来一个 </think> ?)"}]}'

(System: "you are a girl chatting in a group, reply in one or two short sentences". User: "you got freeloaded on compute today, did you know? (by the way, why did a </think> show up at the end of your last line?)")

With seeds 1–6, all six end in finish_reason: "stop" after 157–396 tokens, and all six have the same shape:

  • reasoning_content ends right where the model quotes the user's question: …上一句末尾怎么冒出来一个
  • content begins with the rest of the reasoning ( ?)" 角色:小满…需要回应…). That reasoning ends in a draft of the reply.
  • Then comes a second </think>, visible in content, then the reply itself.

So content looks like <rest of reasoning ending in draft X>\n</think>\n\n<X>, which client harnesses see as a stray tag plus the reply written twice. The #537 input fix works: the user's </think> reaches the model as text. The model still writes the quote in its reasoning as the single </think> token, and the parser switches channels there.

Counts (0.1.39, same setup)

Condition Replies with </think> in content
User message quoting </think>, plain chat, T=0.7 8/8 on that turn; then 1/8, 1/8, 2/8 on the next three normal turns (the model keeps talking about the tag and quotes it again)
Same, agent shape (a think tool step, then a text reply; reasoning resent as reasoning_content), T=0.2, fixed seed 2/6
User message quoting </next_thinking> (not a special token) 0/13 (quoted in the reasoning, no split)
A previous assistant message containing X\n</think>\n\nX, no quote in the new message 0/52 conversations
Control 0/14

We also saw this in production. An agent's own leaked line (X\n</think>\n\nX) was later passed to a summarizer subagent as input, and the summarizer leaked on its first step (2/2).

Suggestion: split at the last </think>

In every leaked reply above, content contains a second </think>. Taking the text after the last one gave the clean intended reply in 12/12 text replies. The other 2 were tool-call steps with nothing after the tag, where everything before the call is reasoning anyway. Right now OutputParser passes any later </think> through as content text once it is in the content state.

A proposal, in the spirit of #1053's "close the thinking and continue":

  • Non-streaming: if the model emits </think> again after the first one (and no tool call has been emitted since), move everything before the last one into reasoning_content. This doesn't require deciding which tag was "real". A second end-of-thinking token is enough evidence that the first one was a quote.
  • Streaming: what was already sent can't be taken back. But the later </think> could at least be held back instead of sent, and clients could be told the boundary moved (for example a reasoning delta repeating the moved span, or a flag in the final chunk).

I haven't captured raw token ids. I'm assuming the second visible </think> is token 248069 rather than the text pieces </, think, >, since that string is one token in this vocabulary. I can rerun with STRATA_DEBUG=1 to confirm if that helps.

<!-- gh-comment-id:6035247241 --> @eamars commented on GitHub (Oct 7, 2026): Another data point for the "literal marker in the model's own reasoning" shape (#537, second half): it reproduces on 0.1.39 with a single request, and the leaked replies share a structure that the parser could fix. ## Environment - Strata **0.1.39**, through the NVFP4 fork [sergqwer/strata-nvfp4 v0.1.39-nvfp4.3](https://github.com/sergqwer/strata-nvfp4/releases/tag/v0.1.39-nvfp4.3). `serve/frontend.py` (`OutputParser`, `mark_think_literals`) is the 0.1.39 code. - Qwen3.8-Flash-Next, ModelOpt NVFP4. RTX 5090, Windows 11, 262144 context, `--kv int8`, MTP `--spec 4 --spec-min-p 0.5`, conversation cache with 16 slots, vision on. - Direct `/v1/chat/completions`, non-streaming, one request at a time, thinking on (default effort). ## Minimal repro: 6/6 seeds ```bash curl -s http://127.0.0.1:1919/v1/chat/completions -H 'Content-Type: application/json' -d '{ "model": "<model>", "stream": false, "max_tokens": 4096, "temperature": 0.7, "top_p": 0.95, "seed": 1, "messages": [ {"role": "system", "content": "你是小满,一个在QQ群里聊天的女孩子。说话简短、口语化,一次只回一两句。"}, {"role": "user", "content": "[群主] 你今天被白嫖算力了你知道么\n(对了你上一句末尾怎么冒出来一个 </think> ?)"}]}' ``` (System: "you are a girl chatting in a group, reply in one or two short sentences". User: "you got freeloaded on compute today, did you know? (by the way, why did a `</think>` show up at the end of your last line?)") With seeds 1–6, all six end in `finish_reason: "stop"` after 157–396 tokens, and all six have the same shape: - `reasoning_content` ends right where the model quotes the user's question: `…上一句末尾怎么冒出来一个 ` - `content` begins with the rest of the reasoning (` ?)" 角色:小满…需要回应…`). That reasoning ends in a draft of the reply. - Then comes a second `</think>`, visible in `content`, then the reply itself. So `content` looks like `<rest of reasoning ending in draft X>\n</think>\n\n<X>`, which client harnesses see as a stray tag plus the reply written twice. The #537 input fix works: the user's `</think>` reaches the model as text. The model still writes the quote in its reasoning as the single `</think>` token, and the parser switches channels there. ## Counts (0.1.39, same setup) | Condition | Replies with `</think>` in `content` | |---|---| | User message quoting `</think>`, plain chat, T=0.7 | **8/8** on that turn; then 1/8, 1/8, 2/8 on the next three normal turns (the model keeps talking about the tag and quotes it again) | | Same, agent shape (a `think` tool step, then a text reply; reasoning resent as `reasoning_content`), T=0.2, fixed seed | 2/6 | | User message quoting `</next_thinking>` (not a special token) | 0/13 (quoted in the reasoning, no split) | | A previous assistant message containing `X\n</think>\n\nX`, no quote in the new message | 0/52 conversations | | Control | 0/14 | We also saw this in production. An agent's own leaked line (`X\n</think>\n\nX`) was later passed to a summarizer subagent as input, and the summarizer leaked on its first step (2/2). ## Suggestion: split at the last `</think>` In every leaked reply above, `content` contains a **second** `</think>`. Taking the text after the **last** one gave the clean intended reply in 12/12 text replies. The other 2 were tool-call steps with nothing after the tag, where everything before the call is reasoning anyway. Right now `OutputParser` passes any later `</think>` through as content text once it is in the `content` state. A proposal, in the spirit of #1053's "close the thinking and continue": - **Non-streaming:** if the model emits `</think>` again after the first one (and no tool call has been emitted since), move everything before the last one into `reasoning_content`. This doesn't require deciding which tag was "real". A second end-of-thinking token is enough evidence that the first one was a quote. - **Streaming:** what was already sent can't be taken back. But the later `</think>` could at least be held back instead of sent, and clients could be told the boundary moved (for example a `reasoning` delta repeating the moved span, or a flag in the final chunk). I haven't captured raw token ids. I'm assuming the second visible `</think>` is token 248069 rather than the text pieces `</`, `think`, `>`, since that string is one token in this vocabulary. I can rerun with `STRATA_DEBUG=1` to confirm if that helps.
Author
Owner

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

Added in 0.1.40.2 as an opt-in: "reasoning_close_retry": true in strata-.json. When a reply ends on its end-of-turn token still inside with no answer and no tool call, the thinking is closed once and generation continues. Off by default; please try it on your agent and tell us the failure rate before and after.

<!-- gh-comment-id:6037959653 --> @Niko1221 commented on GitHub (Oct 7, 2026): Added in 0.1.40.2 as an opt-in: "reasoning_close_retry": true in strata-<model>.json. When a reply ends on its end-of-turn token still inside <think> with no answer and no tool call, the thinking is closed once and generation continues. Off by default; please try it on your agent and tell us the failure rate before and after.
Author
Owner

@davidsheridan77-dot commented on GitHub (Oct 12, 2026):

Thanks for adding reasoning_close_retry, and to @justxiami and @eamars for the extra data points.

Numbers from our setup (single RX 9060 XT 16 GB / gfx1200, Linux, ROCm, Qwen3.8-Flash-Next Q2_0, --kv int8 --spec 4, a tool-using agent, thinking on, low effort):

  • Before, on our targeted replay of the failing agent turn (L5b, a tool-using edit step): 3/20 runs ended inside <think> with empty content and the agent stopped.
  • Our local patch (same idea, before 0.1.40.2): L5b 20/20; it fired 2 times in 20, and both times the model went on to write the correct tool call.
  • After, upstream opt-in (0.1.40.3, "reasoning_close_retry": true): our 24-task agent ladder passes 24/24, and in about 900 real replies from Oct 8 to Oct 12 the retry fired 0 times. Some logs from that period were lost to restarts, so treat this as "rare", not "zero".

We're keeping it on. We'll run a direct A/B next (the same failing step 20 times with the setting off, then 20 times on, on 0.1.40.3) and post the results here soon.

<!-- gh-comment-id:6120073999 --> @davidsheridan77-dot commented on GitHub (Oct 12, 2026): Thanks for adding `reasoning_close_retry`, and to @justxiami and @eamars for the extra data points. Numbers from our setup (single RX 9060 XT 16 GB / gfx1200, Linux, ROCm, Qwen3.8-Flash-Next Q2_0, `--kv int8 --spec 4`, a tool-using agent, thinking on, low effort): - **Before**, on our targeted replay of the failing agent turn (L5b, a tool-using edit step): **3/20** runs ended inside `<think>` with empty content and the agent stopped. - **Our local patch** (same idea, before 0.1.40.2): L5b **20/20**; it fired 2 times in 20, and both times the model went on to write the correct tool call. - **After, upstream opt-in** (0.1.40.3, `"reasoning_close_retry": true`): our 24-task agent ladder passes 24/24, and in about 900 real replies from Oct 8 to Oct 12 the retry fired **0 times**. Some logs from that period were lost to restarts, so treat this as "rare", not "zero". We're keeping it on. We'll run a direct A/B next (the same failing step 20 times with the setting off, then 20 times on, on 0.1.40.3) and post the results here soon.
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#448
No description provided.