[PR #4613] [Engine] serve: a call-shaped block inside a code fence is counted and named too (#4071) #5110

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

📋 Pull Request Information

Original PR: https://github.com/Niko1221/Strata/pull/4613
Author: @james-martinez
Created: 10/29/2026
Status: 🔄 Open

Base: main ← Head: f-4071-fenced-reject-marker


📝 Commits (1)

  • f9ad906 serve: a call-shaped block inside a code fence is counted and named too (#4071)

📊 Changes

4 files changed (+161 additions, -8 deletions)

View changed files

📝 docs/DETAILS.md (+3 -2)
📝 serve/frontend.py (+37 -4)
📝 serve/server.py (+6 -2)
➕ serve/test_unread_call_marker.py (+115 -0)

📄 Description

Problem and result

A Chat Completions request that declares no tools (or none matching what the model writes) gets an answer ending in a complete, well-formed <tool_call> block inside a Markdown code fence — what Open WebUI shows as "the tool XML appeared inside a code block". tool_calls is empty, finish_reason is stop, and the chat stores the markup as text.

The rules that keep such a block as text both stay (declared-only #3075, code fence #1058); the reply text and finish_reason are unchanged. What changes is visibility: the fence path used to pass the block back without counting it at all, so a client could not distinguish "the model wrote a call and the parser dropped it" from "the model chose not to call". After this commit the fenced/inline-code block is counted and named like the other paths, and strata_rejected_tool_calls entries carry a reason.

Reproduced locally (not static analysis):

  • Live: Qwen3.8-Flash-Next IQ3_S behind Strata 0.2.7 (rocm and sycl builds), toolless Chat Completions chat (Open WebUI), prompt "make an SVG and save it": complete write_file block in a ```xml fence in content, no tool_calls, finish_reason: stop; parser state unread=0, unread_names=[] — invisible to every signal #3796 added.
  • Parser at main (46c152a): the shape in serve/test_unread_call_marker.py::FencedBlockIsCounted fails on stock main (leak with unread=0), passes with this commit.

#4071 (this is the fenced variant of the reported failure), #3796 (the marker this completes), #3075/#1058 (the rules kept). No prior scope discussion needed per CONTRIBUTING ("focused fixes can go straight to a PR"); datapoint posted in #4071.

Approach

OutputParser's fence / inline-code branch now runs the block through a shared _mark_unread(): it counts once and names once the function name has fully arrived (a partial name is held like a partial tag, so streamed and whole outputs count identically — checked at chunk sizes 1/3/17). Reasons: undeclared, in_code (a declared name quoted inside code), malformed (an opener with no readable name; counted as before, still unnamed, so the existing "malformed blocks have no name to list" contract is preserved). The two existing unread += 1 sites route through the same helper. serve/server.py forwards the reasons in strata_rejected_tool_calls; the stdout warning and tool_calls_unread counter are unchanged apart from now including fenced blocks, which is what that counter was meant to measure. The Anthropic route shares OutputParser, so /v1/messages fenced blocks gain the same marker the JSON route already had for undeclared names. Nothing undeclared becomes a call; quoted examples stay quoted; prose that merely names the tag stays clean (test-covered).

Validation

Python-only change in serve/; no engine code touched. Python 3.12, Linux x86_64.

Passed:

  • python -m unittest serve.test_unread_call_marker at this commit: 7 tests, OK. Same file on a pristine main (46c152a) worktree: fails (fenced block leaks with unread=0 / no unread_info), confirming the regression test captures the bug.
  • python -m pytest serve/test_frontend.py serve/test_parser_hold.py serve/test_parser_track.py serve/test_reasoning_rescue.py serve/test_parser_call_scan.py serve/test_tool_call_envelope.py serve/test_reasoning_tools.py serve/test_tool_name_alias.py serve/test_unread_call_marker.py: the FAILED list is byte-identical before and after this commit (diff of the sorted FAILED sets is empty).
  • serve/test_server.py -k "reject or unread": identical results before and after (see Failed).

Failed (pre-existing on pristine main, environment-bound, not caused by this change):

  • The 35 HTTP-level tests in the suites above (e.g. ForcedToolChoice::*, OverHttp::*) that require built engine binaries; this container has no engine build. Identical set on the pristine checkout.

Not run:

  • CUDA/HIP/SYCL builds — no C++/engine code is touched, so no backend recompilation applies; untested compatibility beyond that is not claimed.
  • A live end-to-end Open WebUI request against a build carrying this commit (the parser contract and the live upstream shape were each verified separately and are listed apart above).

Limits

  • Visibility only: a complete call for an undeclared name stays text by design (maintainer statement in #3796); this PR does not change that contract, only whether the client can see it happened.
  • unread_info keeps the same first-five cap as unread_names.
  • Fenced blocks now also increment tool_calls_unread, so /metrics counts move for shapes that were previously silent — intended, but consumers comparing pre/post dashboards should know.

🔄 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/4613 **Author:** [@james-martinez](https://github.com/james-martinez) **Created:** 10/29/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `f-4071-fenced-reject-marker` --- ### 📝 Commits (1) - [`f9ad906`](https://github.com/Niko1221/Strata/commit/f9ad906635ff1d4822d92f52b0bc0d1f7e419ad1) serve: a call-shaped block inside a code fence is counted and named too (#4071) ### 📊 Changes **4 files changed** (+161 additions, -8 deletions) <details> <summary>View changed files</summary> 📝 `docs/DETAILS.md` (+3 -2) 📝 `serve/frontend.py` (+37 -4) 📝 `serve/server.py` (+6 -2) ➕ `serve/test_unread_call_marker.py` (+115 -0) </details> ### 📄 Description ## Problem and result A Chat Completions request that declares no tools (or none matching what the model writes) gets an answer ending in a complete, well-formed `<tool_call>` block **inside a Markdown code fence** — what Open WebUI shows as "the tool XML appeared inside a code block". `tool_calls` is empty, `finish_reason` is `stop`, and the chat stores the markup as text. The rules that keep such a block as text both stay (declared-only #3075, code fence #1058); the reply text and `finish_reason` are unchanged. What changes is visibility: the fence path used to pass the block back **without counting it at all**, so a client could not distinguish "the model wrote a call and the parser dropped it" from "the model chose not to call". After this commit the fenced/inline-code block is counted and named like the other paths, and `strata_rejected_tool_calls` entries carry a `reason`. **Reproduced locally** (not static analysis): - Live: Qwen3.8-Flash-Next IQ3_S behind Strata 0.2.7 (rocm and sycl builds), toolless Chat Completions chat (Open WebUI), prompt "make an SVG and save it": complete `write_file` block in a ```xml fence in `content`, no `tool_calls`, `finish_reason: stop`; parser state `unread=0, unread_names=[]` — invisible to every signal #3796 added. - Parser at `main` (46c152a): the shape in `serve/test_unread_call_marker.py::FencedBlockIsCounted` fails on stock main (leak with `unread=0`), passes with this commit. ## Related discussion #4071 (this is the fenced variant of the reported failure), #3796 (the marker this completes), #3075/#1058 (the rules kept). No prior scope discussion needed per CONTRIBUTING ("focused fixes can go straight to a PR"); datapoint posted in #4071. ## Approach `OutputParser`'s fence / inline-code branch now runs the block through a shared `_mark_unread()`: it counts once and names once the function name has fully arrived (a partial name is held like a partial tag, so streamed and whole outputs count identically — checked at chunk sizes 1/3/17). Reasons: `undeclared`, `in_code` (a declared name quoted inside code), `malformed` (an opener with no readable name; counted as before, still unnamed, so the existing "malformed blocks have no name to list" contract is preserved). The two existing `unread += 1` sites route through the same helper. `serve/server.py` forwards the reasons in `strata_rejected_tool_calls`; the stdout warning and `tool_calls_unread` counter are unchanged apart from now including fenced blocks, which is what that counter was meant to measure. The Anthropic route shares `OutputParser`, so `/v1/messages` fenced blocks gain the same marker the JSON route already had for undeclared names. Nothing undeclared becomes a call; quoted examples stay quoted; prose that merely names the tag stays clean (test-covered). ## Validation Python-only change in `serve/`; no engine code touched. Python 3.12, Linux x86_64. **Passed:** - `python -m unittest serve.test_unread_call_marker` at this commit: 7 tests, OK. Same file on a pristine `main` (46c152a) worktree: fails (fenced block leaks with `unread=0` / no `unread_info`), confirming the regression test captures the bug. - `python -m pytest serve/test_frontend.py serve/test_parser_hold.py serve/test_parser_track.py serve/test_reasoning_rescue.py serve/test_parser_call_scan.py serve/test_tool_call_envelope.py serve/test_reasoning_tools.py serve/test_tool_name_alias.py serve/test_unread_call_marker.py`: the FAILED list is byte-identical before and after this commit (diff of the sorted FAILED sets is empty). - `serve/test_server.py -k "reject or unread"`: identical results before and after (see Failed). **Failed (pre-existing on pristine main, environment-bound, not caused by this change):** - The 35 HTTP-level tests in the suites above (e.g. `ForcedToolChoice::*`, `OverHttp::*`) that require built engine binaries; this container has no engine build. Identical set on the pristine checkout. **Not run:** - CUDA/HIP/SYCL builds — no C++/engine code is touched, so no backend recompilation applies; untested compatibility beyond that is not claimed. - A live end-to-end Open WebUI request against a build carrying this commit (the parser contract and the live upstream shape were each verified separately and are listed apart above). ## Limits - Visibility only: a complete call for an undeclared name stays text by design (maintainer statement in #3796); this PR does not change that contract, only whether the client can see it happened. - `unread_info` keeps the same first-five cap as `unread_names`. - Fenced blocks now also increment `tool_calls_unread`, so `/metrics` counts move for shapes that were previously silent — intended, but consumers comparing pre/post dashboards should know. --- <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#5110
No description provided.