[PR #1881] [CLOSED] [Engine] serve: a tool call whose </tool_call> is missing ends at its own </function> #3733

Closed
opened 2026-11-07 15:30:22 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Niko1221/Strata/pull/1881
Author: @LeGeRyChEeSe
Created: 10/10/2026
Status: ❌ Closed

Base: main ← Head: pr/tool-call-unclosed


📝 Commits (1)

  • fe6abbd serve: a tool call whose </tool_call> is missing ends at its own when another <tool_call> or text follows, instead of merging into the next call or losing its arguments

📊 Changes

2 files changed (+74 additions, -0 deletions)

View changed files

📝 serve/frontend.py (+10 -0)
➕ serve/test_tool_call_unclosed.py (+64 -0)

📄 Description

Problem and result

When the model leaves out a call's </tool_call>, call_end falls back to the next </tool_call> anywhere in the output. Two cases go wrong, with or without tool_call_recovery, streamed or not:

model output before after
<tool_call> read(a.py) (no closer) <tool_call> write(b.py, "x = 1") </tool_call> one call: read with {"path": "b.py", "content": "x = 1"} read(a.py), then write(b.py, "x = 1")
<tool_call> read(a.py) (no closer) Done. read with {} (streamed) or no call read(a.py), then the content Done.

The first is the worse one: an agent runs the first tool with the second tool's arguments. The bug is still present in v0.2.2.

No open issue found (searched 2026-10-22: "missing </tool_call>", "unclosed tool_call", "tool_call closing tag"). Related, all closed: #210 (call_end), #211 (a call cut before its closer), #1172 (recover's batch in one wrapper, opt-in), #1431.
This pull request was closed in the 0.2.0-beta tracker reset; it is rebased on v0.2.2 and unchanged in content.

Approach

OutputParser.feed, the wrapped-call branch (a few lines). After the call's own </function> - found by function_end, which walks the parameters with param_end, so a value that holds </function> or <tool_call> does not count - the next non-blank text decides:

  • </tool_call> (or the start of it, still arriving): closes the call, as before;
  • <function= or <parameter= (or the start of one, still arriving): left to recover's batch (opt-in), unchanged;
  • anything else (another <tool_call>, text): the call ends at its </function>, and what follows is read as usual.

Nothing changes for a call that has its closer. New regression test: serve/test_tool_call_unclosed.py.

Validation

Revision: v0.2.2 (011c9e60) plus this one commit. Environment: Windows 11, Python 3.13, RTX 4070 SUPER.

Passed:

  • python -m unittest serve.test_tool_call_unclosed on v0.2.2 without the change: 4 tests, 24 sub-test failures (for example [('read', {})] != [('read', {'path': 'a.py'})]). With the change: 4 tests, OK. The tests cover the two cases above, closed calls unchanged, and a parameter value that holds </function> and <tool_call>, each with stream_tools and recover on and off, fed 1, 3 and 7 characters at a time.
  • python -m pytest serve -q on this branch: 916 passed, 17 skipped.
  • A server built from v0.2.2 plus this change (and two other small serve/ changes, #1882 and #1883) answered a request with a declared tool by a tool call, streamed and not. That request has a closed call, so it only shows that nothing regressed.

Failed:
none observed.

Not run:

  • A live model that actually drops the closer: the unclosed cases are synthetic outputs fed to OutputParser.
  • Linux and macOS: the change is pure Python parsing with no platform code.
  • Engine builds (CUDA, HIP, SYCL, Metal): no engine file is touched.

Limits

This only reads what the model wrote more faithfully; a model that omits the closer still does so.


🔄 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/1881 **Author:** [@LeGeRyChEeSe](https://github.com/LeGeRyChEeSe) **Created:** 10/10/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `pr/tool-call-unclosed` --- ### 📝 Commits (1) - [`fe6abbd`](https://github.com/Niko1221/Strata/commit/fe6abbdc8995b3e5840f097f34c474b1e6b3cfaf) serve: a tool call whose </tool_call> is missing ends at its own </function> when another <tool_call> or text follows, instead of merging into the next call or losing its arguments ### 📊 Changes **2 files changed** (+74 additions, -0 deletions) <details> <summary>View changed files</summary> 📝 `serve/frontend.py` (+10 -0) ➕ `serve/test_tool_call_unclosed.py` (+64 -0) </details> ### 📄 Description ## Problem and result When the model leaves out a call's `</tool_call>`, `call_end` falls back to the *next* `</tool_call>` anywhere in the output. Two cases go wrong, with or without `tool_call_recovery`, streamed or not: | model output | before | after | |---|---|---| | `<tool_call>` read(a.py) *(no closer)* `<tool_call>` write(b.py, "x = 1") `</tool_call>` | **one** call: `read` with `{"path": "b.py", "content": "x = 1"}` | `read(a.py)`, then `write(b.py, "x = 1")` | | `<tool_call>` read(a.py) *(no closer)* `Done.` | `read` with `{}` (streamed) or no call | `read(a.py)`, then the content `Done.` | The first is the worse one: an agent runs the first tool with the second tool's arguments. The bug is still present in v0.2.2. ## Related discussion No open issue found (searched 2026-10-22: "missing </tool_call>", "unclosed tool_call", "tool_call closing tag"). Related, all closed: #210 (call_end), #211 (a call cut before its closer), #1172 (recover's batch in one wrapper, opt-in), #1431. This pull request was closed in the 0.2.0-beta tracker reset; it is rebased on v0.2.2 and unchanged in content. ## Approach `OutputParser.feed`, the wrapped-call branch (a few lines). After the call's own `</function>` - found by `function_end`, which walks the parameters with `param_end`, so a value that holds `</function>` or `<tool_call>` does not count - the next non-blank text decides: - `</tool_call>` (or the start of it, still arriving): closes the call, as before; - `<function=` or `<parameter=` (or the start of one, still arriving): left to recover's batch (opt-in), unchanged; - anything else (another `<tool_call>`, text): the call ends at its `</function>`, and what follows is read as usual. Nothing changes for a call that has its closer. New regression test: `serve/test_tool_call_unclosed.py`. ## Validation Revision: v0.2.2 (`011c9e60`) plus this one commit. Environment: Windows 11, Python 3.13, RTX 4070 SUPER. **Passed:** - `python -m unittest serve.test_tool_call_unclosed` on v0.2.2 **without** the change: 4 tests, 24 sub-test failures (for example `[('read', {})] != [('read', {'path': 'a.py'})]`). With the change: 4 tests, OK. The tests cover the two cases above, closed calls unchanged, and a parameter value that holds `</function>` and `<tool_call>`, each with `stream_tools` and `recover` on and off, fed 1, 3 and 7 characters at a time. - `python -m pytest serve -q` on this branch: 916 passed, 17 skipped. - A server built from v0.2.2 plus this change (and two other small `serve/` changes, #1882 and #1883) answered a request with a declared tool by a tool call, streamed and not. That request has a closed call, so it only shows that nothing regressed. **Failed:** none observed. **Not run:** - A live model that actually drops the closer: the unclosed cases are synthetic outputs fed to `OutputParser`. - Linux and macOS: the change is pure Python parsing with no platform code. - Engine builds (CUDA, HIP, SYCL, Metal): no engine file is touched. ## Limits This only reads what the model wrote more faithfully; a model that omits the closer still does so. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-07 15:30:22 +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#3733
No description provided.