[PR #3960] [Engine] Serve: tool calls coerce parameters by declared type; recover damaged <=param> openers and </NAME> closers #4852

Open
opened 2026-11-07 16:30:52 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Niko1221/Strata/pull/3960
Author: @mnott
Created: 10/24/2026
Status: 🔄 Open

Base: main ← Head: pr/coder-l-toolcall-recovery


📝 Commits (10+)

  • e861803 fix(serve): recover damaged qwen3-coder tool-call openers (<=NAME>, bare )
  • 394d6f6 test(serve): damaged-opener test tuple
  • ba3f805 fix(serve): coerce tool parameters by declared type; recover damaged <=param> openers
  • 1de5c2d fix(serve): coerce tool arguments on every call path; recover a tool name fused with its first parameter
  • 9144d88 fix(serve): a bare after opens declared parameter NAME
  • b75fbd8 fix(serve): a parameter without a declared type is JSON-decoded again (dsv41 and schema-less calls)
  • 881636a fix(serve): a parameter without a declared type is JSON-decoded again (test follows)
  • f52c86a fix(serve): a call cut inside a parameter name keeps its complete parameters instead of raising
  • 738d7a9 fix(serve): a parameter closer ends the value before any tag-shaped follower
  • 510b7a0 fix(serve): only call-format followers end a value; tags in file content stay verbatim

📊 Changes

19 files changed (+2132 additions, -122 deletions)

View changed files

📝 serve/frontend.py (+616 -72)
📝 serve/responses.py (+1 -13)
📝 serve/server.py (+7 -31)
➕ serve/test_live_tools.py (+164 -0)
➕ serve/test_param_types.py (+214 -0)
➕ serve/test_parser_bare_opener.py (+45 -0)
➕ serve/test_parser_bare_param_opener.py (+49 -0)
📝 serve/test_parser_call_scan.py (+1 -1)
➕ serve/test_parser_cut_name.py (+46 -0)
➕ serve/test_parser_damaged_opener.py (+147 -0)
➕ serve/test_parser_damaged_param_openers.py (+62 -0)
➕ serve/test_parser_followers.py (+95 -0)
➕ serve/test_parser_json_args.py (+105 -0)
➕ serve/test_parser_rules4.py (+111 -0)
➕ serve/test_parser_stub.py (+147 -0)
➕ serve/test_parser_xml_elems.py (+99 -0)
📝 serve/test_server.py (+3 -5)
➕ serve/test_stream_followers.py (+139 -0)
➕ tools/replay_raw.py (+81 -0)

📄 Description

Rebased onto v0.2.6.

Problem and result

Qwen3-coder style models sometimes write tool calls the parser rejects or misreads: a damaged opener (<=NAME>, a bare <NAME>, <parameter=NAME:, a function name fused with its first parameter), a closer without > or with a degenerate tail, an empty stub after a value, or a parameter whose declared type is a number or object but arrives as text. The call then fails and the agent retries. With this change those forms parse as the model meant and parameters arrive with their declared types.

Overview of our related macOS / Metal contributions: #4128. Focused fix, no scope agreement needed.

Approach

  • Tool parameters are coerced by their declared type on every call path; a parameter without a declared type is JSON-decoded.
  • The damaged opener and closer forms above are recognised; empty stubs after a value are skipped.
  • Only call-format followers end a value, so tag-like text inside file content stays verbatim.
  • A streamed tool_use block is emitted once, whole, with the parsed call's arguments.
  • Adds tools/replay_raw.py for replaying captured model output through the parser.

Validation

Revision 17c8d4ff (26 commits on v0.2.6), macOS on Apple Silicon, Python 3 with pytest 9.

Passed:

  • python3 -m pytest -q serve/test_live_tools.py serve/test_param_types.py serve/test_parser_bare_opener.py serve/test_parser_bare_param_opener.py serve/test_parser_call_scan.py serve/test_parser_cut_name.py serve/test_parser_damaged_opener.py serve/test_parser_damaged_param_openers.py serve/test_parser_followers.py serve/test_parser_json_args.py serve/test_parser_rules4.py serve/test_parser_stub.py serve/test_parser_xml_elems.py serve/test_server.py serve/test_stream_followers.py serve/test_frontend.py serve/test_answer_speed.py: 460 passed, 650 subtests passed.

Failed:

  • serve/test_server.py::VisionArgs::test_min_tokens_is_passed_only_when_set: fails the same way on plain v0.2.6 (the test's fake process has no pid); fixed separately in #4125.

Not run:

  • Linux and Windows test runs (only macOS here); the fork CI runs the serving runtime tests on Linux.

Limits

The recovery covers the damaged forms observed with Qwen3-coder style models; other malformed shapes still fail as before.


🔄 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/3960 **Author:** [@mnott](https://github.com/mnott) **Created:** 10/24/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `pr/coder-l-toolcall-recovery` --- ### 📝 Commits (10+) - [`e861803`](https://github.com/Niko1221/Strata/commit/e8618030ef1244ffbcd10a8cd22c38a96c15d49d) fix(serve): recover damaged qwen3-coder tool-call openers (<=NAME>, bare <NAME>) - [`394d6f6`](https://github.com/Niko1221/Strata/commit/394d6f6725a66687e495657fca3068b178797379) test(serve): damaged-opener test tuple - [`ba3f805`](https://github.com/Niko1221/Strata/commit/ba3f805045f2fd4e639775817333ed7d72f367b3) fix(serve): coerce tool parameters by declared type; recover damaged <=param> openers - [`1de5c2d`](https://github.com/Niko1221/Strata/commit/1de5c2d1c432671634285c00bb21fb9d9fcb1e1e) fix(serve): coerce tool arguments on every call path; recover a tool name fused with its first parameter - [`9144d88`](https://github.com/Niko1221/Strata/commit/9144d88aff7bf86515442e9759e92e96f34b115b) fix(serve): a bare <NAME> after </parameter> opens declared parameter NAME - [`b75fbd8`](https://github.com/Niko1221/Strata/commit/b75fbd89620b2ddf4908e43b3096c6807d83cede) fix(serve): a parameter without a declared type is JSON-decoded again (dsv41 and schema-less calls) - [`881636a`](https://github.com/Niko1221/Strata/commit/881636a919f2e9c216e35e957387f060191faf3d) fix(serve): a parameter without a declared type is JSON-decoded again (test follows) - [`f52c86a`](https://github.com/Niko1221/Strata/commit/f52c86ac263a3f967eb50e060413278c6687b21f) fix(serve): a call cut inside a parameter name keeps its complete parameters instead of raising - [`738d7a9`](https://github.com/Niko1221/Strata/commit/738d7a96f79e18521bcb0ed8435a1128e69f7f43) fix(serve): a parameter closer ends the value before any tag-shaped follower - [`510b7a0`](https://github.com/Niko1221/Strata/commit/510b7a03734b124e59cc94f6f0f69d414edae5ff) fix(serve): only call-format followers end a value; tags in file content stay verbatim ### 📊 Changes **19 files changed** (+2132 additions, -122 deletions) <details> <summary>View changed files</summary> 📝 `serve/frontend.py` (+616 -72) 📝 `serve/responses.py` (+1 -13) 📝 `serve/server.py` (+7 -31) ➕ `serve/test_live_tools.py` (+164 -0) ➕ `serve/test_param_types.py` (+214 -0) ➕ `serve/test_parser_bare_opener.py` (+45 -0) ➕ `serve/test_parser_bare_param_opener.py` (+49 -0) 📝 `serve/test_parser_call_scan.py` (+1 -1) ➕ `serve/test_parser_cut_name.py` (+46 -0) ➕ `serve/test_parser_damaged_opener.py` (+147 -0) ➕ `serve/test_parser_damaged_param_openers.py` (+62 -0) ➕ `serve/test_parser_followers.py` (+95 -0) ➕ `serve/test_parser_json_args.py` (+105 -0) ➕ `serve/test_parser_rules4.py` (+111 -0) ➕ `serve/test_parser_stub.py` (+147 -0) ➕ `serve/test_parser_xml_elems.py` (+99 -0) 📝 `serve/test_server.py` (+3 -5) ➕ `serve/test_stream_followers.py` (+139 -0) ➕ `tools/replay_raw.py` (+81 -0) </details> ### 📄 Description Rebased onto v0.2.6. ## Problem and result Qwen3-coder style models sometimes write tool calls the parser rejects or misreads: a damaged opener (`<=NAME>`, a bare `<NAME>`, `<parameter=NAME:`, a function name fused with its first parameter), a closer without `>` or with a degenerate tail, an empty stub after a value, or a parameter whose declared type is a number or object but arrives as text. The call then fails and the agent retries. With this change those forms parse as the model meant and parameters arrive with their declared types. ## Related discussion Overview of our related macOS / Metal contributions: #4128. Focused fix, no scope agreement needed. ## Approach - Tool parameters are coerced by their declared type on every call path; a parameter without a declared type is JSON-decoded. - The damaged opener and closer forms above are recognised; empty stubs after a value are skipped. - Only call-format followers end a value, so tag-like text inside file content stays verbatim. - A streamed `tool_use` block is emitted once, whole, with the parsed call's arguments. - Adds `tools/replay_raw.py` for replaying captured model output through the parser. ## Validation Revision `17c8d4ff` (26 commits on `v0.2.6`), macOS on Apple Silicon, Python 3 with pytest 9. **Passed:** - `python3 -m pytest -q serve/test_live_tools.py serve/test_param_types.py serve/test_parser_bare_opener.py serve/test_parser_bare_param_opener.py serve/test_parser_call_scan.py serve/test_parser_cut_name.py serve/test_parser_damaged_opener.py serve/test_parser_damaged_param_openers.py serve/test_parser_followers.py serve/test_parser_json_args.py serve/test_parser_rules4.py serve/test_parser_stub.py serve/test_parser_xml_elems.py serve/test_server.py serve/test_stream_followers.py serve/test_frontend.py serve/test_answer_speed.py`: 460 passed, 650 subtests passed. **Failed:** - `serve/test_server.py::VisionArgs::test_min_tokens_is_passed_only_when_set`: fails the same way on plain `v0.2.6` (the test's fake process has no `pid`); fixed separately in #4125. **Not run:** - Linux and Windows test runs (only macOS here); the fork CI runs the serving runtime tests on Linux. ## Limits The recovery covers the damaged forms observed with Qwen3-coder style models; other malformed shapes still fail as before. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
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#4852
No description provided.