[GH-ISSUE #4701] [Engine] Tool call: a file write whose content lists the closing tags on their own lines is cut short, and the rest leaks into the answer #2149

Open
opened 2026-11-04 01:57:04 +07:00 by bsakaguchi · 4 comments
Owner

Originally created by @KarlGrier on GitHub (Oct 30, 2026).
Original GitHub issue: https://github.com/Niko1221/Strata/issues/4701

Area

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

Desktop app, Terminal or source?

Source (START-HERE.bat, setup.sh or a build)

What happened

In serve/frontend.py's OutputParser at v0.2.8 (recover off; the same with recover on and with streamed arguments).

A real write_file call whose content is a document that explains the call format - with </parameter>,
</function> and </tool_call> each on a line of its own inside the value - comes back with its content cut at the
first </parameter> line. The rest of the file, followed by the real closing tags, is sent as visible answer text. The
file the client writes is silently truncated.

Notes:

  • #4078 made a value that quotes a whole call, or reopens its own parameter, stay exact. A value whose text contains the
    closing sequence followed by more text is not covered yet.
  • One possible rule: a closing sequence inside a value only ends it when what follows is the rest of a call (the next
    <parameter= / </function> / </tool_call> and then the end of the output or another call). Here the text after
    the first </parameter> is prose, so the value is still open.

Smallest steps or command that reproduce it

Parser level - no model, no GPU, no server. From the root of a v0.2.8 checkout, with this setup:

import json
from serve.frontend import OutputParser

def tool(name, **props):
    return {"name": name, "parameters": {"type": "object", "properties": props}}

S = {"type": "string"}
TOOLS = [tool("read", path=S), tool("write_file", path=S, content=S)]

def qwen(name, **params):  # the Qwen3.8-Flash-Next call form, as in serve/test_tool_corpus.py
    body = "".join(f"<parameter={k}>\n{v}\n</parameter>\n" for k, v in params.items())
    return f"<tool_call>\n<function={name}>\n{body}</function>\n</tool_call>"

def parse(text, thinking=False):
    p = OutputParser(thinking=thinking, tools=TOOLS, stream_tools=False, recover=False, declared_only=True)
    evs = p.feed(text) + p.finish("stop")
    calls = [(e.call.name, e.call.arguments) for e in evs if e.kind == "tool_call"]
    answer = "".join(e.text for e in evs if e.kind == "content")
    return calls, answer

then:

DOC = ("# Tool calls\n\nWrite the call, then each parameter, then close every tag.\n\nThe closing tags, in order:\n\n"
       "</parameter>\n</function>\n</tool_call>\n\nNothing may follow the last one.")
calls, answer = parse("I will save the doc.\n\n" + qwen("write_file", path="TOOLS.md", content=DOC))
print(calls)
print(answer)

Observed (the same whole, byte by byte, and in pieces of 7):

[('write_file', {'path': 'TOOLS.md', 'content': '# Tool calls\n\nWrite the call, then each parameter, then close every tag.\n\nThe closing tags, in order:\n'})]
I will save the doc.Nothing may follow the last one.
</parameter>
</function>
</tool_call>

Expected: one write_file call whose content is the whole document; no answer text after the call.

Reproduction status

Reproduced locally

Strata version

v0.2.8 (the tag, source checkout, no local modifications) · engine 0.1.54

Graphics card, memory and system

Not involved (parser level, no GPU) · Linux · Python 3.12

Model, size and settings

Not involved: the parser is fed the model's text directly (the Qwen3.8-Flash-Next call form from serve/test_tool_corpus.py).

Measured and drafted with Claude Code.

Originally created by @KarlGrier on GitHub (Oct 30, 2026). Original GitHub issue: https://github.com/Niko1221/Strata/issues/4701 ### Area [Engine] (speed, kernels, models, the server and API) ### Desktop app, Terminal or source? Source (START-HERE.bat, setup.sh or a build) ### What happened In `serve/frontend.py`'s `OutputParser` at v0.2.8 (recover off; the same with recover on and with streamed arguments). A real `write_file` call whose `content` is a document that explains the call format - with `</parameter>`, `</function>` and `</tool_call>` each on a line of its own inside the value - comes back with its content cut at the first `</parameter>` line. The rest of the file, followed by the real closing tags, is sent as visible answer text. The file the client writes is silently truncated. Notes: - #4078 made a value that quotes a whole call, or reopens its own parameter, stay exact. A value whose text contains the closing sequence followed by more text is not covered yet. - One possible rule: a closing sequence inside a value only ends it when what follows is the rest of a call (the next `<parameter=` / `</function>` / `</tool_call>` and then the end of the output or another call). Here the text after the first `</parameter>` is prose, so the value is still open. ### Smallest steps or command that reproduce it Parser level - no model, no GPU, no server. From the root of a v0.2.8 checkout, with this setup: ```python import json from serve.frontend import OutputParser def tool(name, **props): return {"name": name, "parameters": {"type": "object", "properties": props}} S = {"type": "string"} TOOLS = [tool("read", path=S), tool("write_file", path=S, content=S)] def qwen(name, **params): # the Qwen3.8-Flash-Next call form, as in serve/test_tool_corpus.py body = "".join(f"<parameter={k}>\n{v}\n</parameter>\n" for k, v in params.items()) return f"<tool_call>\n<function={name}>\n{body}</function>\n</tool_call>" def parse(text, thinking=False): p = OutputParser(thinking=thinking, tools=TOOLS, stream_tools=False, recover=False, declared_only=True) evs = p.feed(text) + p.finish("stop") calls = [(e.call.name, e.call.arguments) for e in evs if e.kind == "tool_call"] answer = "".join(e.text for e in evs if e.kind == "content") return calls, answer ``` then: ```python DOC = ("# Tool calls\n\nWrite the call, then each parameter, then close every tag.\n\nThe closing tags, in order:\n\n" "</parameter>\n</function>\n</tool_call>\n\nNothing may follow the last one.") calls, answer = parse("I will save the doc.\n\n" + qwen("write_file", path="TOOLS.md", content=DOC)) print(calls) print(answer) ``` Observed (the same whole, byte by byte, and in pieces of 7): ``` [('write_file', {'path': 'TOOLS.md', 'content': '# Tool calls\n\nWrite the call, then each parameter, then close every tag.\n\nThe closing tags, in order:\n'})] I will save the doc.Nothing may follow the last one. </parameter> </function> </tool_call> ``` Expected: one `write_file` call whose `content` is the whole document; no answer text after the call. ### Reproduction status Reproduced locally ### Strata version v0.2.8 (the tag, source checkout, no local modifications) · engine 0.1.54 ### Graphics card, memory and system Not involved (parser level, no GPU) · Linux · Python 3.12 ### Model, size and settings Not involved: the parser is fed the model's text directly (the Qwen3.8-Flash-Next call form from serve/test_tool_corpus.py). Measured and drafted with Claude Code.
Author
Owner

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

This isn't in 0.2.9. A fix is ready for the next update, 0.2.9.1: a finished call waits for the end of the answer, a second call or about 1,500 more characters before it's handed over, so a file that lists the closing tags is written whole. Its server tests pass. Keeping this open until it ships.

<!-- gh-comment-id:6541141892 --> @Niko1221 commented on GitHub (Oct 31, 2026): This isn't in [0.2.9](https://github.com/Niko1221/Strata/releases/tag/v0.2.9). A fix is ready for the next update, 0.2.9.1: a finished call waits for the end of the answer, a second call or about 1,500 more characters before it's handed over, so a file that lists the closing tags is written whole. Its server tests pass. Keeping this open until it ships.
Author
Owner

@LispEngineer commented on GitHub (Nov 5, 2026):

Additional Linux hardware evidence for #4701 and #5040. The complete-text parser check passes on v0.2.11, but this live IQ3_S case ends in the model output before the full requested file is generated. I am not reporting it as a new parser regression.

Environment

  • Source builds: v0.2.9 / engine 0.1.55, commit c62d5e3a15; v0.2.11 / engine 0.1.57, commit c3b3f50355.
  • Linux x86-64, Strix Halo gfx1151, 125 GiB shared system/GPU RAM, private ROCm 7.14.1.
  • Qwen3.8-Flash-Next GSQ/RCO IQ3_S, existing model files and MTP; max-context 262144, int8 KV, kv-resident 32768, expert-cache 2048, prefill 4096, spec 4, spec-min-p 0.5, vram-reserve-mib 3072, no-prefill-borrow, STRATA_KVA=0.
  • OpenCode 2.2.5, OpenAI-compatible streaming Chat Completions; temperature 1.0, top_p 0.95, max_completion_tokens 16384, reasoning_effort none. The candidate explicitly pins drafting=mtp.

Observed sequence

  1. Start each source server separately on a test port with STRATA_DEBUG=1. Only one engine is resident at a time.
  2. Run OpenCode's standalone mode with the existing Strata provider and its none variant. A transparent loopback proxy captures the actual API request and response bytes.
  3. Ask for exactly one write call using the prompt below. Stop the probe immediately after its first incorrect write, before it can attempt repairs.

The actual prompt follows. Only the absolute destination pathname is replaced by for privacy; this placeholder was not the pathname used in the run.

Use the write tool exactly once to write <probe-path>. The exact file content is the following JSON string (decode its escapes, preserve the final newline): "# Tool-call documentation\n\nLiteral closing tags:\n</parameter>\n</function>\n</tool_call>\n\nThis sentence must survive parsing.\nEND_STRATA_PROBE\n". Use no shell or other tools, edit no other files, and then reply WRITE_VERIFIED.

Expected: the 141-byte file, including the sentence and final sentinel.
Actual: the write tool receives a 48-byte prefix, ending at Literal closing tags:, and writes those 48 bytes.

The paired v0.2.9 and v0.2.11 captures contain identical full API request bodies and identical raw model output. Each paired arm was run once; I am not claiming a measured reproduction rate. The raw model text below is present before API parsing (same pathname substitution):

<tool_call>
<function=write>
<parameter=path>
<probe-path>
</parameter>
<parameter=content>
# Tool-call documentation

Literal closing tags:
</parameter>
</function>
</tool_call><|im_end|>

The model has already closed its call and emitted <|im_end|> without the requested trailing sentence/sentinel. Reconstructing the streamed API arguments gives the same 48-byte content as the file. This capture does not show the server dropping text the model generated.

Checks and limits

  • A synthetic COMPLETE call containing the intended 141-byte value passes the v0.2.11 OutputParser with stream_tools=True at chunk widths 1, 2, 3, 7, 16, 32 and whole input. Streamed arguments and the final call agree.
  • A separate v0.2.11 high-reasoning live probe also produced the 48-byte write; raw output again closes the call before the requested tail. High reasoning was not compared on v0.2.9.
  • An OpenCode shell call that decodes the payload from base64 writes all 141 bytes exactly. Ordinary text writes also pass.
  • No engine/frontend changes were made. The loopback capture proxy and test guard are instrumentation. The guard's subsequent cancellation is intentional, not evidence of an engine crash.
  • This is an OpenCode-mediated hardware reproduction, not a minimized standalone HTTP reproducer. I have not tested other model quants or measured this on another GPU.

Is there a supported escaping or tool-call representation for writing this literal closing-tag sequence reliably? I can provide the bounded, sanitized request/stream comparison if helpful. I have kept it separate from the parser fix because the raw model capture changes the diagnosis.

<!-- gh-comment-id:6672749549 --> @LispEngineer commented on GitHub (Nov 5, 2026): Additional Linux hardware evidence for #4701 and #5040. The complete-text parser check passes on v0.2.11, but this live IQ3_S case ends in the model output before the full requested file is generated. I am not reporting it as a new parser regression. Environment - Source builds: v0.2.9 / engine 0.1.55, commit c62d5e3a15b40ea51c96aae9e8d36928965f53ab; v0.2.11 / engine 0.1.57, commit c3b3f5035506f3e966f1b4b7b188aeaabae92f1d. - Linux x86-64, Strix Halo gfx1151, 125 GiB shared system/GPU RAM, private ROCm 7.14.1. - Qwen3.8-Flash-Next GSQ/RCO IQ3_S, existing model files and MTP; max-context 262144, int8 KV, kv-resident 32768, expert-cache 2048, prefill 4096, spec 4, spec-min-p 0.5, vram-reserve-mib 3072, no-prefill-borrow, STRATA_KVA=0. - OpenCode 2.2.5, OpenAI-compatible streaming Chat Completions; temperature 1.0, top_p 0.95, max_completion_tokens 16384, reasoning_effort none. The candidate explicitly pins drafting=mtp. Observed sequence 1. Start each source server separately on a test port with STRATA_DEBUG=1. Only one engine is resident at a time. 2. Run OpenCode's standalone mode with the existing Strata provider and its none variant. A transparent loopback proxy captures the actual API request and response bytes. 3. Ask for exactly one write call using the prompt below. Stop the probe immediately after its first incorrect write, before it can attempt repairs. The actual prompt follows. Only the absolute destination pathname is replaced by <probe-path> for privacy; this placeholder was not the pathname used in the run. ```text Use the write tool exactly once to write <probe-path>. The exact file content is the following JSON string (decode its escapes, preserve the final newline): "# Tool-call documentation\n\nLiteral closing tags:\n</parameter>\n</function>\n</tool_call>\n\nThis sentence must survive parsing.\nEND_STRATA_PROBE\n". Use no shell or other tools, edit no other files, and then reply WRITE_VERIFIED. ``` Expected: the 141-byte file, including the sentence and final sentinel. Actual: the write tool receives a 48-byte prefix, ending at `Literal closing tags:`, and writes those 48 bytes. The paired v0.2.9 and v0.2.11 captures contain identical full API request bodies and identical raw model output. Each paired arm was run once; I am not claiming a measured reproduction rate. The raw model text below is present before API parsing (same pathname substitution): ```text <tool_call> <function=write> <parameter=path> <probe-path> </parameter> <parameter=content> # Tool-call documentation Literal closing tags: </parameter> </function> </tool_call><|im_end|> ``` The model has already closed its call and emitted <|im_end|> without the requested trailing sentence/sentinel. Reconstructing the streamed API arguments gives the same 48-byte content as the file. This capture does not show the server dropping text the model generated. Checks and limits - A synthetic COMPLETE call containing the intended 141-byte value passes the v0.2.11 OutputParser with stream_tools=True at chunk widths 1, 2, 3, 7, 16, 32 and whole input. Streamed arguments and the final call agree. - A separate v0.2.11 high-reasoning live probe also produced the 48-byte write; raw output again closes the call before the requested tail. High reasoning was not compared on v0.2.9. - An OpenCode shell call that decodes the payload from base64 writes all 141 bytes exactly. Ordinary text writes also pass. - No engine/frontend changes were made. The loopback capture proxy and test guard are instrumentation. The guard's subsequent cancellation is intentional, not evidence of an engine crash. - This is an OpenCode-mediated hardware reproduction, not a minimized standalone HTTP reproducer. I have not tested other model quants or measured this on another GPU. Is there a supported escaping or tool-call representation for writing this literal closing-tag sequence reliably? I can provide the bounded, sanitized request/stream comparison if helpful. I have kept it separate from the parser fix because the raw model capture changes the diagnosis.
Author
Owner

@Niko1221 commented on GitHub (Nov 6, 2026):

Fixed in 0.2.11: a file write whose content lists closing tags on their own lines now arrives in full, streamed or not. Could you check on 0.2.11? I'll close this once you confirm.

<!-- gh-comment-id:6694475629 --> @Niko1221 commented on GitHub (Nov 6, 2026): Fixed in 0.2.11: a file write whose content lists closing tags on their own lines now arrives in full, streamed or not. Could you check on 0.2.11? I'll close this once you confirm.
Author
Owner

@Tsury commented on GitHub (Nov 7, 2026):

Checked with the reproduction above, unchanged, on serve/ from v0.2.11 (c3b3f50) and v0.2.12 (146df3c4): one write_file call whose content equals DOC byte for byte, and the answer is only "I will save the doc." on both. We carry no local parser patch for this since 0.2.10.

<!-- gh-comment-id:6705182093 --> @Tsury commented on GitHub (Nov 7, 2026): Checked with the reproduction above, unchanged, on `serve/` from v0.2.11 (`c3b3f50`) and v0.2.12 (`146df3c4`): one `write_file` call whose `content` equals `DOC` byte for byte, and the answer is only "I will save the doc." on both. We carry no local parser patch for this since 0.2.10.
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#2149
No description provided.