[GH-ISSUE #3075] [Engine] a tool call the request never offered still becomes tool_calls on the content path (frontend.py:1285, 0.2.1) #1232

Closed
opened 2026-11-04 01:49:34 +07:00 by bsakaguchi · 14 comments
Owner

Originally created by @riverhh76 on GitHub (Oct 18, 2026).
Original GitHub issue: https://github.com/Niko1221/Strata/issues/3075

Re-tested on 0.2.0-beta and on 0.2.1 (see
the latest comment):
still present on 0.2.0-beta (engine 0.1.45.3) and on 0.2.1 (engine 0.1.46).
serve/frontend.py is unchanged between 477ac13c (0.1.45) and v0.2.1.
New detail: the reasoning state (:1246) already has the if self.schemas gate from #804;
the content state (:1285) does not — so the same call is text or a call depending on which
side of </think> the model puts it.

Environment

  • Strata main @ 477ac13c (fetched 2026-10-19), --engine strata, OpenAI-compatible serve
  • Models: swift-1.5-iq3_xxs and the qwen3.8-flash-next family — model-independent (see
    "Another observation, not part of the fix")
  • Sampling: {"temperature": 0, "top_p": 1.0, "presence_penalty": 0} — greedy
  • Reproduces on every model tested; also present in the released 0.1.45 container image

Summary

OutputParser scans the answer for <​tool_call> in two states. The scan in the
reasoning state is gated on whether the request declared tools; the scan in the
content state is not. So a request with no tools field at all still yields
message.tool_calls and finish_reason: "tool_calls" whenever the model writes that
XML — and the function name is never checked against the declared set (there is no
declared set).

A client that does the normal thing — if (msg.tool_calls): run(msg.tool_calls) — then
executes calls for tools it never offered. When the client instead ignores them because
it offered none, it gets content: "" back, i.e. an empty answer.


Minimal reproduction

No GPU, no model, no server — the parser alone.

import sys; sys.path.insert(0, "serve")
import frontend as F

def call(name, **params):
    body = F.FUNC_START + name + ">\n"
    for k, v in params.items():
        body += F.PARAM_START + k + ">\n" + str(v) + "\n" + F.PARAM_END + "\n"
    return F.CALL_START + body + "</function>" + F.CALL_END

# exactly what the model wrote in the incident below
out = call("get_indicators", curr_date="2026-10-15", indicator="close_10_ema", symbol=600076) \
    + call("get_indicators", curr_date="2026-10-15", indicator="close_50_sma", symbol=600076)

p = F.OutputParser(thinking=False, tools=None, stream_tools=False)
events = p.feed(out)
print([e.call.name for e in events if e.kind == "tool_call"])
print("".join(e.text for e in events if e.kind == "content"))

Actual output — tools=None was passed:

['get_indicators', 'get_indicators']
''            # content is empty

tools=[] behaves the same. The streaming path reproduces it too: over HTTP with
stream: true and stream_tools always on (server.py:4216), all four subtests of the
regression test below fail on the unpatched tree.


Observed behaviour matrix

Same parser, same model output, varying only what the request declared:

Request declared tool_calls emitted content
nothing (tools absent) 2 empty ← wrong
tools: [] 2 empty ← wrong
tools: [get_indicators] 2 empty (correct — they are real)
tools: [some_other_tool] 2 ← names get_indicators empty ← wrong

The last row is a second, independent gap: a request that does declare tools still
gets a call to a function that is not in the set. The guard proposed below does not cover
it; it is written up separately under "A second, related gap" because the obvious patch
for it does not work.


Root cause

One line, sitting next to the guarded twin of it:

# :1246  reasoning state — gated
tool = self.buf.find(CALL_START) if self.schemas else -1

# :1285  content state — NOT gated   ← this line
i = self.buf.find(CALL_START)

With no tools, self.schemas == {} (built at :887), yet the content state still
transitions into "call" and runs _finish_call, which builds the ToolCall at :872
without ever comparing name with the declared names (:1448-1451 does
self.schemas.get(name), which is None and is accepted).

Why this reads as an oversight rather than a decision. Every neighbouring path in the
same parser checks something the content path does not:

path line gated on declared tools?
rcall state (a call quoted in the reasoning) :1203 yes — if name in self.schemas
reasoning-state opener scan :1246, :1258 yes — gated on self.schemas
json_tool_call (the recover path) :829-830 yes — obj["name"] not in schemas → None
content-state opener scan :1285 no

The JSON sibling of the same feature validates the name; the XML path does not.

This also runs against the principle the parser has already been fixed to hold elsewhere:
a <​tool_call> that is quoted is text, not a call — #1058, #2039, and #700 ("serve: a
<​tool_call> named in prose before the real call is content, not a malformed call"). The
rule those fixes established is that text which looks like a tool call is text. Here the
inverse holds: a tool call naming a function that was never declared is still a tool call.


Real-world impact

Production agent (TradingAgents) on 600076.SH, 2026-10-15. The technical analyst ran
four tool rounds, then sent a convergence turn that deliberately omits tools and
appends "tool call rounds are exhausted, you must not call any more tools". The
response was:

{"content": "", "finish_reason": "tool_calls",
 "tool_calls": [{"name": "get_indicators", "arguments": {"curr_date": "2026-10-15",
                    "indicator": "close_10_ema", "look_back_days": 30, "symbol": 600076}},
                {"name": "get_indicators", "arguments": {..., "indicator": "close_50_sma", ...}}],
 "usage": {"prompt_tokens": 7328, "completion_tokens": 172}}

The agent writes content only when tool_calls is empty, so the analyst's report became
the empty string, the data-quality gate graded it F, and the final research document
shipped a section reading (empty). A production research pipeline produced a report with
a silent hole in it.

This is not rare, and it predates the current release: our own bench logs from 2026-10-04
(Strata 0.1.38/0.1.39) already recorded finish=tool_calls on requests that carried no
tools, twice, noted then as "occasional tool_calls hallucination" and attributed to the
model. It is the parser.

Anyone whose convergence/final-turn pattern is "stop calling tools" is exposed — that is a
common and reasonable agent design.


Test gap

serve/test_server.py:4313 test_auto_absent_and_none_leave_the_tools_to_the_model is the
test for this case, and it only checks the prompt side:

offered = "search the web" in self.tok.decode(self.engine.prompts[0])
self.assertEqual(offered, extra.get("tool_choice") != "none")

Its fake engine never emits tool-call XML, so the answer side is never exercised. There is
no test anywhere asserting that a request which declared no tools cannot come back with
tool_calls.


Suggested direction

Mirror the guard that already exists at :1246:

# :1285
i = self.buf.find(CALL_START) if self.schemas else -1

That one line is the whole fix for this report. Measured with the repo's own
serve/test_server.py inside the 0.1.45 image (jinja2 3.1.6):

result
baseline 477ac13c, with the new regression test 4 subtests fail (nothing declared and tool_choice none, streaming and not)
with the guard 4 subtests pass
full suite, baseline 337 passed, 482 subtests passed
full suite, with the guard and the new test 338 passed, 486 subtests passed

The new test is ForcedToolChoice.test_a_call_the_request_never_offered_stays_text: a model
that, after </think>, writes a complete well-formed call naming a tool the request never
offered. Today that comes back as tool_calls with an empty content; with the guard the
whole answer comes back as text, call and all.

The test also pins the case where the request declared other tools and tool_choice: none
— both must produce text, and both do today only by accident of the first guard being absent.


When a request does declare tools but the model names a function that is not among them,
the call is emitted anyway:

request declared model writes result today
[some_other_tool] a call to get_indicators tool_calls: [get_indicators], content empty

This one is not fixed by the guard above, and I want to be precise about why, because the
obvious patch does not work.

Service.run always constructs the parser with streaming on (server.py:4216,
stream_tools=True). With streaming on, the call is consumed by _scan() before
_finish_call() runs (frontend.py:1395-1408):

  • _scan() hits <function=NAME> at frontend.py:1078-1087, builds
    ToolCall(name=name, arguments={}) with no membership check — self.schemas.get(name)
    at :1085 is used only to read declared parameter types — and immediately emits
    tool_start, so the client is already told about the call.
  • finish() (:1428-1431) emits the final tool_call for that already-announced call.

Adding a name check inside _finish_call therefore changes nothing observable over the wire:
by the time it runs, the tool_start/tool_args chunks are already on the wire and the
client has assembled the call. I confirmed this by measurement — with such a check added, the
response carried both the text and a tool_calls entry.

The right place is _scan() at the ss == "name" step (:1083): the name is complete there
and nothing has been emitted yet, so an undeclared name can still be refused and the raw text
returned as content. That is a real change to the streaming state machine, so I would rather
raise it than guess at it. Flagging it as a separate item rather than folding it into the
one-line fix above — happy to work on it if you want it in the same PR.


Another observation, not part of the fix

serve/chat_template.jinja:130-157 renders an assistant message's tool_calls
unconditionally — that loop sits outside the {%- if tools ... %} block at :72. So a
request that declares no tools, but whose history contains tool-calling turns, puts verbatim
tool-call demonstrations into the prompt:

<|im_start|>assistant
<think>

</think>

<​tool_call>
<function=get_indicators>
<parameter=indicator>
rsi
</parameter>
...
</function>
</​tool_call><|im_end|>

Measured on swift-1.5-iq3_xxs with the repo's own tokenizer
(tools/strata_tokenizer.py over /data/packs/swift-iq3_xxs/tokenizer):

conversation tools=None tools=[one tool]
5-message demo (1 historical call) 396 tokens 641 tokens (the tools block adds 245)
the real 13-message incident payload 7364 tokens, 4 verbatim call demonstrations —

The prompt then ends with an already-opened assistant turn (<|im_start|>assistant\n<think>\n\n),
after a final user turn that reads "Tool call rounds are exhausted. You must not call any
more tools. Write the final report now."

Greedy decoding on that context continues the demonstrated pattern. That is expected, and it
is not the bug — a model writing <​tool_call> after being shown four examples is behaving
reasonably. The bug is that the parser treats the result as a real call.

Worth noting that the reasoning-state equivalent is already handled: a call quoted inside the
thinking stays reasoning text (rcall at :1194-1212, guard at :1203/:1246). The answer
of a non-thinking turn, or the part of a thinking turn after </think>, was not. I confirmed
that split by measurement: the same XML before </think> stays text today; the same XML after
it becomes a call.

I am not proposing a change here — the history rendering cannot simply be dropped without
corrupting the conversation — but the trigger is prompt hygiene, not the weights, so
swapping models does not remove it.


What I did not test

  • Only the Content → call path was exercised directly. The rcall (reasoning) path
    already gates correctly and was left alone.
  • No end-to-end run against a live engine for the fix; the regression data above is the
    parser plus the full serve suite, not a served request.
  • Vision and MCP paths untouched.
Originally created by @riverhh76 on GitHub (Oct 18, 2026). Original GitHub issue: https://github.com/Niko1221/Strata/issues/3075 > **Re-tested on 0.2.0-beta and on 0.2.1** (see > [the latest comment](https://github.com/Niko1221/Strata/issues/3075#issuecomment-6293843875)): > still present on **0.2.0-beta** (engine 0.1.45.3) and on **0.2.1** (engine 0.1.46). > `serve/frontend.py` is unchanged between `477ac13c` (0.1.45) and `v0.2.1`. > New detail: the reasoning state (`:1246`) already has the `if self.schemas` gate from #804; > the content state (`:1285`) does not — so the same call is text or a call depending on which > side of `</think>` the model puts it. ## Environment - Strata `main` @ `477ac13c` (fetched 2026-10-19), `--engine strata`, OpenAI-compatible serve - Models: `swift-1.5-iq3_xxs` and the `qwen3.8-flash-next` family — **model-independent** (see "Another observation, not part of the fix") - Sampling: `{"temperature": 0, "top_p": 1.0, "presence_penalty": 0}` — greedy - Reproduces on **every** model tested; also present in the released `0.1.45` container image --- ## Summary `OutputParser` scans the answer for `<​tool_call>` in two states. The scan in the **reasoning** state is gated on whether the request declared tools; the scan in the **content** state is not. So a request with **no `tools` field at all** still yields `message.tool_calls` and `finish_reason: "tool_calls"` whenever the model writes that XML — and the function name is never checked against the declared set (there is no declared set). A client that does the normal thing — `if (msg.tool_calls): run(msg.tool_calls)` — then executes calls for tools it never offered. When the client instead *ignores* them because it offered none, it gets `content: ""` back, i.e. **an empty answer**. --- ## Minimal reproduction No GPU, no model, no server — the parser alone. ```python import sys; sys.path.insert(0, "serve") import frontend as F def call(name, **params): body = F.FUNC_START + name + ">\n" for k, v in params.items(): body += F.PARAM_START + k + ">\n" + str(v) + "\n" + F.PARAM_END + "\n" return F.CALL_START + body + "</function>" + F.CALL_END # exactly what the model wrote in the incident below out = call("get_indicators", curr_date="2026-10-15", indicator="close_10_ema", symbol=600076) \ + call("get_indicators", curr_date="2026-10-15", indicator="close_50_sma", symbol=600076) p = F.OutputParser(thinking=False, tools=None, stream_tools=False) events = p.feed(out) print([e.call.name for e in events if e.kind == "tool_call"]) print("".join(e.text for e in events if e.kind == "content")) ``` Actual output — `tools=None` was passed: ``` ['get_indicators', 'get_indicators'] '' # content is empty ``` `tools=[]` behaves the same. The streaming path reproduces it too: over HTTP with `stream: true` and `stream_tools` always on (`server.py:4216`), all four subtests of the regression test below fail on the unpatched tree. --- ## Observed behaviour matrix Same parser, same model output, varying only what the request declared: | Request declared | `tool_calls` emitted | `content` | |---|---|---| | nothing (`tools` absent) | **2** | **empty** ← wrong | | `tools: []` | **2** | **empty** ← wrong | | `tools: [get_indicators]` | 2 | empty (correct — they are real) | | `tools: [some_other_tool]` | **2** ← names `get_indicators` | **empty** ← wrong | The last row is a second, independent gap: a request that *does* declare tools still gets a call to a function that is not in the set. The guard proposed below does not cover it; it is written up separately under "A second, related gap" because the obvious patch for it does not work. --- ## Root cause One line, sitting next to the guarded twin of it: ```python # :1246 reasoning state — gated tool = self.buf.find(CALL_START) if self.schemas else -1 # :1285 content state — NOT gated ← this line i = self.buf.find(CALL_START) ``` With no tools, `self.schemas == {}` (built at `:887`), yet the content state still transitions into `"call"` and runs `_finish_call`, which builds the `ToolCall` at `:872` without ever comparing `name` with the declared names (`:1448-1451` does `self.schemas.get(name)`, which is `None` and is accepted). **Why this reads as an oversight rather than a decision.** Every neighbouring path in the same parser checks something the content path does not: | path | line | gated on declared tools? | |---|---|---| | `rcall` state (a call quoted in the reasoning) | `:1203` | yes — `if name in self.schemas` | | reasoning-state opener scan | `:1246`, `:1258` | yes — gated on `self.schemas` | | `json_tool_call` (the `recover` path) | `:829-830` | yes — `obj["name"] not in schemas → None` | | **content-state opener scan** | **`:1285`** | **no** | The JSON sibling of the same feature validates the name; the XML path does not. This also runs against the principle the parser has already been fixed to hold elsewhere: a `<​tool_call>` that is *quoted* is text, not a call — #1058, #2039, and #700 ("serve: a `<​tool_call>` named in prose before the real call is content, not a malformed call"). The rule those fixes established is that text which looks like a tool call is text. Here the inverse holds: a tool call naming a function that was never declared is still a tool call. --- ## Real-world impact Production agent (`TradingAgents`) on 600076.SH, 2026-10-15. The technical analyst ran four tool rounds, then sent a convergence turn that deliberately **omits `tools`** and appends *"tool call rounds are exhausted, you must not call any more tools"*. The response was: ```json {"content": "", "finish_reason": "tool_calls", "tool_calls": [{"name": "get_indicators", "arguments": {"curr_date": "2026-10-15", "indicator": "close_10_ema", "look_back_days": 30, "symbol": 600076}}, {"name": "get_indicators", "arguments": {..., "indicator": "close_50_sma", ...}}], "usage": {"prompt_tokens": 7328, "completion_tokens": 172}} ``` The agent writes `content` only when `tool_calls` is empty, so the analyst's report became the empty string, the data-quality gate graded it **F**, and the final research document shipped a section reading *(empty)*. A production research pipeline produced a report with a silent hole in it. This is not rare, and it predates the current release: our own bench logs from **2026-10-04** (Strata 0.1.38/0.1.39) already recorded `finish=tool_calls` on requests that carried no `tools`, twice, noted then as *"occasional tool_calls hallucination"* and attributed to the model. It is the parser. Anyone whose convergence/final-turn pattern is "stop calling tools" is exposed — that is a common and reasonable agent design. --- ## Test gap `serve/test_server.py:4313 test_auto_absent_and_none_leave_the_tools_to_the_model` is the test for this case, and it only checks the **prompt** side: ```python offered = "search the web" in self.tok.decode(self.engine.prompts[0]) self.assertEqual(offered, extra.get("tool_choice") != "none") ``` Its fake engine never emits tool-call XML, so the answer side is never exercised. There is no test anywhere asserting that a request which declared no tools cannot come back with `tool_calls`. --- ## Suggested direction Mirror the guard that already exists at `:1246`: ```python # :1285 i = self.buf.find(CALL_START) if self.schemas else -1 ``` That one line is the whole fix for this report. Measured with the repo's own `serve/test_server.py` inside the 0.1.45 image (jinja2 3.1.6): | | result | |---|---| | baseline `477ac13c`, with the new regression test | **4 subtests fail** (`nothing declared` and `tool_choice none`, streaming and not) | | with the guard | **4 subtests pass** | | full suite, baseline | 337 passed, 482 subtests passed | | full suite, with the guard **and** the new test | **338 passed, 486 subtests passed** | The new test is `ForcedToolChoice.test_a_call_the_request_never_offered_stays_text`: a model that, after `</think>`, writes a complete well-formed call naming a tool the request never offered. Today that comes back as `tool_calls` with an empty content; with the guard the whole answer comes back as text, call and all. The test also pins the case where the request declared *other* tools and `tool_choice: none` — both must produce text, and both do today only by accident of the first guard being absent. --- ## A second, related gap: an undeclared name, with tools declared When a request *does* declare tools but the model names a function that is not among them, the call is emitted anyway: | request declared | model writes | result today | |---|---|---| | `[some_other_tool]` | a call to `get_indicators` | `tool_calls: [get_indicators]`, content empty | This one is **not** fixed by the guard above, and I want to be precise about why, because the obvious patch does not work. `Service.run` always constructs the parser with streaming on (`server.py:4216`, `stream_tools=True`). With streaming on, the call is consumed by `_scan()` **before** `_finish_call()` runs (`frontend.py:1395-1408`): - `_scan()` hits `<function=NAME>` at `frontend.py:1078-1087`, builds `ToolCall(name=name, arguments={})` with **no membership check** — `self.schemas.get(name)` at `:1085` is used only to read declared parameter *types* — and immediately emits `tool_start`, so the client is already told about the call. - `finish()` (`:1428-1431`) emits the final `tool_call` for that already-announced call. Adding a name check inside `_finish_call` therefore changes nothing observable over the wire: by the time it runs, the `tool_start`/`tool_args` chunks are already on the wire and the client has assembled the call. I confirmed this by measurement — with such a check added, the response carried **both** the text and a `tool_calls` entry. The right place is `_scan()` at the `ss == "name"` step (`:1083`): the name is complete there and nothing has been emitted yet, so an undeclared name can still be refused and the raw text returned as content. That is a real change to the streaming state machine, so I would rather raise it than guess at it. Flagging it as a separate item rather than folding it into the one-line fix above — happy to work on it if you want it in the same PR. --- ## Another observation, not part of the fix `serve/chat_template.jinja:130-157` renders an assistant message's `tool_calls` **unconditionally** — that loop sits *outside* the `{%- if tools ... %}` block at `:72`. So a request that declares no tools, but whose history contains tool-calling turns, puts verbatim tool-call demonstrations into the prompt: ``` <|im_start|>assistant <think> </think> <​tool_call> <function=get_indicators> <parameter=indicator> rsi </parameter> ... </function> </​tool_call><|im_end|> ``` Measured on `swift-1.5-iq3_xxs` with the repo's own tokenizer (`tools/strata_tokenizer.py` over `/data/packs/swift-iq3_xxs/tokenizer`): | conversation | `tools=None` | `tools=[one tool]` | |---|---|---| | 5-message demo (1 historical call) | 396 tokens | 641 tokens (the tools block adds 245) | | the real 13-message incident payload | **7364 tokens, 4 verbatim call demonstrations** | — | The prompt then ends with an **already-opened assistant turn** (`<|im_start|>assistant\n<think>\n\n`), after a final user turn that reads *"Tool call rounds are exhausted. You must not call any more tools. Write the final report now."* Greedy decoding on that context continues the demonstrated pattern. That is expected, and it is not the bug — a model writing `<​tool_call>` after being shown four examples is behaving reasonably. The bug is that **the parser treats the result as a real call**. Worth noting that the reasoning-state equivalent is already handled: a call quoted inside the thinking stays reasoning text (`rcall` at `:1194-1212`, guard at `:1203`/`:1246`). The answer of a non-thinking turn, or the part of a thinking turn after `</think>`, was not. I confirmed that split by measurement: the same XML before `</think>` stays text today; the same XML after it becomes a call. I am not proposing a change here — the history rendering cannot simply be dropped without corrupting the conversation — but the trigger is prompt hygiene, not the weights, so swapping models does not remove it. --- ## What I did not test - Only the `Content` → `call` path was exercised directly. The `rcall` (reasoning) path already gates correctly and was left alone. - No end-to-end run against a live engine for the fix; the regression data above is the parser plus the full serve suite, not a served request. - Vision and MCP paths untouched.
Author
Owner

@riverhh76 commented on GitHub (Oct 18, 2026):

A one-line fix for the first of the three items, in case it saves you the round trip.

The content state simply gates on the declared tools, the way the reasoning state three lines above already does:

--- a/serve/frontend.py
+++ b/serve/frontend.py
@@ -1282,7 +1282,7 @@
                         self.buf = ""
                         return out
                     self.buf, self.lead = stripped, False
-                i = self.buf.find(CALL_START)
+                i = self.buf.find(CALL_START) if self.schemas else -1
                 b, decided = self._bare_opener() if self.recover and self.schemas else (-1, False)
                 if b >= 0 and (i < 0 or b < i):
                     # recover: <function=NAME> alone at the start of a line - the call without its <​tool_call>.

Regression test, next to test_auto_absent_and_none_leave_the_tools_to_the_model:

    def test_a_call_the_request_never_offered_stays_text(self):
        # the model goes on writing the format it was shown in its history; a request that offered no tools must not
        # come back with tool_calls - the answer is text, the call and all
        from serve.frontend import CALL_END, CALL_START
        answer = (CallingEngine.THOUGHT + "</think>\n\n" + "I will check that.\n" + CALL_START +
                  "<function=search>\n<parameter=q>\n2+2\n</parameter>\n</function>\n" + CALL_END +
                  "\nHere is the report.")

        def generate(ids, max_new, sampling, cancel, embeddings=None):
            self.engine.prompts.append(list(ids))
            yield from self.tok.encode(answer) + self.tok.encode("<|im_end|>", parse_special=True)
        self.engine.generate = generate
        for label, extra in {"nothing declared": {"tools": []},
                             "tool_choice none": {"tool_choice": "none"}}.items():
            for stream in (False, True):
                with self.subTest(case=label, stream=stream):
                    self.engine.prompts = []
                    code, b = self.openai(stream=stream, **extra)
                    finish, calls, reasoning = self.call_of(code, b, stream)
                    self.assertEqual((finish, calls), ("stop", []), b)
                    if not stream:                                  # the call is still there, as the text it is
                        content = b["choices"][0]["message"]["content"] or ""
                        self.assertIn("Here is the report.", content)
                        self.assertIn(CALL_START, content)
                        self.assertIn("<function=search>", content)

Measured in the released 0.1.45 container (jinja2 3.1.6), patch and baseline each in its own
scratch tree, /app untouched:

baseline 477ac13c, test added 4 subtests fail — both cases, streaming and not
patched, test added 1 passed, 4 subtests passed
full serve/test_server.py, baseline 337 passed, 482 subtests passed
full serve/test_server.py, patched + test 338 passed, 486 subtests passed

The test drives the HTTP path, so stream_tools=True — the server's only mode — is covered.

Scope: this touches only the :1285 gate. It leaves the two other items alone — the
_scan() streaming gap, where a name check in _finish_call provably does not work because
tool_start is already on the wire by then, and the template rendering. No existing test needed
changing, no snapshot or timing expectation moved.

Behaviour change for the changelog: a tools-less request can now return the <​tool_call> XML as
text in content where it returned tool_calls with an empty content.

Happy to open a PR if you want it — I did not send one, since the few I saw on recent serve/
changes seemed to get closed.

<!-- gh-comment-id:6252713612 --> @riverhh76 commented on GitHub (Oct 18, 2026): A one-line fix for the first of the three items, in case it saves you the round trip. The content state simply gates on the declared tools, the way the reasoning state three lines above already does: ```diff --- a/serve/frontend.py +++ b/serve/frontend.py @@ -1282,7 +1282,7 @@ self.buf = "" return out self.buf, self.lead = stripped, False - i = self.buf.find(CALL_START) + i = self.buf.find(CALL_START) if self.schemas else -1 b, decided = self._bare_opener() if self.recover and self.schemas else (-1, False) if b >= 0 and (i < 0 or b < i): # recover: <function=NAME> alone at the start of a line - the call without its <​tool_call>. ``` Regression test, next to `test_auto_absent_and_none_leave_the_tools_to_the_model`: ```python def test_a_call_the_request_never_offered_stays_text(self): # the model goes on writing the format it was shown in its history; a request that offered no tools must not # come back with tool_calls - the answer is text, the call and all from serve.frontend import CALL_END, CALL_START answer = (CallingEngine.THOUGHT + "</think>\n\n" + "I will check that.\n" + CALL_START + "<function=search>\n<parameter=q>\n2+2\n</parameter>\n</function>\n" + CALL_END + "\nHere is the report.") def generate(ids, max_new, sampling, cancel, embeddings=None): self.engine.prompts.append(list(ids)) yield from self.tok.encode(answer) + self.tok.encode("<|im_end|>", parse_special=True) self.engine.generate = generate for label, extra in {"nothing declared": {"tools": []}, "tool_choice none": {"tool_choice": "none"}}.items(): for stream in (False, True): with self.subTest(case=label, stream=stream): self.engine.prompts = [] code, b = self.openai(stream=stream, **extra) finish, calls, reasoning = self.call_of(code, b, stream) self.assertEqual((finish, calls), ("stop", []), b) if not stream: # the call is still there, as the text it is content = b["choices"][0]["message"]["content"] or "" self.assertIn("Here is the report.", content) self.assertIn(CALL_START, content) self.assertIn("<function=search>", content) ``` Measured in the released 0.1.45 container (jinja2 3.1.6), patch and baseline each in its own scratch tree, `/app` untouched: | | | |---|---| | baseline `477ac13c`, test added | **4 subtests fail** — both cases, streaming and not | | patched, test added | **1 passed, 4 subtests passed** | | full `serve/test_server.py`, baseline | 337 passed, 482 subtests passed | | full `serve/test_server.py`, patched + test | **338 passed, 486 subtests passed** | The test drives the HTTP path, so `stream_tools=True` — the server's only mode — is covered. Scope: this touches **only** the `:1285` gate. It leaves the two other items alone — the `_scan()` streaming gap, where a name check in `_finish_call` provably does not work because `tool_start` is already on the wire by then, and the template rendering. No existing test needed changing, no snapshot or timing expectation moved. Behaviour change for the changelog: a tools-less request can now return the `<​tool_call>` XML as text in `content` where it returned `tool_calls` with an empty `content`. Happy to open a PR if you want it — I did not send one, since the few I saw on recent `serve/` changes seemed to get closed.
Author
Owner

@ctr-137 commented on GitHub (Oct 18, 2026):

Measured on a working checkout of main (Windows, Python 3.14.7, CPU only, no GPU, no model files).

The test. I wrote the missing answer-side test as ForcedToolChoice.test_a_call_the_request_never_offered_stays_text in serve/test_server.py: after </think> the model writes a complete, well-formed call for get_indicators, and the request declares nothing — tools absent, tools: [], and tool_choice: "none", each streamed and not, so 6 subtests. On the unpatched tree all 6 fail with finish_reason: "tool_calls" and empty content; with the guard at serve/frontend.py:1285 all 6 pass.

What the guard does not leave alone. Two existing tests assert the opposite, so the one line is a behaviour change, not a fix:

  • serve/test_mcp.py:329 (test_plain_requests_get_no_mcp_tools) — a request that declares no tools, the model writes a call, and the test asserts finish_reason == "tool_calls", with the comment "returned to the client as always". With the guard it becomes stop.
  • serve/test_parser_call_scan.py:56 (test_no_structural_rescans_until_closer_and_reset_for_next_call) — a parser built with no tools is expected to enter the call state and reach call_end once. With the guard the scan never starts, so the count is 0 instead of 1.

Full serve suite on this machine:

result
baseline 848 tests, 1 failure + 1 error (test_winjob, test_keepawake — Windows/timing, unrelated to this)
guard + new test 849 tests, the same 2 plus the 2 above

So I cannot reproduce the clean run you measured in the 0.1.45 image. Which behaviour is intended here? If the guard is the rule, those two tests have to be rewritten, and the change stops being a one-liner: it decides what the content state does with a call for a tool the request never offered. I would rather ask than quietly flip those two expectations. The test is ready in my working tree — with a decision I can open the PR with the guard, the test and the two adjusted expectations in one change.

<!-- gh-comment-id:6254752209 --> @ctr-137 commented on GitHub (Oct 18, 2026): Measured on a working checkout of `main` (Windows, Python 3.14.7, CPU only, no GPU, no model files). **The test.** I wrote the missing answer-side test as `ForcedToolChoice.test_a_call_the_request_never_offered_stays_text` in `serve/test_server.py`: after `</think>` the model writes a complete, well-formed call for `get_indicators`, and the request declares nothing — `tools` absent, `tools: []`, and `tool_choice: "none"`, each streamed and not, so 6 subtests. On the unpatched tree all 6 fail with `finish_reason: "tool_calls"` and empty content; with the guard at `serve/frontend.py:1285` all 6 pass. **What the guard does not leave alone.** Two existing tests assert the opposite, so the one line is a behaviour change, not a fix: - `serve/test_mcp.py:329` (`test_plain_requests_get_no_mcp_tools`) — a request that declares no tools, the model writes a call, and the test asserts `finish_reason == "tool_calls"`, with the comment *"returned to the client as always"*. With the guard it becomes `stop`. - `serve/test_parser_call_scan.py:56` (`test_no_structural_rescans_until_closer_and_reset_for_next_call`) — a parser built with no tools is expected to enter the call state and reach `call_end` once. With the guard the scan never starts, so the count is 0 instead of 1. Full `serve` suite on this machine: | | result | |---|---| | baseline | 848 tests, 1 failure + 1 error (`test_winjob`, `test_keepawake` — Windows/timing, unrelated to this) | | guard + new test | 849 tests, the same 2 plus the 2 above | So I cannot reproduce the clean run you measured in the 0.1.45 image. Which behaviour is intended here? If the guard is the rule, those two tests have to be rewritten, and the change stops being a one-liner: it decides what the content state does with a call for a tool the request never offered. I would rather ask than quietly flip those two expectations. The test is ready in my working tree — with a decision I can open the PR with the guard, the test and the two adjusted expectations in one change.
Author
Owner

@riverhh76 commented on GitHub (Oct 19, 2026):

You are right, and my verification was too narrow. Thank you for catching it before this became a PR.

What I got wrong. I ran serve/test_server.py alone (337 passed) and called it the suite. serve/ holds 49 test files and 848 tests. Re-run on a checkout of main @ 477ac13c, CPU only:

tree full serve suite
baseline 848 tests — 1 failed, 835 passed, 12 skipped, 10499 subtests passed
with the :1285 guard 849 tests — 3 failed, 833 passed, 12 skipped, 10499 subtests passed
with a name check in _finish_call only (no gate) 848 tests — 1 failed, 835 passed, 12 skipped, 10499 subtests passed

The baseline failure is test_server.py::SilentEngine::test_a_busy_gpu_is_not_a_frozen_engine; it passes when run alone and failed only while the machine was busy. It is not related. (The third row's single failure is not that one — see the last section.)

Your two, and a third you did not list. The guard fails three tests, not two:

  • serve/test_mcp.py:329 test_plain_requests_get_no_mcp_tools — yours
  • serve/test_parser_call_scan.py:56 test_no_structural_rescans_until_closer_and_reset_for_next_call — yours
  • serve/test_responses.py:687 test_the_kept_tools_shape_only_the_prompt — not in your list, and its comment is the most explicit of the three: "the calls come back as for any request without tools: no namespace, no custom tool"

So the pass-through is written down in two protocols (Chat Completions' MCP path and the Responses/Codex path) and three tests, one dating to 2026-09-28. I am withdrawing the guard. Asking you to flip three written expectations to land a one-liner is the wrong trade, and I no longer think this is an oversight.

One distinction on your second test. test_parser_call_scan.py is a re-scan test: it counts call_end walks to prove a long body is not rescanned. It builds OutputParser(thinking=False) with no tools because that is the shortest constructor, not because it asserts anything about tools. Give it the tool it actually writes and it passes under the guard:

parser = frontend.OutputParser(thinking=False,
                               tools=[{"name": "write", "parameters": {"properties": {"text": {"type": "string"}}}}])

2 passed. So that one is a test that never declared the tool it uses — only test_mcp.py:329 and test_responses.py:687 are behaviour assertions.

Which behaviour is intended — what I can measure. The two states are exactly opposite today, and each side has its own tests. Measured on OutputParser at 477ac13c, streamed and whole:

the model writes, after </think> (content) upstream main test
a call, no tools declared tool_calls test_mcp.py:329, test_responses.py:687
a call for an undeclared name, tools declared tool_calls none
the same call, inside the reasoning upstream main test
a call, no tools declared reasoning text test_reasoning_tools.py:62, test_reasoning_rescue.py:155
a call for an undeclared name, tools declared reasoning text test_reasoning_tools.py:53, test_reasoning_rescue.py:162

The content JSON path (:927/:934, test_server.py:1105) and the content recovery path (:1286, :1305, test_frontend.py:336) also keep an undeclared name as text. So #804's rule — a tool call counts only for a declared tool — holds in the reasoning state (the :1246 gate plus the :1203 membership check), in the content JSON path, and in the content recovery path. The content structural path (:1285, _finish_call at :1451) is the only one where neither the gate nor the name is checked.

If the answer is the content state hands back whatever the model wrote, that is coherent, my issue's headline is wrong, and I will close it — the two states would simply be meant to differ. If the answer is #804's rule, the undeclared-name row is the part to change, and the no-tools rows above stay exactly as they are.

Two things to know before choosing the second. I tried the narrow version — a name check in _finish_call (:1451) only, no gate at :1285 — and it is neither sufficient nor free.

It is not sufficient. server.py:4216 builds every parser with stream_tools=True, so _scan() has already emitted tool_start at :1087 by the time _finish_call runs. Measured, tools declared and a call for another name:

whole response streamed
the call text (fixed) 5 tool_start/tool_args events and then the same body as text

The client is told a call started, is given its deltas, and then the same body arrives as content — worse than either answer on its own. _scan has to be gated too.

And it is not free. name in self.schemas is the wrong test, because the name on the wire is not always a schemas key. See test_responses.py:520 test_namespace_call_written_with_double_underscore: Codex declares a namespace tool named mcp__websearch holding web_search, and Qwen writes the call as the flat <function=mcp__websearch__web_search>. responses.py:254 offers the template mcp__websearch.web_search (dot form) and maps that spelling back, then :271 deliberately adds the underscore spelling to the name map without adding it to the tools — with the comment "Qwen writes Codex's MCP tools as mcp__server__tool (the flat name it learned), not mcp__server.tool: map that spelling back as well". So the underscore form is in names and by design not in schemas.

With the check added, the full serve suite still reports one failure — but it is a different one: the busy-machine timing test passes, and test_responses.py:520 fails instead. The check rejects a call that path exists to accept. Measured in both trees on the same machine.

So the check cannot be schemas membership; it has to go through the resolution the protocol itself uses. Which is your point exactly: this decides what the content state does with a call for a tool the request never offered, and it is a decision rather than a one-liner.

Offered: whichever you pick, the undeclared-name row has no coverage in any path today, and it is worth having either way — as a "stays text" test or as a "still comes back" one. Say which and I will write it.

<!-- gh-comment-id:6263561962 --> @riverhh76 commented on GitHub (Oct 19, 2026): You are right, and my verification was too narrow. Thank you for catching it before this became a PR. **What I got wrong.** I ran `serve/test_server.py` alone (337 passed) and called it the suite. `serve/` holds 49 test files and 848 tests. Re-run on a checkout of `main` @ `477ac13c`, CPU only: | tree | full `serve` suite | |---|---| | baseline | 848 tests — **1 failed**, 835 passed, 12 skipped, 10499 subtests passed | | with the `:1285` guard | 849 tests — **3 failed**, 833 passed, 12 skipped, 10499 subtests passed | | with a name check in `_finish_call` only (no gate) | 848 tests — **1 failed**, 835 passed, 12 skipped, 10499 subtests passed | The baseline failure is `test_server.py::SilentEngine::test_a_busy_gpu_is_not_a_frozen_engine`; it passes when run alone and failed only while the machine was busy. It is not related. (The third row's single failure is not that one — see the last section.) **Your two, and a third you did not list.** The guard fails three tests, not two: - `serve/test_mcp.py:329` `test_plain_requests_get_no_mcp_tools` — yours - `serve/test_parser_call_scan.py:56` `test_no_structural_rescans_until_closer_and_reset_for_next_call` — yours - `serve/test_responses.py:687` `test_the_kept_tools_shape_only_the_prompt` — **not in your list**, and its comment is the most explicit of the three: *"the calls come back as for any request without tools: no namespace, no custom tool"* So the pass-through is written down in two protocols (Chat Completions' MCP path and the Responses/Codex path) and three tests, one dating to 2026-09-28. **I am withdrawing the guard.** Asking you to flip three written expectations to land a one-liner is the wrong trade, and I no longer think this is an oversight. **One distinction on your second test.** `test_parser_call_scan.py` is a re-scan test: it counts `call_end` walks to prove a long body is not rescanned. It builds `OutputParser(thinking=False)` with no tools because that is the shortest constructor, not because it asserts anything about tools. Give it the tool it actually writes and it passes under the guard: ```python parser = frontend.OutputParser(thinking=False, tools=[{"name": "write", "parameters": {"properties": {"text": {"type": "string"}}}}]) ``` `2 passed`. So that one is a test that never declared the tool it uses — only `test_mcp.py:329` and `test_responses.py:687` are behaviour assertions. **Which behaviour is intended — what I can measure.** The two states are exactly opposite today, and each side has its own tests. Measured on `OutputParser` at `477ac13c`, streamed and whole: | the model writes, after `</think>` (content) | upstream `main` | test | |---|---|---| | a call, **no tools declared** | `tool_calls` | `test_mcp.py:329`, `test_responses.py:687` | | a call for an **undeclared name**, tools declared | `tool_calls` | **none** | | the same call, inside the reasoning | upstream `main` | test | |---|---|---| | a call, **no tools declared** | reasoning text | `test_reasoning_tools.py:62`, `test_reasoning_rescue.py:155` | | a call for an **undeclared name**, tools declared | reasoning text | `test_reasoning_tools.py:53`, `test_reasoning_rescue.py:162` | The content JSON path (`:927`/`:934`, `test_server.py:1105`) and the content recovery path (`:1286`, `:1305`, `test_frontend.py:336`) also keep an undeclared name as text. So #804's rule — *a tool call counts only for a declared tool* — holds in the reasoning state (the `:1246` gate plus the `:1203` membership check), in the content JSON path, and in the content recovery path. The content **structural** path (`:1285`, `_finish_call` at `:1451`) is the only one where neither the gate nor the name is checked. If the answer is *the content state hands back whatever the model wrote*, that is coherent, my issue's headline is wrong, and I will close it — the two states would simply be meant to differ. If the answer is #804's rule, the undeclared-name row is the part to change, and the no-tools rows above stay exactly as they are. **Two things to know before choosing the second.** I tried the narrow version — a name check in `_finish_call` (`:1451`) only, no gate at `:1285` — and it is neither sufficient nor free. *It is not sufficient.* `server.py:4216` builds every parser with `stream_tools=True`, so `_scan()` has already emitted `tool_start` at `:1087` by the time `_finish_call` runs. Measured, tools declared and a call for another name: | | whole response | streamed | |---|---|---| | the call | text (fixed) | 5 `tool_start`/`tool_args` events **and then** the same body as text | The client is told a call started, is given its deltas, and then the same body arrives as content — worse than either answer on its own. `_scan` has to be gated too. *And it is not free.* `name in self.schemas` is the wrong test, because the name on the wire is not always a `schemas` key. See `test_responses.py:520` `test_namespace_call_written_with_double_underscore`: Codex declares a namespace tool named `mcp__websearch` holding `web_search`, and Qwen writes the call as the flat `<function=mcp__websearch__web_search>`. `responses.py:254` offers the template `mcp__websearch.web_search` (dot form) and maps that spelling back, then `:271` deliberately adds the **underscore** spelling to the name map *without* adding it to the tools — with the comment *"Qwen writes Codex's MCP tools as `mcp__server__tool` (the flat name it learned), not `mcp__server.tool`: map that spelling back as well"*. So the underscore form is in `names` and by design not in `schemas`. With the check added, the full `serve` suite still reports one failure — but it is a different one: the busy-machine timing test passes, and `test_responses.py:520` fails instead. The check rejects a call that path exists to accept. Measured in both trees on the same machine. So the check cannot be `schemas` membership; it has to go through the resolution the protocol itself uses. Which is your point exactly: this decides what the content state does with a call for a tool the request never offered, and it is a decision rather than a one-liner. **Offered:** whichever you pick, the undeclared-name row has no coverage in any path today, and it is worth having either way — as a "stays text" test or as a "still comes back" one. Say which and I will write it.
Author
Owner

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

Thanks for taking the time to report this.

We're resetting the tracker for 0.2.0-beta. There are more than 1,300 open issues and pull requests, too many for us to read properly, so we're closing everything that isn't being worked on right now. Closed here does not mean rejected.

To reopen it takes about two minutes:

  1. Re-test on 0.2.0-beta. It may already be fixed. Write down what you see.
  2. Start the title with its area: [Engine], [GUI], [TUI], [Benchmark], [Docs] or [Other].
  3. Fill in the parts of the issue form: what happened, the Strata version, your graphics card, memory and system.
  4. Comment /reopen. A check runs and either reopens the issue or lists what is still missing.

The rules are in CONTRIBUTING.md.

<!-- gh-comment-id:6271459622 --> @Niko1221 commented on GitHub (Oct 19, 2026): Thanks for taking the time to report this. We're resetting the tracker for 0.2.0-beta. There are more than 1,300 open issues and pull requests, too many for us to read properly, so we're closing everything that isn't being worked on right now. Closed here does not mean rejected. To reopen it takes about two minutes: 1. Re-test on 0.2.0-beta. It may already be fixed. Write down what you see. 2. Start the title with its area: [Engine], [GUI], [TUI], [Benchmark], [Docs] or [Other]. 3. Fill in the parts of the issue form: what happened, the Strata version, your graphics card, memory and system. 4. Comment `/reopen`. A check runs and either reopens the issue or lists what is still missing. The rules are in [CONTRIBUTING.md](https://github.com/Niko1221/Strata/blob/main/CONTRIBUTING.md).
Author
Owner

@riverhh76 commented on GitHub (Oct 20, 2026):

Re-test on 0.2.1, per the tracker reset

Re-tested on 0.2.1 (engine 0.1.46) on 2× RTX A5000 (sm_86), as step 1 of the reset asks. It is still there, and the local sources show why: the rule that #804 added to the reasoning state is missing from the content state.

What happens

A request that declares no tools ("tools": []) sends back a tool_calls array when the model writes a call in its answer. The answer text is lost: content comes back as "". The same call written inside <think> is left alone as text.

where the model writes the call tools declared finish_reason tool_calls content
inside <think> no (tools: []) stop 0 the call, as text ✅
inside <think> yes tool_calls 1 "" ✅
in the answer no (tools: []) tool_calls 1 "" ❌
in the answer yes tool_calls 1 "" ✅

So one and the same undeclared call is text or a call depending only on whether it lands before or after </think>. "tool_choice": "none" behaves the same way (the request is rewritten to tools = None at serve/server.py:6695): 4 of 4 combinations (two cases × streaming and not) come back tool_calls.

Where

serve/frontend.py, OutputParser.feed() — two states, each scanning for <tool_call>:

line state code
1246 reasoning tool = self.buf.find(CALL_START) if self.schemas else -1
1285 content i = self.buf.find(CALL_START) — no schemas gate

1246 was added by 8d0bb446 (2026-10-05) for #804, "a tool call inside the reasoning counts only for a declared tool". serve/frontend.py has no changes between 477ac13c (0.1.45) and v0.2.1, which is why this reproduces on both.

Smallest reproduction

One request, no tools. The model keeps writing the call format it was shown in its history — the same thing the test's CallingEngine fakes, only through the ordinary HTTP path:

hist = [{"role": "user", "content": "Search for 3+3."},
        {"role": "assistant", "content": "",
         "tool_calls": [{"id": "c1", "type": "function",
                         "function": {"name": "search", "arguments": "{\"q\": \"3+3\"}"}}]},
        {"role": "tool", "tool_call_id": "c1", "content": "6"}]
body = {"messages": hist + [{"role": "user", "content": "Now search for 2+2."}],
        "tools": [], "temperature": 0, "stream": False}

Reply: finish_reason: "tool_calls", one call, content: "". Expected: finish_reason: "stop" with the call left in content as text — which is what the reasoning state already does.

A note on what does not reproduce it: asking the model to "search the web for 2+2" gives 2 + 2 = 4 as text and no call at all (0 of 4) — the format has to be in its history, or the request has to ask for the call in the thinking block. Assistant prefill is ignored by the engine. So the history above is not decoration; without it there is nothing to mis-parse.

Reproducible?

Yes — 4 of 4 (the two no-tools cases, streaming and not) on 0.2.1, and the same on 0.1.45. The "written in the answer / written in the thinking" pair above is the one that shows the inconsistency.

Version, hardware, model

  • Strata 0.2.1, engine 0.1.46, served from the official 0.2.1-cuda13 image.
  • 2× RTX A5000 24 GB (sm_86), 124 GB RAM, Linux (driver 595.80), --layer-split 28, --kv int8 --kv-resident 32768, --spec 6 with MTP.
  • Model: Qwen3.8-Flash-Next Swift 1.5 IQ3_XXS. Reproduced on 0.1.45 with the same model and flags.

The question

Is the content state meant to follow #804?

  • If yes, the gate at 1285 is the same one-liner as at 1246, and this closes #3075 as originally reported.
  • If the content state is meant to parse calls regardless — a model that writes a call in its answer is "acting", not quoting — then the reasoning gate should say so too. Either way the two states disagree today, and the answer a client gets depends on where the model put the tag.

I am not asking for a particular policy, only that the two paths agree. Happy to open a PR with the one-line gate plus the test from my earlier comment if you want it.

<!-- gh-comment-id:6293843875 --> @riverhh76 commented on GitHub (Oct 20, 2026): ## Re-test on 0.2.1, per the tracker reset Re-tested on **0.2.1 (engine 0.1.46)** on 2× RTX A5000 (sm_86), as step 1 of the reset asks. It is still there, and the local sources show why: the rule that **#804** added to the reasoning state is missing from the content state. ### What happens A request that declares **no** tools (`"tools": []`) sends back a `tool_calls` array when the model writes a call in its answer. The answer text is lost: `content` comes back as `""`. The same call written inside `<think>` is left alone as text. | where the model writes the call | `tools` declared | `finish_reason` | `tool_calls` | `content` | |---|---|---|---|---| | inside `<think>` | no (`tools: []`) | `stop` | **0** | the call, as text ✅ | | inside `<think>` | yes | `tool_calls` | 1 | `""` ✅ | | **in the answer** | **no** (`tools: []`) | **`tool_calls`** | **1** | **`""`** ❌ | | in the answer | yes | `tool_calls` | 1 | `""` ✅ | So one and the same undeclared call is text or a call depending only on whether it lands before or after `</think>`. `"tool_choice": "none"` behaves the same way (the request is rewritten to `tools = None` at `serve/server.py:6695`): 4 of 4 combinations (two cases × streaming and not) come back `tool_calls`. ### Where `serve/frontend.py`, `OutputParser.feed()` — two states, each scanning for `<tool_call>`: | line | state | code | |---|---|---| | 1246 | `reasoning` | `tool = self.buf.find(CALL_START) if self.schemas else -1` | | 1285 | `content` | `i = self.buf.find(CALL_START)` — no `schemas` gate | 1246 was added by **`8d0bb446`** (2026-10-05) for #804, *"a tool call inside the reasoning counts only for a declared tool"*. `serve/frontend.py` has **no changes** between `477ac13c` (0.1.45) and `v0.2.1`, which is why this reproduces on both. ### Smallest reproduction One request, no tools. The model keeps writing the call format it was shown in its history — the same thing the test's `CallingEngine` fakes, only through the ordinary HTTP path: ```python hist = [{"role": "user", "content": "Search for 3+3."}, {"role": "assistant", "content": "", "tool_calls": [{"id": "c1", "type": "function", "function": {"name": "search", "arguments": "{\"q\": \"3+3\"}"}}]}, {"role": "tool", "tool_call_id": "c1", "content": "6"}] body = {"messages": hist + [{"role": "user", "content": "Now search for 2+2."}], "tools": [], "temperature": 0, "stream": False} ``` Reply: `finish_reason: "tool_calls"`, one call, `content: ""`. Expected: `finish_reason: "stop"` with the call left in `content` as text — which is what the reasoning state already does. **A note on what does *not* reproduce it:** asking the model to "search the web for 2+2" gives `2 + 2 = 4` as text and no call at all (0 of 4) — the format has to be in its history, or the request has to ask for the call in the thinking block. Assistant prefill is ignored by the engine. So the history above is not decoration; without it there is nothing to mis-parse. ### Reproducible? Yes — 4 of 4 (the two no-tools cases, streaming and not) on 0.2.1, and the same on 0.1.45. The "written in the answer / written in the thinking" pair above is the one that shows the inconsistency. ### Version, hardware, model - Strata **0.2.1**, engine **0.1.46**, served from the official `0.2.1-cuda13` image. - 2× RTX A5000 24 GB (sm_86), 124 GB RAM, Linux (driver 595.80), `--layer-split 28`, `--kv int8 --kv-resident 32768`, `--spec 6` with MTP. - Model: Qwen3.8-Flash-Next Swift 1.5 IQ3_XXS. Reproduced on 0.1.45 with the same model and flags. ### The question Is the content state meant to follow #804? - **If yes**, the gate at 1285 is the same one-liner as at 1246, and this closes #3075 as originally reported. - **If the content state is meant to parse calls regardless** — a model that writes a call in its answer is "acting", not quoting — then the reasoning gate should say so too. Either way the two states disagree today, and the answer a client gets depends on where the model put the tag. I am not asking for a particular policy, only that the two paths agree. Happy to open a PR with the one-line gate plus the test from my earlier comment if you want it.
Author
Owner

@riverhh76 commented on GitHub (Oct 20, 2026):

/reopen

<!-- gh-comment-id:6293845947 --> @riverhh76 commented on GitHub (Oct 20, 2026): /reopen
Author
Owner

@github-actions[bot] commented on GitHub (Oct 20, 2026):

Not reopened yet. Still missing:

  • Start the title with its area: [Engine], [GUI], [TUI], [Benchmark], [Docs] or [Other], then a short description. Example: "[Engine] decode stops after 2 minutes".
  • Re-test on Strata 0.2.0-beta and name that version in the issue. If it no longer happens, say so in a comment instead.

Edit the issue and comment /reopen again. Details: CONTRIBUTING.md

<!-- gh-comment-id:6293849259 --> @github-actions[bot] commented on GitHub (Oct 20, 2026): Not reopened yet. Still missing: - [ ] Start the title with its area: [Engine], [GUI], [TUI], [Benchmark], [Docs] or [Other], then a short description. Example: "[Engine] decode stops after 2 minutes". - [ ] Re-test on Strata 0.2.0-beta and name that version in the issue. If it no longer happens, say so in a comment instead. Edit the issue and comment `/reopen` again. Details: [CONTRIBUTING.md](https://github.com/Niko1221/Strata/blob/main/CONTRIBUTING.md)
Author
Owner

@riverhh76 commented on GitHub (Oct 20, 2026):

/reopen

<!-- gh-comment-id:6293872260 --> @riverhh76 commented on GitHub (Oct 20, 2026): /reopen
Author
Owner

@github-actions[bot] commented on GitHub (Oct 20, 2026):

Reopened, thank you. A maintainer will pick it up from here.

<!-- gh-comment-id:6293878991 --> @github-actions[bot] commented on GitHub (Oct 20, 2026): Reopened, thank you. A maintainer will pick it up from here.
Author
Owner

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

Fixed for 0.2.2, the next release (not out yet). For Chat Completions and /v1/messages a call counts only for a tool the request declared, with or without tools, before or after </think>. The Responses route keeps returning calls from a request without tools because Codex's compaction request relies on it.

<!-- gh-comment-id:6308090278 --> @Niko1221 commented on GitHub (Oct 21, 2026): Fixed for 0.2.2, the next release (not out yet). For Chat Completions and /v1/messages a call counts only for a tool the request declared, with or without tools, before or after `</think>`. The Responses route keeps returning calls from a request without tools because Codex's compaction request relies on it.
Author
Owner

@riverhh76 commented on GitHub (Oct 21, 2026):

Thanks — that answers the question. We'll re-run the same four cases on 0.2.2 and report back here, then close it if the content path keeps the undeclared call as text.

<!-- gh-comment-id:6318511960 --> @riverhh76 commented on GitHub (Oct 21, 2026): Thanks — that answers the question. We'll re-run the same four cases on 0.2.2 and report back here, then close it if the content path keeps the undeclared call as text.
Author
Owner

@riverhh76 commented on GitHub (Oct 21, 2026):

Tested on 0.2.2 (image strata:0.2.2-cuda13, engine 0.1.47) — same requests, only the version changed.

# where the <tool_call> is written tools declared 0.2.1 0.2.2
1 reasoning no stop, 0 calls, kept as text stop, 0 calls, kept in reasoning_content
2 reasoning yes tool_calls, 1 tool_calls, 1
3 content no tool_calls, 1 stop, 0 calls, kept as text
4 content yes tool_calls, 1 tool_calls, 1

Row 3 is the case from the report, and it now behaves as expected — 5/5 runs, the call stays
plain text and nothing is synthesised.

tool_choice: "none" (server rewrites to tools = None) on the same content-path prompt:
stop with the call left as text, both stream: false and stream: true
(0.2.1 returned tool_calls for both).

No collateral damage here: 19/19 tool-call cases still pass with zero direction changes vs
0.2.1, including the two "must not call" cases (chit-chat, 1+1) which still return
tool_calls: []; a "quoted tool call in prose" probe is still 5/5.

Thanks for the quick fix — closing.

<!-- gh-comment-id:6321916800 --> @riverhh76 commented on GitHub (Oct 21, 2026): Tested on 0.2.2 (image `strata:0.2.2-cuda13`, engine 0.1.47) — same requests, only the version changed. | # | where the `<tool_call>` is written | `tools` declared | 0.2.1 | 0.2.2 | |---|---|---|---|---| | 1 | reasoning | no | `stop`, 0 calls, kept as text | `stop`, 0 calls, kept in `reasoning_content` | | 2 | reasoning | yes | `tool_calls`, 1 | `tool_calls`, 1 | | 3 | **content** | **no** | **`tool_calls`, 1** | **`stop`, 0 calls, kept as text** | | 4 | content | yes | `tool_calls`, 1 | `tool_calls`, 1 | Row 3 is the case from the report, and it now behaves as expected — 5/5 runs, the call stays plain text and nothing is synthesised. `tool_choice: "none"` (server rewrites to `tools = None`) on the same content-path prompt: `stop` with the call left as text, both `stream: false` and `stream: true` (0.2.1 returned `tool_calls` for both). No collateral damage here: 19/19 tool-call cases still pass with zero direction changes vs 0.2.1, including the two "must not call" cases (chit-chat, `1+1`) which still return `tool_calls: []`; a "quoted tool call in prose" probe is still 5/5. Thanks for the quick fix — closing.
Author
Owner

@achanbaka commented on GitHub (Oct 25, 2026):

Same class, fourth client: DeepSeek Harness (DSH) PTC / non-PTC — with before/after evidence that returning the call was the client's recovery mechanism

Adding data from a fourth client, plus run evidence across the upgrade that explains why this is not just "prompt the model better": for this client class the pre-0.2.2 behavior was the recovery mechanism, and we verified that delivering the same block as tool_calls restores it.

Setup

DeepSeek Harness (DSH) has an agent preset ("PTC mode") whose request declares exactly one function, run_code; the real tools are described in the system prompt and are supposed to be called from inside that program. Model: Qwen3.8-Flash-Next IQ3_XXS. Strata: 0.2.6 line / engine 0.1.50 (Qwen engine), /v1/chat/completions, streaming and non-streaming. Intermittently the model calls those tools directly by name (web_search, glob, pwsh, …), which lands exactly in the undeclared-name path.

DSH's tool layer already treats a call to a "visible but collapsed" tool as a deterministic error result (it is not executed):

only run_code is callable directly — call web_search from inside a run_code program instead

A genuinely unknown name gets unknown tool "…". Either way the agent loop continues and the model corrects itself — but only if the engine hands the call over.

Before / after the upgrade (same client, model and endpoint)

period client-visible direct calls to undeclared tools client-side corrective tool results raw-XML answers
pre-0.2.2 (engine ≤ 0.1.46 line) delivered as tool_calls (web_search, glob, pwsh, …) 12 / 7 / 3 in three sessions 0
engine 0.1.50 (0.2.6 line) none — diverted to content 0 2 sessions, 5 complete blocks, finish_reason: "stop"

After the upgrade the leaked block stayed in history and the model imitated it on the next turn (same self-reinforcing pattern as #3441).

Same failure in non-PTC mode, with all real tools declared

While an MCP server was being set up but was not yet mounted, a request declared its 79 native tools and none from that server (no mcp__* in tools; no --mcp child process). The model wrote a well-formed call for a name it invented from documentation it had been reading:

<tool_call>
<function=mcp__cordis__cordis_inspect_query_39e28c4b>
<parameter=method>Config.listConfigs</parameter>
...
</tool_call>

That name appears nowhere in the session or its configuration — it is a hallucinated tool name, which is the same undeclared-name path. Result: the block as content, finish_reason: "stop", turn over. Had it been delivered, the client would have answered "unknown tool" and the model would have continued.

Deterministic reproduction on engine 0.1.50

Force the exact block for web_search while only run_code is declared (same technique as the #3441 repro, no model drift needed):

curl -s http://127.0.0.1:8080/v1/chat/completions -H 'Content-Type: application/json' -d '{
  "model": "<model>",
  "messages": [{"role": "user", "content": "Output ONLY this text. No code fence.\n<tool_call>\n<function=web_search>\n<parameter=queries>\n[\"x\"]\n</parameter>\n</function>\n</tool_call>"}],
  "tools": [{"type": "function", "function": {"name": "run_code", "parameters": {"type": "object", "properties": {"code": {"type": "string"}}, "required": ["code"]}}}],
  "temperature": 0, "max_tokens": 512, "stream": false
}'

Actual: content = the whole block, no tool_calls, finish_reason: "stop", plus the server line
[strata] 1 <tool_call> block(s) in the answer did not read as a call of a declared tool and went back as text …; the names the model wrote: web_search.

Control: adding web_search to tools in the same request returns finish_reason: "tool_calls", one correct tool_calls entry, empty content. So the block itself is well formed — this is not the #3441 malformed-opener case; only the declared-name check diverts it. The same rule serves /v1/messages (declared_only=True in the server); /v1/responses differs only for requests that declare no tools.

Client-side recovery validated

We delivered the identical block as a normal tool_calls entry (temporary client-side shim): the client answered Error: unknown tool "mcp__livecheck__ping" and the model continued to a normal final answer in the same turn — no raw XML. That is exactly what pre-0.2.2 did, and it confirms that the missing piece is delivery, not a client capability. We removed the shim; it was only to validate the recovery path.

Proposal (same as the OP; one concrete shape)

  • Request-level opt-in, e.g. "strata_tool_call_compat": true (name TBD; matches strata_mcp / return_progress). When the request declares at least one tool, a well-formed <tool_call><function=NAME>… whose NAME is not declared is returned as a normal tool_calls entry (arguments parsed as strings when no schema exists). Default false = exactly today's behavior, so #3075 stays the default; requests with no tools keep returning text; the Responses route unchanged.
  • Or the machine-readable rejected_tool_calls field in the response / final SSE chunk (names only), so a client can drive its own retry. For DSH that needs an extra client-side loop; the call-as-tool_calls path needs none.
  • Related to #4071: the unread warning exists but only on stdout, so clients behind a proxy cannot see it; a response field would make the event actionable.

Scope / safety

  • Default stays declared-only; opt-in only.
  • No-tools requests keep the #3075 behavior unconditionally.
  • Opt-in must be documented as "for agent clients that validate tool names and answer with a tool error"; a client that blindly executes tool_calls should not enable it.
  • The engine already detects and counts these blocks (and names them in the log since 0.2.3); the missing part is making that fact deliverable to the client.

Reproduction status: reproduced locally (deterministic API repro on engine 0.1.50, stream and non-stream), observed in real sessions before and after the upgrade, observed in non-PTC mode with all real tools declared, and client-side recovery validated.

Related: #3883, #4071, #3441, #3075.

<!-- gh-comment-id:6400918213 --> @achanbaka commented on GitHub (Oct 25, 2026): ## Same class, fourth client: DeepSeek Harness (DSH) PTC / non-PTC — with before/after evidence that returning the call was the client's recovery mechanism Adding data from a fourth client, plus run evidence across the upgrade that explains why this is not just "prompt the model better": for this client class the pre-0.2.2 behavior was the recovery mechanism, and we verified that delivering the same block as `tool_calls` restores it. ### Setup DeepSeek Harness (DSH) has an agent preset ("PTC mode") whose request declares exactly one function, `run_code`; the real tools are described in the system prompt and are supposed to be called from inside that program. Model: Qwen3.8-Flash-Next IQ3_XXS. Strata: **0.2.6 line / engine 0.1.50** (Qwen engine), `/v1/chat/completions`, streaming and non-streaming. Intermittently the model calls those tools directly by name (`web_search`, `glob`, `pwsh`, …), which lands exactly in the undeclared-name path. DSH's tool layer already treats a call to a "visible but collapsed" tool as a deterministic error result (it is not executed): > only `run_code` is callable directly — call `web_search` from inside a `run_code` program instead A genuinely unknown name gets `unknown tool "…"`. Either way the agent loop continues and the model corrects itself — but only if the engine hands the call over. ### Before / after the upgrade (same client, model and endpoint) | period | client-visible direct calls to undeclared tools | client-side corrective tool results | raw-XML answers | |---|---|---|---| | pre-0.2.2 (engine ≤ 0.1.46 line) | delivered as `tool_calls` (`web_search`, `glob`, `pwsh`, …) | 12 / 7 / 3 in three sessions | 0 | | engine 0.1.50 (0.2.6 line) | none — diverted to content | 0 | 2 sessions, 5 complete blocks, `finish_reason: "stop"` | After the upgrade the leaked block stayed in history and the model imitated it on the next turn (same self-reinforcing pattern as #3441). ### Same failure in non-PTC mode, with all real tools declared While an MCP server was being set up but was not yet mounted, a request declared its 79 native tools and none from that server (no `mcp__*` in `tools`; no `--mcp` child process). The model wrote a well-formed call for a name it invented from documentation it had been reading: ``` <tool_call> <function=mcp__cordis__cordis_inspect_query_39e28c4b> <parameter=method>Config.listConfigs</parameter> ... </tool_call> ``` That name appears nowhere in the session or its configuration — it is a hallucinated tool name, which is the same undeclared-name path. Result: the block as content, `finish_reason: "stop"`, turn over. Had it been delivered, the client would have answered "unknown tool" and the model would have continued. ### Deterministic reproduction on engine 0.1.50 Force the exact block for `web_search` while only `run_code` is declared (same technique as the #3441 repro, no model drift needed): ```bash curl -s http://127.0.0.1:8080/v1/chat/completions -H 'Content-Type: application/json' -d '{ "model": "<model>", "messages": [{"role": "user", "content": "Output ONLY this text. No code fence.\n<tool_call>\n<function=web_search>\n<parameter=queries>\n[\"x\"]\n</parameter>\n</function>\n</tool_call>"}], "tools": [{"type": "function", "function": {"name": "run_code", "parameters": {"type": "object", "properties": {"code": {"type": "string"}}, "required": ["code"]}}}], "temperature": 0, "max_tokens": 512, "stream": false }' ``` Actual: `content` = the whole block, no `tool_calls`, `finish_reason: "stop"`, plus the server line `[strata] 1 <tool_call> block(s) in the answer did not read as a call of a declared tool and went back as text …; the names the model wrote: web_search`. Control: adding `web_search` to `tools` in the same request returns `finish_reason: "tool_calls"`, one correct `tool_calls` entry, empty content. So the block itself is well formed — this is not the #3441 malformed-opener case; only the declared-name check diverts it. The same rule serves `/v1/messages` (`declared_only=True` in the server); `/v1/responses` differs only for requests that declare no tools. ### Client-side recovery validated We delivered the identical block as a normal `tool_calls` entry (temporary client-side shim): the client answered `Error: unknown tool "mcp__livecheck__ping"` and the model continued to a normal final answer in the same turn — no raw XML. That is exactly what pre-0.2.2 did, and it confirms that the missing piece is delivery, not a client capability. We removed the shim; it was only to validate the recovery path. ### Proposal (same as the OP; one concrete shape) - **Request-level opt-in**, e.g. `"strata_tool_call_compat": true` (name TBD; matches `strata_mcp` / `return_progress`). When the request declares at least one tool, a well-formed `<tool_call><function=NAME>…` whose NAME is not declared is returned as a normal `tool_calls` entry (arguments parsed as strings when no schema exists). Default `false` = exactly today's behavior, so #3075 stays the default; requests with no `tools` keep returning text; the Responses route unchanged. - Or the machine-readable `rejected_tool_calls` field in the response / final SSE chunk (names only), so a client can drive its own retry. For DSH that needs an extra client-side loop; the call-as-`tool_calls` path needs none. - Related to #4071: the unread warning exists but only on stdout, so clients behind a proxy cannot see it; a response field would make the event actionable. ### Scope / safety - Default stays declared-only; opt-in only. - No-tools requests keep the #3075 behavior unconditionally. - Opt-in must be documented as "for agent clients that validate tool names and answer with a tool error"; a client that blindly executes `tool_calls` should not enable it. - The engine already detects and counts these blocks (and names them in the log since 0.2.3); the missing part is making that fact deliverable to the client. Reproduction status: reproduced locally (deterministic API repro on engine 0.1.50, stream and non-stream), observed in real sessions before and after the upgrade, observed in non-PTC mode with all real tools declared, and client-side recovery validated. Related: #3883, #4071, #3441, #3075.
Author
Owner

@cjmckenna commented on GitHub (Nov 1, 2026):

Another DSH data point on Strata 0.2.9, using Qwen3.8-Flash-Next IQ3_S with the openai-completions streaming route: the model returned a complete <tool_call> for an undeclared linear_comment_get. Strata returned it as text with finish_reason: stop, and DSH ended the turn. After a manual “continue,” the model called the available linear_comment_list tool successfully.

We tested a DSH-side workaround using the agent/turn-stopping hook. When the whole response is a narrowly recognized, standalone call to an unavailable tool, it queues one corrective notice for the same turn. It does not execute the named tool. A scripted test using DSH 0.2.1-rc.5’s agent loop continued to the next model step with no tool execution; a clean-profile installation and focused checks for fenced examples, native tool calls, aborted turns, and max-token stops also passed.

Limitations: the current pi-ai adapter does not surface strata_rejected_tool_calls to this hook, so the workaround uses a deliberately narrow text heuristic, restricted to our configured Strata provider. It can retry once for an intentionally requested standalone XML example, and does not cover other malformed shapes. Live Desktop activation and end-to-end model recovery have not yet been verified. Using the explicit rejection marker in DSH would be a better general solution.

<!-- gh-comment-id:6562326688 --> @cjmckenna commented on GitHub (Nov 1, 2026): Another DSH data point on Strata 0.2.9, using Qwen3.8-Flash-Next IQ3_S with the `openai-completions` streaming route: the model returned a complete `<tool_call>` for an undeclared `linear_comment_get`. Strata returned it as text with `finish_reason: stop`, and DSH ended the turn. After a manual “continue,” the model called the available `linear_comment_list` tool successfully. We tested a DSH-side workaround using the `agent/turn-stopping` hook. When the whole response is a narrowly recognized, standalone call to an unavailable tool, it queues one corrective notice for the same turn. It does not execute the named tool. A scripted test using DSH 0.2.1-rc.5’s agent loop continued to the next model step with no tool execution; a clean-profile installation and focused checks for fenced examples, native tool calls, aborted turns, and max-token stops also passed. Limitations: the current pi-ai adapter does not surface `strata_rejected_tool_calls` to this hook, so the workaround uses a deliberately narrow text heuristic, restricted to our configured Strata provider. It can retry once for an intentionally requested standalone XML example, and does not cover other malformed shapes. Live Desktop activation and end-to-end model recovery have not yet been verified. Using the explicit rejection marker in DSH would be a better general solution.
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#1232
No description provided.