[PR #3556] [CLOSED] [Engine] preserve streamed tool aliases and confirm wrapper boundaries #4685

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

📋 Pull Request Information

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

Base: main ← Head: fix/native-tool-parser


📝 Commits (4)

  • b4fa044 fix(serve): preserve declared tool schemas through streamed aliases
  • 607c5db fix(serve): confirm streamed wrapper boundaries before completing calls
  • 9bad147 Keep omitted-wrapper calls incomplete on output limits and cancellation
  • c42a808 Align alias regressions with upstream declared-tool policy

📊 Changes

7 files changed (+367 additions, -35 deletions)

View changed files

📝 serve/frontend.py (+51 -21)
📝 serve/responses.py (+3 -7)
➕ serve/test_native_tool_parser.py (+145 -0)
📝 serve/test_responses.py (+47 -0)
📝 serve/test_server.py (+26 -6)
📝 serve/test_tool_call_envelope.py (+1 -1)
➕ serve/test_tool_call_unclosed.py (+94 -0)

📄 Description

Problem and result

A declared namespaced tool written with its flat alias or padded name can lose its schema while streaming. An ambiguous alias can also route to the first namespace. Canonicalize only unambiguous aliases at the parser boundary, with exact declared names taking precedence, so names and parameter types agree across streamed and completed calls.

This refresh also fixes the quoted incomplete-wrapper example identified in review. Format: <tool_call>... </function> and then I explain it. now stays text rather than becoming a completed call. A following actual call opener still separates concatenated calls without merging their arguments.

Replaces #2284 because its requested /reopen check passed but GitHub refused reopening with HTTP 422 Validation Failed (empty errors). REST and GraphQL reopening also failed after restoring the original branch head. The bot explicitly recommended a new linked PR: https://github.com/Niko1221/Strata/pull/2284#issuecomment-6310183962

Review: https://github.com/Niko1221/Strata/pull/2284#issuecomment-6184667095

Tracker reset/reopen instructions: https://github.com/Niko1221/Strata/pull/2284#issuecomment-6272913330

Approach

Keep alias resolution and schema lookup together in the shared parser, removing the redundant Responses-only alias map. Preserve native declared-tool enforcement, literal markers and opt-in recovery batches. Ambiguous aliases stay literal under current main instead of choosing a namespace.

Keep early streamed names and argument pieces, but hold their final JSON closing brace until the wrapper or next-call boundary confirms completion. Preserve native streaming recovery when output ends immediately after </function> on a natural stop (None or stop). Output limits, cancellation and disconnect keep an omitted-wrapper call incomplete; fully closed calls keep their existing behavior. Trailing prose cannot confirm an omitted wrapper closer. Responses marks an implicitly interrupted call incomplete; only the parser's completed call confirms it.

Validation

Passed:

On Linux, Python 3.14.8, CPU-only mock engine, revision c42a808d, rebased onto main 011c9e600a93bbc9fd451c563501b5831c32bbca (0.2.2 / engine 0.1.47):

python3 -m unittest serve.test_tool_call_unclosed serve.test_native_tool_parser serve.test_tool_call_envelope serve.test_server.ToolCallRecovery serve.test_server.ToolCallRecoveryOff serve.test_server.UnfinishedToolCall serve.test_server.ToolCallTerminators serve.test_server.ToolCallTagInProse
python3 -m unittest serve.test_responses

85 tests passed across separate 44-method parser/API and 41-method Responses processes. Valid-call controls, chunk boundaries, aliases/schema types, concatenated calls, literal tags, quoted incomplete wrappers, and streamed/collected Chat Completions, Messages and Responses are covered. The new main's drifted openers and declared-tool-only rules are retained. One constructor conflict combined its declared-tool state with the unique canonical alias map. Old ambiguous/unknown-name expectations were updated to require literal text and no dispatch; the new envelope test expects the canonical declared name. git diff --check passed.

Failed:

The first current-main Responses run failed its old ambiguous-alias expectation; after the current declared-tool policy assertion was corrected, all 41 passed. Historical original failures remain valid: before this repair, both new HTTP regression methods failed against the original parser patch after rebase: Chat returned tool_calls, and Responses returned a completed function call. The two pure-parser literal scenarios also reproduced the unexpected call across all 24 tested streaming/recovery/chunk subcases. The added natural-stop boundary test and extended Chat/Messages max-token test also failed on the previous condition (10 subcase failures across two methods), then passed with this repair. Two combined-suite runs encountered the existing NoLeakedSampler.test_server_close_ends_the_sampler global thread-count timing failure (1 != 2). That class passed in isolation. Running the parser/API group and Responses module in separate processes passed all 75 methods, including that class. No test or production change was made for the unrelated thread-count failure.

Not run:

GPU inference, native client checks, or CUDA/HIP/SYCL builds on this standalone contribution tree. This contribution changes Python serving code only and makes no hardware or throughput claim.

Limits

An incomplete wrapper can still announce a tentative streamed tool name and partial arguments. Those arguments remain incomplete JSON; no completed tool call follows. Chat and Messages collected replies omit that tentative call. Responses retains an explicitly incomplete item beside the literal text. Fully buffering all call events would remove early argument streaming and is outside this fix.


🔄 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/3556 **Author:** [@Tsury](https://github.com/Tsury) **Created:** 10/21/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `fix/native-tool-parser` --- ### 📝 Commits (4) - [`b4fa044`](https://github.com/Niko1221/Strata/commit/b4fa044f3301d23a5838c67659cd1ffd6cf9be96) fix(serve): preserve declared tool schemas through streamed aliases - [`607c5db`](https://github.com/Niko1221/Strata/commit/607c5db4ebcdabc35f962788592e832dae2ecc0b) fix(serve): confirm streamed wrapper boundaries before completing calls - [`9bad147`](https://github.com/Niko1221/Strata/commit/9bad147114256805ea6df275753d4b17f0aeaeab) Keep omitted-wrapper calls incomplete on output limits and cancellation - [`c42a808`](https://github.com/Niko1221/Strata/commit/c42a808d81488e3d47ae00bd6996d91a7ad65687) Align alias regressions with upstream declared-tool policy ### 📊 Changes **7 files changed** (+367 additions, -35 deletions) <details> <summary>View changed files</summary> 📝 `serve/frontend.py` (+51 -21) 📝 `serve/responses.py` (+3 -7) ➕ `serve/test_native_tool_parser.py` (+145 -0) 📝 `serve/test_responses.py` (+47 -0) 📝 `serve/test_server.py` (+26 -6) 📝 `serve/test_tool_call_envelope.py` (+1 -1) ➕ `serve/test_tool_call_unclosed.py` (+94 -0) </details> ### 📄 Description ## Problem and result A declared namespaced tool written with its flat alias or padded name can lose its schema while streaming. An ambiguous alias can also route to the first namespace. Canonicalize only unambiguous aliases at the parser boundary, with exact declared names taking precedence, so names and parameter types agree across streamed and completed calls. This refresh also fixes the quoted incomplete-wrapper example identified in review. `Format: <tool_call>... </function> and then I explain it.` now stays text rather than becoming a completed call. A following actual call opener still separates concatenated calls without merging their arguments. ## Related discussion Replaces #2284 because its requested `/reopen` check passed but GitHub refused reopening with HTTP 422 `Validation Failed` (empty errors). REST and GraphQL reopening also failed after restoring the original branch head. The bot explicitly recommended a new linked PR: https://github.com/Niko1221/Strata/pull/2284#issuecomment-6310183962 Review: https://github.com/Niko1221/Strata/pull/2284#issuecomment-6184667095 Tracker reset/reopen instructions: https://github.com/Niko1221/Strata/pull/2284#issuecomment-6272913330 ## Approach Keep alias resolution and schema lookup together in the shared parser, removing the redundant Responses-only alias map. Preserve native declared-tool enforcement, literal markers and opt-in recovery batches. Ambiguous aliases stay literal under current main instead of choosing a namespace. Keep early streamed names and argument pieces, but hold their final JSON closing brace until the wrapper or next-call boundary confirms completion. Preserve native streaming recovery when output ends immediately after `</function>` on a natural stop (`None` or `stop`). Output limits, cancellation and disconnect keep an omitted-wrapper call incomplete; fully closed calls keep their existing behavior. Trailing prose cannot confirm an omitted wrapper closer. Responses marks an implicitly interrupted call incomplete; only the parser's completed call confirms it. ## Validation **Passed:** On Linux, Python 3.14.8, CPU-only mock engine, revision `c42a808d`, rebased onto main `011c9e600a93bbc9fd451c563501b5831c32bbca` (0.2.2 / engine 0.1.47): ```sh python3 -m unittest serve.test_tool_call_unclosed serve.test_native_tool_parser serve.test_tool_call_envelope serve.test_server.ToolCallRecovery serve.test_server.ToolCallRecoveryOff serve.test_server.UnfinishedToolCall serve.test_server.ToolCallTerminators serve.test_server.ToolCallTagInProse python3 -m unittest serve.test_responses ``` 85 tests passed across separate 44-method parser/API and 41-method Responses processes. Valid-call controls, chunk boundaries, aliases/schema types, concatenated calls, literal tags, quoted incomplete wrappers, and streamed/collected Chat Completions, Messages and Responses are covered. The new main's drifted openers and declared-tool-only rules are retained. One constructor conflict combined its declared-tool state with the unique canonical alias map. Old ambiguous/unknown-name expectations were updated to require literal text and no dispatch; the new envelope test expects the canonical declared name. `git diff --check` passed. **Failed:** The first current-main Responses run failed its old ambiguous-alias expectation; after the current declared-tool policy assertion was corrected, all 41 passed. Historical original failures remain valid: before this repair, both new HTTP regression methods failed against the original parser patch after rebase: Chat returned `tool_calls`, and Responses returned a completed function call. The two pure-parser literal scenarios also reproduced the unexpected call across all 24 tested streaming/recovery/chunk subcases. The added natural-stop boundary test and extended Chat/Messages max-token test also failed on the previous condition (10 subcase failures across two methods), then passed with this repair. Two combined-suite runs encountered the existing `NoLeakedSampler.test_server_close_ends_the_sampler` global thread-count timing failure (`1 != 2`). That class passed in isolation. Running the parser/API group and Responses module in separate processes passed all 75 methods, including that class. No test or production change was made for the unrelated thread-count failure. **Not run:** GPU inference, native client checks, or CUDA/HIP/SYCL builds on this standalone contribution tree. This contribution changes Python serving code only and makes no hardware or throughput claim. ## Limits An incomplete wrapper can still announce a tentative streamed tool name and partial arguments. Those arguments remain incomplete JSON; no completed tool call follows. Chat and Messages collected replies omit that tentative call. Responses retains an explicitly incomplete item beside the literal text. Fully buffering all call events would remove early argument streaming and is outside this fix. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-07 15:38:19 +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#4685
No description provided.