[PR #5040] [CLOSED] [Engine] tool parser: streamed arguments keep a file that lists the closing tags #5295

Closed
opened 2026-11-07 16:34:08 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Niko1221/Strata/pull/5040
Author: @Tsury
Created: 11/3/2026
Status: ❌ Closed

Base: main ← Head: fix-4701-stream


📝 Commits (1)

  • 854c07c fix(parser): streamed arguments keep a file that lists the closing tags

📊 Changes

2 files changed (+15 additions, -2 deletions)

View changed files

📝 serve/frontend.py (+6 -2)
📝 serve/test_tool_corpus.py (+9 -0)

📄 Description

Problem and result

v0.2.10 fixed #4701 for the final tool_call event, but not for the streamed arguments. On a stream, a client builds a call from the tool_args deltas, so it still gets the cut file.

Before this change, on v0.2.10 (commit ffa80d73), a write_file call whose content lists the three closing tags, fed to OutputParser(stream_tools=True):

Chunk size Streamed content Final tool_call
1 # Tool calls\n\nThe closing tags, in order:\n whole
7 # Tool calls\n\nThe closing tags, in order:\n whole
4096 whole whole

So the streamed JSON and the final call differ, and only when text arrives in small pieces, which is what a running engine sends. Chat Completions yields tool_args as deltas and only records the final tool_call in finished, so the client never sees the whole value. The Anthropic route also emits tool_args as deltas.

After this change, the streamed arguments equal the final call at every chunk size.

Follows #4701. My earlier #4762 was closed in favour of the fix that shipped.

Approach

_close_verdict returned "end" when after held </function> and </tool_call> had not arrived yet. _scan then committed the value, so the later text could not change the verdict. call_end saw the whole sequence later, which is why the final call stayed right.

  • _close_verdict now returns "hold" when what follows </function> is empty or a prefix of </tool_call>, unless the output has ended.
  • A hold in the raw state would leave a typed value unclosed when the call body is cut at its known end. The body's end is confirmed at that point, so that one _scan runs with _final set. dsml-typed-arguments and test_reasoning_then_two_calls failed without this part.

No change for a value with no closing tags in it: the hold lasts until </tool_call> arrives.

Validation

Passed:

  • python -m unittest discover -s serve -t . -p 'test_*.py' on this branch (v0.2.10 + this commit), Linux, Python 3.12, MockEngine: 1385 tests, 17 skipped, no failures.
  • The four 4701-* cases added to serve/test_tool_corpus.py run whole, in pieces of 1, 3 and 7, and cut in two at every byte, with and without stream_tools. Two of the four cases pin neighbouring behaviour: text after a whole call, and two calls with text between.

Failed:

  • On v0.2.10 without the serve/frontend.py change, test_every_specimen_whole_and_in_pieces and test_every_specimen_cut_in_two_at_every_byte fail on 4701-closing-tags-in-a-file, as the table shows.

Not run:

  • Any GPU or model run. This is parser code, so the unit tests are the evidence for this branch.

Limits

The hold only covers </function> followed by a partial </tool_call>. A value cut by the token limit behaves as before.

🤖 Generated with Claude Code


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/Niko1221/Strata/pull/5040 **Author:** [@Tsury](https://github.com/Tsury) **Created:** 11/3/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `fix-4701-stream` --- ### 📝 Commits (1) - [`854c07c`](https://github.com/Niko1221/Strata/commit/854c07cef8047b24a2ab52c7ea399791a77abb12) fix(parser): streamed arguments keep a file that lists the closing tags ### 📊 Changes **2 files changed** (+15 additions, -2 deletions) <details> <summary>View changed files</summary> 📝 `serve/frontend.py` (+6 -2) 📝 `serve/test_tool_corpus.py` (+9 -0) </details> ### 📄 Description ## Problem and result v0.2.10 fixed [#4701](https://github.com/Niko1221/Strata/issues/4701) for the final `tool_call` event, but not for the streamed arguments. On a stream, a client builds a call from the `tool_args` deltas, so it still gets the cut file. Before this change, on v0.2.10 (commit ffa80d73), a `write_file` call whose content lists the three closing tags, fed to `OutputParser(stream_tools=True)`: | Chunk size | Streamed `content` | Final `tool_call` | |---|---|---| | 1 | `# Tool calls\n\nThe closing tags, in order:\n` | whole | | 7 | `# Tool calls\n\nThe closing tags, in order:\n` | whole | | 4096 | whole | whole | So the streamed JSON and the final call differ, and only when text arrives in small pieces, which is what a running engine sends. Chat Completions yields `tool_args` as deltas and only records the final `tool_call` in `finished`, so the client never sees the whole value. The Anthropic route also emits `tool_args` as deltas. After this change, the streamed arguments equal the final call at every chunk size. ## Related discussion Follows [#4701](https://github.com/Niko1221/Strata/issues/4701). My earlier [#4762](https://github.com/Niko1221/Strata/pull/4762) was closed in favour of the fix that shipped. ## Approach `_close_verdict` returned `"end"` when `after` held `</function>` and `</tool_call>` had not arrived yet. `_scan` then committed the value, so the later text could not change the verdict. `call_end` saw the whole sequence later, which is why the final call stayed right. - `_close_verdict` now returns `"hold"` when what follows `</function>` is empty or a prefix of `</tool_call>`, unless the output has ended. - A hold in the `raw` state would leave a typed value unclosed when the call body is cut at its known end. The body's end is confirmed at that point, so that one `_scan` runs with `_final` set. `dsml-typed-arguments` and `test_reasoning_then_two_calls` failed without this part. No change for a value with no closing tags in it: the hold lasts until `</tool_call>` arrives. ## Validation **Passed:** - `python -m unittest discover -s serve -t . -p 'test_*.py'` on this branch (v0.2.10 + this commit), Linux, Python 3.12, `MockEngine`: 1385 tests, 17 skipped, no failures. - The four `4701-*` cases added to `serve/test_tool_corpus.py` run whole, in pieces of 1, 3 and 7, and cut in two at every byte, with and without `stream_tools`. Two of the four cases pin neighbouring behaviour: text after a whole call, and two calls with text between. **Failed:** - On v0.2.10 without the `serve/frontend.py` change, `test_every_specimen_whole_and_in_pieces` and `test_every_specimen_cut_in_two_at_every_byte` fail on `4701-closing-tags-in-a-file`, as the table shows. **Not run:** - Any GPU or model run. This is parser code, so the unit tests are the evidence for this branch. ## Limits The hold only covers `</function>` followed by a partial `</tool_call>`. A value cut by the token limit behaves as before. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-07 16:34:08 +07:00
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#5295
No description provided.