[GH-ISSUE #4923] [Engine] A stray backtick in the reasoning hides every tool call that follows it in the paragraph #2260

Open
opened 2026-11-04 01:58:00 +07:00 by bsakaguchi · 1 comment
Owner

Originally created by @florian862-art on GitHub (Nov 1, 2026).
Original GitHub issue: https://github.com/Niko1221/Strata/issues/4923

Area

[Engine] (speed, kernels, models, the server and API)

Desktop app, Terminal or source?

Docker

What happened

One unpaired backtick anywhere in the reasoning text makes every tool call that follows it in the same paragraph be
kept as reasoning text instead of being delivered as a call. The client receives a well-formed, complete reply -
the block is closed and message_delta + message_stop arrive normally - that simply contains thinking only and no
tool_use block. An agentic client therefore has nothing to execute and sits in "Thinking" indefinitely, while the
engine has already finished the turn.

The inline-code test in OutputParser counts backticks across the whole paragraph (self.ticks += line.count("`"), reset only on a blank line). A model that writes one unpaired backtick - a tool name meant as
inline code whose closing backtick never arrives - leaves that count odd for the rest of the paragraph, and
_opener_ok() / _in_code() then read every later <tool_call> as quoted inline code.

What makes this expensive rather than cosmetic:

  • It is silent. The turn ends with finish=stop, the SSE stream is closed properly, and nothing is logged. The
    client just has nothing to act on.
  • No configuration avoids it. tool_call_recovery does not rescue the call (checked below), because the call is
    never recognised as a call in the first place.
  • It is model-independent: any model that emits a stray backtick while thinking hits it. It is also not a
    streaming artefact - whole and streamed outputs agree (see below), so it is not the buffer/flush class of bug.

Suspected path, for the maintainers' convenience: inline code is a one-line matter in the cases that matter here -
a quoted call is written `<tool_call>` or inside a fence, both of which are already handled by the fence
state and the current line. Carrying the odd count across the rest of the paragraph is what loses the call.

This is the output-side sibling of #1058 (a quoted call being delivered as a real one) and shares OutputParser's
code tracking with #4702 (fence length) and #4703 (indented blocks). It is not a duplicate of any of them: #4702 is
about a fence being closed too early, here a fence-less inline count is carried too far.

Smallest steps or command that reproduce it

Parser level - no model, no GPU, no server. From the root of a checkout:

import sys; sys.path.insert(0, ".")
from serve.frontend import OutputParser

TOOLS = [{"name": "run_commands", "parameters": {"type": "object", "properties": {
    "commands": {"type": "array", "items": {"type": "string"}}}, "required": ["commands"]}}]
CALL = ('<tool_call>\n<function=run_commands>\n<parameter=commands>\n["ls"]\n</parameter>\n'
        '</function>\n</tool_call>')

def delivered(text, chunk=None, recover=False):
    p = OutputParser(True, list(TOOLS), stream_tools=True, recover=recover)
    ev = []
    if chunk:                                  # streamed, in pieces of `chunk` characters
        for i in range(0, len(text), chunk):
            ev += p.feed(text[i:i + chunk])
    else:
        ev = p.feed(text)
    return "tool_call" in [e.kind for e in ev + p.finish("stop")]

A = "Let me use `run_commands` to check.\n" + CALL + "\n"   # backticks paired
B = "Let me use `run_commands to check.\n"  + CALL + "\n"   # one stray backtick
C = "I should check the ls` output first.\nthen run it.\n" + CALL + "\n"

for label, text in (("A paired", A), ("B stray", B), ("C stray, earlier line", C)):
    print(f"{label:22} whole={delivered(text)}  streamed={delivered(text, chunk=7)}")

Observed on main (c62d5e3a):

A paired                 whole=True   streamed=True
B stray                  whole=False  streamed=False
C stray, earlier line    whole=False  streamed=False

Expected: all three True. A call the model writes at the start of a line, outside a fence and outside inline
code, is a call. Variant A shows that a closed inline-code span does not suppress the call, so the odd count is
what does the damage. The opposite guarantee - a call the model quotes on purpose (`<tool_call>`, or inside
a fence) must stay text - is #1058's, is covered by serve/test_tool_corpus.py, and has to keep holding.

The same input with recover=True (the opt-in tool_call_recovery) also stays False in all four combinations of
recover x stream_tools, so no configuration avoids this.

Reproduction status

Reproduced locally

Strata version

Strata 0.2.2 (commit a7689c48) · engine 0.1.47. Reproduced again against serve/frontend.py from main
(c62d5e3a), which still has the paragraph-wide self.ticks count.

Graphics card, memory and system

2x RTX 5070 Ti 16 GB · 91 GB RAM · Linux 7.0.0-38-generic, driver 595.99.02, served in Docker with the source
mounted

Model, size and settings

qwen3.8-flash-next nvfp4 · 262144 context · pictures on · thinking on (thinking budget 12288 of max_tokens 16384) ·
requests over /v1/messages (Anthropic form) from the Cline client

Logs

The parser repro above is the evidence; there is no useful server log for the failure itself, because the failure
is silent by construction. s["phase"] is set only from parser events (server.py ~4837-4845: a tool_call event
is what makes the phase tool call complete), so a turn lost to this bug never logs a tool-call line at all - it
goes from thinking straight to a normal done: ... (stop, cancel=False). A healthy turn for comparison:

[strata] thinking: 390 of budget 12288 (max 16384) tokens, 82.8 tok/s, 35 s
[strata] answering: 554 of max 16384 tokens, 82.2 tok/s, 37 s
[strata] tool call complete: 641 of max 16384 tokens, 82.8 tok/s, 38 s
[strata] done: 700 tokens in 38 s (83.9 tok/s) (stop, cancel=False)

The client-side symptom is a reply that carries reasoning content and ends without a tool call, so the agent never
receives a tool_use to run. The stream itself is well-formed: the open block is closed and message_delta +
message_stop are sent (server.py ~5814-5828), which is why the client waits rather than errors.

A note on the fix, in case it helps

The first rule I tried - carry the open span only when a backtick run ends its line - fixes B and C but is too
narrow: it loses the wrapped span whose closing run ends the line (D1 below). What held up instead pairs the runs
across the paragraph and asks one extra question - whether the last run ended a line:

runs = self._backtick_runs(line)          # "a `b` c" -> 2, "``x" -> 1
self.par_runs += runs
if runs:                                  # a line with no backticks does not move the last run
    self.par_open = line.endswith("`")    # reset both on a blank line, as the tick count was
runs = self._backtick_runs(self.line)
if runs:
    return (self.par_runs + runs) % 2 == 1 and self.line.endswith("`")
return self.par_runs % 2 == 1 and self.par_open

A fence line's own backticks stay literal, and _opener_ok() can delegate to _in_code() instead of repeating the
logic. Where the two rules differ:

shape expected main run-parity + "last run ended a line"
B1 one stray backtick mid-line, then a call delivered kept as text delivered
B2 stray on an earlier line of the paragraph delivered kept as text delivered
D1 wrapped `example closed by a run that ends its line, then a call delivered delivered delivered
D2 same, closing run mid-line delivered delivered delivered
E1 a call quoted inside a fence kept as text kept kept
E2 a call quoted inline in backticks kept as text kept kept

One case is not recoverable by any rule without lookahead, and it is worth stating because it bounds the fix: "use
run_commands to check." (a stray) and "a span that stays open" (an unclosed span) are the same shape - one
backtick run, not at the end of the line, nothing closing it later in the paragraph. A parser cannot tell them
apart before the paragraph ends. The rule above resolves it towards delivering the call, which for an agentic client
is the cheaper error: a delivered call is at worst a tool the model did not mean, while a kept-as-text call ends the
turn with nothing to run and the client waits forever.

Verified on main (c62d5e3a), not just on my older 0.2.2 checkout:

what was run result
serve/test_parser_track.py, test_tool_corpus.py, test_tool_call_unclosed.py, test_native_tool_parser.py on unpatched main 23 tests OK (baseline)
the same four files with the rule above 23 tests OK
a regression test for variants A-C, on patched main 9 tests OK, B and C now delivered
whole vs streamed output for A, B, C, D1 and E1 at chunk sizes 1, 2, 3, 5, 11 and 97 identical in every case

One thing any fix has to carry: serve/test_parser_track.py pins self.ticks directly (its ReferenceParser
re-implements the tracking and the state tuples compare it), so the test needs the same state change as the parser -
the 23-test line above is with that adaptation applied. test_tool_corpus.py needed no change; its
4077-stray-think-after-a-backtick and qwen-quoted-in-a-fence cases pass as they are.

Why the extra "did the last run end a line" question is what makes it work: parity alone is what main already
does, and parity alone is exactly what loses B1 - a stray backtick leaves the paragraph odd, so everything after it
reads as code. Asking whether the run that would have opened the span actually ended its line keeps the wrapped
example reading #1058 pinned (D1, D2) while a run sitting in the middle of a sentence no longer poisons the rest
of the paragraph.

I am reporting this rather than only carrying a local patch, and I am not presuming the shape of an upstream fix -
the maintainers know what OutputParser has to keep guaranteeing.

Originally created by @florian862-art on GitHub (Nov 1, 2026). Original GitHub issue: https://github.com/Niko1221/Strata/issues/4923 ### Area [Engine] (speed, kernels, models, the server and API) ### Desktop app, Terminal or source? Docker ### What happened One unpaired backtick anywhere in the reasoning text makes every tool call that follows it in the same paragraph be kept as reasoning text instead of being delivered as a call. The client receives a well-formed, complete reply - the block is closed and `message_delta` + `message_stop` arrive normally - that simply contains thinking only and no `tool_use` block. An agentic client therefore has nothing to execute and sits in "Thinking" indefinitely, while the engine has already finished the turn. The inline-code test in `OutputParser` counts backticks across the whole paragraph (`` self.ticks += line.count("`") ``, reset only on a blank line). A model that writes one unpaired backtick - a tool name meant as inline code whose closing backtick never arrives - leaves that count odd for the rest of the paragraph, and `_opener_ok()` / `_in_code()` then read every later `<tool_call>` as quoted inline code. What makes this expensive rather than cosmetic: - It is silent. The turn ends with `finish=stop`, the SSE stream is closed properly, and nothing is logged. The client just has nothing to act on. - No configuration avoids it. `tool_call_recovery` does not rescue the call (checked below), because the call is never recognised as a call in the first place. - It is model-independent: any model that emits a stray backtick while thinking hits it. It is also not a streaming artefact - whole and streamed outputs agree (see below), so it is not the buffer/flush class of bug. Suspected path, for the maintainers' convenience: inline code is a one-line matter in the cases that matter here - a quoted call is written `` `<tool_call>` `` or inside a fence, both of which are already handled by the fence state and the current line. Carrying the odd count across the rest of the paragraph is what loses the call. This is the output-side sibling of #1058 (a quoted call being delivered as a real one) and shares `OutputParser`'s code tracking with #4702 (fence length) and #4703 (indented blocks). It is not a duplicate of any of them: #4702 is about a fence being closed too early, here a fence-less inline count is carried too far. ### Smallest steps or command that reproduce it Parser level - no model, no GPU, no server. From the root of a checkout: ```python import sys; sys.path.insert(0, ".") from serve.frontend import OutputParser TOOLS = [{"name": "run_commands", "parameters": {"type": "object", "properties": { "commands": {"type": "array", "items": {"type": "string"}}}, "required": ["commands"]}}] CALL = ('<tool_call>\n<function=run_commands>\n<parameter=commands>\n["ls"]\n</parameter>\n' '</function>\n</tool_call>') def delivered(text, chunk=None, recover=False): p = OutputParser(True, list(TOOLS), stream_tools=True, recover=recover) ev = [] if chunk: # streamed, in pieces of `chunk` characters for i in range(0, len(text), chunk): ev += p.feed(text[i:i + chunk]) else: ev = p.feed(text) return "tool_call" in [e.kind for e in ev + p.finish("stop")] A = "Let me use `run_commands` to check.\n" + CALL + "\n" # backticks paired B = "Let me use `run_commands to check.\n" + CALL + "\n" # one stray backtick C = "I should check the ls` output first.\nthen run it.\n" + CALL + "\n" for label, text in (("A paired", A), ("B stray", B), ("C stray, earlier line", C)): print(f"{label:22} whole={delivered(text)} streamed={delivered(text, chunk=7)}") ``` Observed on `main` (`c62d5e3a`): ```text A paired whole=True streamed=True B stray whole=False streamed=False C stray, earlier line whole=False streamed=False ``` Expected: all three `True`. A call the model writes at the start of a line, outside a fence and outside inline code, is a call. Variant A shows that a *closed* inline-code span does not suppress the call, so the odd count is what does the damage. The opposite guarantee - a call the model quotes on purpose (`` `<tool_call>` ``, or inside a fence) must stay text - is #1058's, is covered by `serve/test_tool_corpus.py`, and has to keep holding. The same input with `recover=True` (the opt-in `tool_call_recovery`) also stays `False` in all four combinations of `recover` x `stream_tools`, so no configuration avoids this. ### Reproduction status Reproduced locally ### Strata version Strata 0.2.2 (commit `a7689c48`) · engine 0.1.47. Reproduced again against `serve/frontend.py` from `main` (`c62d5e3a`), which still has the paragraph-wide `self.ticks` count. ### Graphics card, memory and system 2x RTX 5070 Ti 16 GB · 91 GB RAM · Linux 7.0.0-38-generic, driver 595.99.02, served in Docker with the source mounted ### Model, size and settings qwen3.8-flash-next nvfp4 · 262144 context · pictures on · thinking on (thinking budget 12288 of max_tokens 16384) · requests over `/v1/messages` (Anthropic form) from the Cline client ### Logs The parser repro above is the evidence; there is no useful server log for the failure itself, because the failure is silent by construction. `s["phase"]` is set only from parser events (`server.py` ~4837-4845: a `tool_call` event is what makes the phase `tool call complete`), so a turn lost to this bug never logs a tool-call line at all - it goes from thinking straight to a normal `done: ... (stop, cancel=False)`. A healthy turn for comparison: ```text [strata] thinking: 390 of budget 12288 (max 16384) tokens, 82.8 tok/s, 35 s [strata] answering: 554 of max 16384 tokens, 82.2 tok/s, 37 s [strata] tool call complete: 641 of max 16384 tokens, 82.8 tok/s, 38 s [strata] done: 700 tokens in 38 s (83.9 tok/s) (stop, cancel=False) ``` The client-side symptom is a reply that carries reasoning content and ends without a tool call, so the agent never receives a `tool_use` to run. The stream itself is well-formed: the open block is closed and `message_delta` + `message_stop` are sent (`server.py` ~5814-5828), which is why the client waits rather than errors. ### A note on the fix, in case it helps The first rule I tried - carry the open span only when a backtick run *ends* its line - fixes B and C but is too narrow: it loses the wrapped span whose closing run ends the line (D1 below). What held up instead pairs the runs across the paragraph and asks one extra question - whether the last run ended a line: ```python runs = self._backtick_runs(line) # "a `b` c" -> 2, "``x" -> 1 self.par_runs += runs if runs: # a line with no backticks does not move the last run self.par_open = line.endswith("`") # reset both on a blank line, as the tick count was ``` ```python runs = self._backtick_runs(self.line) if runs: return (self.par_runs + runs) % 2 == 1 and self.line.endswith("`") return self.par_runs % 2 == 1 and self.par_open ``` A fence line's own backticks stay literal, and `_opener_ok()` can delegate to `_in_code()` instead of repeating the logic. Where the two rules differ: | shape | expected | `main` | run-parity + "last run ended a line" | |---|---|---|---| | B1 one stray backtick mid-line, then a call | delivered | kept as text | delivered | | B2 stray on an earlier line of the paragraph | delivered | kept as text | delivered | | D1 wrapped `` `example `` closed by a run that ends its line, then a call | delivered | delivered | delivered | | D2 same, closing run mid-line | delivered | delivered | delivered | | E1 a call quoted inside a fence | kept as text | kept | kept | | E2 a call quoted inline in backticks | kept as text | kept | kept | One case is not recoverable by any rule without lookahead, and it is worth stating because it bounds the fix: "use `run_commands to check." (a stray) and "a `span that stays open" (an unclosed span) are the same shape - one backtick run, not at the end of the line, nothing closing it later in the paragraph. A parser cannot tell them apart before the paragraph ends. The rule above resolves it towards delivering the call, which for an agentic client is the cheaper error: a delivered call is at worst a tool the model did not mean, while a kept-as-text call ends the turn with nothing to run and the client waits forever. Verified on `main` (`c62d5e3a`), not just on my older 0.2.2 checkout: | what was run | result | |---|---| | `serve/test_parser_track.py`, `test_tool_corpus.py`, `test_tool_call_unclosed.py`, `test_native_tool_parser.py` on unpatched `main` | 23 tests OK (baseline) | | the same four files with the rule above | 23 tests OK | | a regression test for variants A-C, on patched `main` | 9 tests OK, B and C now delivered | | whole vs streamed output for A, B, C, D1 and E1 at chunk sizes 1, 2, 3, 5, 11 and 97 | identical in every case | One thing any fix has to carry: `serve/test_parser_track.py` pins `self.ticks` directly (its `ReferenceParser` re-implements the tracking and the state tuples compare it), so the test needs the same state change as the parser - the 23-test line above is with that adaptation applied. `test_tool_corpus.py` needed no change; its `4077-stray-think-after-a-backtick` and `qwen-quoted-in-a-fence` cases pass as they are. Why the extra "did the last run end a line" question is what makes it work: parity alone is what `main` already does, and parity alone is exactly what loses B1 - a stray backtick leaves the paragraph odd, so everything after it reads as code. Asking whether the run that would have opened the span actually ended its line keeps the wrapped `example` reading #1058 pinned (D1, D2) while a run sitting in the middle of a sentence no longer poisons the rest of the paragraph. I am reporting this rather than only carrying a local patch, and I am not presuming the shape of an upstream fix - the maintainers know what `OutputParser` has to keep guaranteeing.
Author
Owner

@XiaoBinGan commented on GitHub (Nov 4, 2026):

Thanks for the reproduction — it is the parser, not the model. serve/frontend.py's OutputParser._track() counts backticks across the whole paragraph, so one unpaired backtick (Let me use `run_commands to check.) leaves the count odd and every later <tool_call> at the start of a line is read as quoted inline code: the turn completes normally with no tool_use block.

I have a pull request with the fix and the issue's three inputs as tests, plus the two shapes that must stay text (`Use `` + a newline, and a backtick immediately before a tag): #5183

<!-- gh-comment-id:6624334670 --> @XiaoBinGan commented on GitHub (Nov 4, 2026): Thanks for the reproduction — it is the parser, not the model. `serve/frontend.py`'s `OutputParser._track()` counts backticks across the whole paragraph, so one unpaired backtick (``Let me use `run_commands to check.``) leaves the count odd and every later `<tool_call>` at the start of a line is read as quoted inline code: the turn completes normally with no `tool_use` block. I have a pull request with the fix and the issue's three inputs as tests, plus the two shapes that must stay text (`Use `` + a newline, and a backtick immediately before a tag): #5183
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#2260
No description provided.