[PR #4762] [CLOSED] [Engine] tool parser: a closing sequence with text after it stays in the value #5169

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

📋 Pull Request Information

Original PR: https://github.com/Niko1221/Strata/pull/4762
Author: @Tsury
Created: 10/30/2026
Status: ❌ Closed

Base: main ← Head: fix/tool-value-close


📝 Commits (1)

  • 1a1a5de [Engine] tool parser: a closing sequence with text after it stays in the value (#4701)

📊 Changes

4 files changed (+56 additions, -23 deletions)

View changed files

📝 serve/frontend.py (+42 -20)
📝 serve/test_dsv41.py (+1 -1)
📝 serve/test_parser_call_scan.py (+4 -2)
📝 serve/test_tool_corpus.py (+9 -0)

📄 Description

Problem and result

A write_file whose content explains the call format, with </parameter>, </function> and </tool_call> on their own lines followed by more text, is cut at the first </parameter>. The rest of the file leaks into the answer and the client writes a short file with no error (#4701).

After this change, the #4701 fixture gives one call with the whole document and no answer text, with recover on and off, whole and in pieces.

Fixes #4701. It extends #4078 and uses the rule the issue suggests.

Approach

A closing sequence only ends a value when the end of the output, another call, or </think> follows it. If text follows, and a later close ends the output, the value goes on. If no later close arrives, the first one was the end, so a real call followed by prose behaves as before. Any <tool_call> in the following text also keeps the old result, so two calls with prose between them stay two calls.

The cost

This cannot be decided at </tool_call>: the next bytes settle it. So a complete call now waits for one more token, or for finish(). That is why the diff is larger than the rule:

  • param_end, call_end and function_end pass final through.
  • finish() sets self.ending and feeds nothing once, so a waiting call completes through the normal path.
  • test_parser_call_scan and test_dsv41 change, because they asserted that a call finishes on the last byte of </tool_call>.

The tool_call event moves by one token at most in the normal case. If a model writes prose after a real call, that call is held until the end of the turn. It stays the same call with the same arguments.

Validation

Passed:

  • The #4701 fixture gives 102 of 174 characters on unchanged main (870aedd9) and 174 of 174 here, recover and streamed arguments on and off, whole and in pieces of 1 and 7.

  • python -m pytest serve on Linux, Python 3.14: 1242 passed, 14 skipped.

  • Before the fix, on a maintained v0.2.8 build on an RTX 5090 Laptop (Qwen3.8-Flash-Next IQ3_S, live server), the model copied such a document into write_file: Responses and streamed Chat wrote 41 of 113 characters and leaked the rest into the answer; Chat cut the file too and added a second call.

Not run: a model run of this branch.

Limits

A file with the closing sequence, then a whole quoted call after it, still ends at the first close. That text looks the same as two real calls with prose between them. If you think one token of delay in this path is the wrong trade, I will close this and leave the report on #4701.

🤖 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/4762 **Author:** [@Tsury](https://github.com/Tsury) **Created:** 10/30/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `fix/tool-value-close` --- ### 📝 Commits (1) - [`1a1a5de`](https://github.com/Niko1221/Strata/commit/1a1a5de784454d81dffe7060fb20f519b86e785e) [Engine] tool parser: a closing sequence with text after it stays in the value (#4701) ### 📊 Changes **4 files changed** (+56 additions, -23 deletions) <details> <summary>View changed files</summary> 📝 `serve/frontend.py` (+42 -20) 📝 `serve/test_dsv41.py` (+1 -1) 📝 `serve/test_parser_call_scan.py` (+4 -2) 📝 `serve/test_tool_corpus.py` (+9 -0) </details> ### 📄 Description ## Problem and result A `write_file` whose content explains the call format, with `</parameter>`, `</function>` and `</tool_call>` on their own lines followed by more text, is cut at the first `</parameter>`. The rest of the file leaks into the answer and the client writes a short file with no error (#4701). After this change, the #4701 fixture gives one call with the whole document and no answer text, with recover on and off, whole and in pieces. ## Related discussion Fixes #4701. It extends #4078 and uses the rule the issue suggests. ## Approach A closing sequence only ends a value when the end of the output, another call, or `</think>` follows it. If text follows, and a later close ends the output, the value goes on. If no later close arrives, the first one was the end, so a real call followed by prose behaves as before. Any `<tool_call>` in the following text also keeps the old result, so two calls with prose between them stay two calls. ## The cost This cannot be decided at `</tool_call>`: the next bytes settle it. So a complete call now waits for one more token, or for `finish()`. That is why the diff is larger than the rule: - `param_end`, `call_end` and `function_end` pass `final` through. - `finish()` sets `self.ending` and feeds nothing once, so a waiting call completes through the normal path. - `test_parser_call_scan` and `test_dsv41` change, because they asserted that a call finishes on the last byte of `</tool_call>`. The `tool_call` event moves by one token at most in the normal case. If a model writes prose after a real call, that call is held until the end of the turn. It stays the same call with the same arguments. ## Validation **Passed:** - The #4701 fixture gives 102 of 174 characters on unchanged `main` (870aedd9) and 174 of 174 here, recover and streamed arguments on and off, whole and in pieces of 1 and 7. - `python -m pytest serve` on Linux, Python 3.14: 1242 passed, 14 skipped. - **Before** the fix, on a maintained v0.2.8 build on an RTX 5090 Laptop (Qwen3.8-Flash-Next IQ3_S, live server), the model copied such a document into `write_file`: Responses and streamed Chat wrote 41 of 113 characters and leaked the rest into the answer; Chat cut the file too and added a second call. **Not run:** a model run of this branch. ## Limits A file with the closing sequence, then a whole quoted call after it, still ends at the first close. That text looks the same as two real calls with prose between them. If you think one token of delay in this path is the wrong trade, I will close this and leave the report on #4701. 🤖 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:33:12 +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#5169
No description provided.