[PR #4132] [CLOSED] [Engine] keep string arguments that quote a tool call or reopen their parameter exact (#4078) #4914

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

📋 Pull Request Information

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

Base: main ← Head: fix-4078-quoted-call-values


📝 Commits (2)

  • 0411a95 serve: a string argument that quotes a tool call or reopens its parameter stays exact (#4078)
  • affadaa serve: only a whole quoted <function=NAME> opener keeps a parameter value open (#4078)

📊 Changes

2 files changed (+90 additions, -14 deletions)

View changed files

📝 serve/frontend.py (+33 -14)
➕ serve/test_quoted_call_values.py (+57 -0)

📄 Description

Problem and result

A string tool argument that quotes a whole tool call, or reopens its own parameter, was cut by the output parser (#4078). Coding agents hit this when they write a parser fixture or a heredoc that contains call markup. The call still looked valid, but its argument was wrong:

  • A value that contains a complete <tool_call>…</tool_call> block was cut at the quoted call's </parameter>. The rest became assistant text.
  • A value that contains </parameter> followed by <parameter=content> (the same parameter name) lost its first part.
  • A heredoc command that prints a quoted call lost its tail.

After this change, these values come back byte for byte. This holds for non-streaming parsing and for streamed tool arguments at any chunk size.

#4078. This is a focused parser fix; no defaults or features change.

Approach

param_end already treats a </parameter> as part of the value unless the next tag is <parameter= or </function> (#210). Two cases still passed that test. This change adds two narrow rules:

  1. A </parameter> inside a call that the value itself opens is part of the value. The walk counts <function= against </function> from the start of the value. It accepts a close only when every quoted function is closed.
  2. A </parameter> followed by <parameter=NAME> for the parameter being read is part of the value. A model does not repeat a parameter name inside one call, so this is a value that quotes its own markup.

Callers pass the current parameter name (call_end, function_end, parse_tool_call and the streaming scanner). The streaming scanner now runs param_end from the start of the value so the balance count sees a quoted opener that an earlier chunk delivered. It runs the walk only when the new text holds a </parameter>, so long values do not rescan on every chunk. A 200 KB streamed value at 4-character chunks took 1.21 s with this change and 1.92 s before it (the before figure includes the old per-chunk scan).

Behavior that stays the same: prose between two calls still ends the first call, and a value with a bare </parameter> that is not followed by a parameter or function tag stays in the value as before (#210).

Validation

Passed:

  • python -m unittest serve.test_quoted_call_values -v on this branch (base 4b9e05a2), Linux, Python 3.14: 2 tests OK. The new test covers a quoted call, a quoted call at the end of the value, a heredoc and a repeated parameter. Each runs whole, streamed and non-streamed, in chunks of 1, 7 and the full length, plus a check that prose between two calls still ends the first. Before the change, the same test fails.
  • python -m unittest discover -s serve -t . -p 'test_*.py' on this branch: 1037 tests, 1 failure (listed under Failed), 12 skipped.
  • Hardware run on an RTX 5090 Laptop GPU (24 GB) with Qwen3.8 Flash-Next IQ3_S, a downstream build of v0.2.6 that carries this same param_end change plus unrelated local patches. Each case asked the model to copy a literal value into one tool call, then compared the argument bytes. Chat, Chat streaming and streaming Responses (through a Responses-to-Chat converter): before, the quoted-call, repeated-parameter and heredoc cases came back truncated or with the head dropped on every route. After, all three were exact on Chat and Responses. On Chat streaming, the heredoc case had one model copy error; two repeats gave one exact copy and one degenerate reply that hit the token limit (sampling at T=1.0, not the parser). Plain values and values with a bare </parameter> or </function> were exact before and after.

Failed:

  • serve.test_keepawake.KeepAwakeTests.test_service_holds_for_the_whole_request_including_early_close fails on unmodified 4b9e05a2 in the same environment too.
  • serve.test_responses.NoLeakedSampler.test_server_close_ends_the_sampler passed in the final run but failed in an earlier run of an earlier revision of this branch. It is timing-dependent in this environment.

Not run:

  • CUDA, HIP, SYCL and Metal builds: this change touches only serve/frontend.py and a new test, no backend code.
  • Windows and the GUI/TUI paths.
  • The hardware run used a downstream build, not stock v0.2.6.

Limits

  • A value that holds a bare </parameter> followed by </function>, with no quoted <function= before it, still ends at that close. Without an opener, the parser cannot tell quoted text from a real end.
  • #4077 (a bare-line closing think tag ends reasoning early) is a separate problem and is not addressed here.

🤖 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/4132 **Author:** [@Tsury](https://github.com/Tsury) **Created:** 10/25/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `fix-4078-quoted-call-values` --- ### 📝 Commits (2) - [`0411a95`](https://github.com/Niko1221/Strata/commit/0411a952213c06c7a83c0901a03302043a0e4ec3) serve: a string argument that quotes a tool call or reopens its parameter stays exact (#4078) - [`affadaa`](https://github.com/Niko1221/Strata/commit/affadaa4a2375363d7159cfbf48168ae14a8ef7f) serve: only a whole quoted <function=NAME> opener keeps a parameter value open (#4078) ### 📊 Changes **2 files changed** (+90 additions, -14 deletions) <details> <summary>View changed files</summary> 📝 `serve/frontend.py` (+33 -14) ➕ `serve/test_quoted_call_values.py` (+57 -0) </details> ### 📄 Description ## Problem and result A string tool argument that quotes a whole tool call, or reopens its own parameter, was cut by the output parser (#4078). Coding agents hit this when they write a parser fixture or a heredoc that contains call markup. The call still looked valid, but its argument was wrong: - A value that contains a complete `<tool_call>…</tool_call>` block was cut at the quoted call's `</parameter>`. The rest became assistant text. - A value that contains `</parameter>` followed by `<parameter=content>` (the same parameter name) lost its first part. - A heredoc command that prints a quoted call lost its tail. After this change, these values come back byte for byte. This holds for non-streaming parsing and for streamed tool arguments at any chunk size. ## Related discussion #4078. This is a focused parser fix; no defaults or features change. ## Approach `param_end` already treats a `</parameter>` as part of the value unless the next tag is `<parameter=` or `</function>` (#210). Two cases still passed that test. This change adds two narrow rules: 1. A `</parameter>` inside a call that the value itself opens is part of the value. The walk counts `<function=` against `</function>` from the start of the value. It accepts a close only when every quoted function is closed. 2. A `</parameter>` followed by `<parameter=NAME>` for the parameter being read is part of the value. A model does not repeat a parameter name inside one call, so this is a value that quotes its own markup. Callers pass the current parameter name (`call_end`, `function_end`, `parse_tool_call` and the streaming scanner). The streaming scanner now runs `param_end` from the start of the value so the balance count sees a quoted opener that an earlier chunk delivered. It runs the walk only when the new text holds a `</parameter>`, so long values do not rescan on every chunk. A 200 KB streamed value at 4-character chunks took 1.21 s with this change and 1.92 s before it (the before figure includes the old per-chunk scan). Behavior that stays the same: prose between two calls still ends the first call, and a value with a bare `</parameter>` that is not followed by a parameter or function tag stays in the value as before (#210). ## Validation **Passed:** - `python -m unittest serve.test_quoted_call_values -v` on this branch (base `4b9e05a2`), Linux, Python 3.14: 2 tests OK. The new test covers a quoted call, a quoted call at the end of the value, a heredoc and a repeated parameter. Each runs whole, streamed and non-streamed, in chunks of 1, 7 and the full length, plus a check that prose between two calls still ends the first. Before the change, the same test fails. - `python -m unittest discover -s serve -t . -p 'test_*.py'` on this branch: 1037 tests, 1 failure (listed under **Failed**), 12 skipped. - Hardware run on an RTX 5090 Laptop GPU (24 GB) with Qwen3.8 Flash-Next IQ3_S, a downstream build of v0.2.6 that carries this same `param_end` change plus unrelated local patches. Each case asked the model to copy a literal value into one tool call, then compared the argument bytes. Chat, Chat streaming and streaming Responses (through a Responses-to-Chat converter): before, the quoted-call, repeated-parameter and heredoc cases came back truncated or with the head dropped on every route. After, all three were exact on Chat and Responses. On Chat streaming, the heredoc case had one model copy error; two repeats gave one exact copy and one degenerate reply that hit the token limit (sampling at T=1.0, not the parser). Plain values and values with a bare `</parameter>` or `</function>` were exact before and after. **Failed:** - `serve.test_keepawake.KeepAwakeTests.test_service_holds_for_the_whole_request_including_early_close` fails on unmodified `4b9e05a2` in the same environment too. - `serve.test_responses.NoLeakedSampler.test_server_close_ends_the_sampler` passed in the final run but failed in an earlier run of an earlier revision of this branch. It is timing-dependent in this environment. **Not run:** - CUDA, HIP, SYCL and Metal builds: this change touches only `serve/frontend.py` and a new test, no backend code. - Windows and the GUI/TUI paths. - The hardware run used a downstream build, not stock v0.2.6. ## Limits - A value that holds a bare `</parameter>` followed by `</function>`, with no quoted `<function=` before it, still ends at that close. Without an opener, the parser cannot tell quoted text from a real end. - #4077 (a bare-line closing think tag ends reasoning early) is a separate problem and is not addressed here. 🤖 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:31:18 +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#4914
No description provided.