Repository navigation
fix(server): DSML tool calls are read from their own tags, never re-read as <tool_call> text - #20
Merged
bertholomus merged 1 commit intoOct 19, 2026
Conversation
…ead as <tool_call> text
A DSML calls block was rewritten as <tool_call>{json}</tool_call> text and parsed again, so the text around a call
could move its bounds. A <tool_call> in the prose before a block, or a </tool_call> inside an argument (a file being
written, an edit's new text), cut a call short; the call then reached the client as that rewritten text and never ran.
A call to a tool the request did not offer also reached the client as <tool_call> text: call syntax the model never
wrote, which the conversation then carries back to it.
Each DSML block is now read from its own tags; the <tool_call> forms are parsed only in the text around the blocks,
and calls keep the reply's order. A call to a tool the request did not offer is returned as a call, so the client
answers it as it answers any unknown tool; one call a reply (parallel_tool_calls false) still skips it. The call
streamer reads only the text before the first DSML block, so a Qwen-style call quoted in an argument is never streamed
as a call (the handler counts streamed calls as the first of the final ones).
Replies with only offered tools and no <tool_call> tag in their text parse as before: 20,000 generated replies, each
parsed with both call limits (40,000 parses), differ only where a reply has a stray tag or an unoffered tool, the cases
above. 21 calls that reached clients as text in real sessions all come back as calls; each leaks again with the old
reader. tests/test_cuda_dsml_calls.py: 7 new.
Owner
|
Thank you @willjriley! The tests pass here, and a reply without a DSML block is unchanged. This one changes what a few replies return (a call to a tool the request did not offer, an argument holding |
Owner
|
Thank you @willjriley — merged on |
Merged
6 of 8 tasks
bertholomus
pushed a commit
that referenced
this pull request
Oct 20, 2026
…<tool_call> text (the native side of #20) The native parser collected the <tool_call> forms and DeepSeek-V4.1's DSML blocks independently and kept whichever started first. A <tool_call> in the prose before a block, with a </tool_call> in one of its arguments (a file being written), swallowed the start of the block: the call was dropped and reached the client as text. A call to a tool the request did not offer was rewritten as <tool_call>{json}</tool_call>, call syntax the model never wrote. And the call streamer read the whole answer, so a Qwen-style <tool_call><function=NAME> quoted in a DSML argument streamed as a real call to NAME when that tool was offered, and the reply's DSML calls were then never sent (tool_calls_streamed). DSML blocks are now found first and the other forms only in the text around them; every invoke is a call, under the model's own name when the request did not offer it (with one call a reply, such an invoke drops out as before); the streamer is fed beforeDsml(answer), the text before the first DSML block. As 222a9c0 did for the Python server. Tests: the unoffered-tool case now expects a call; a new test covers a <tool_call> in the prose, a </tool_call> and a whole call in an argument, and calls in the reply's order. Both fail before this change.
bertholomus
added a commit
that referenced
this pull request
Oct 20, 2026
bertholomus
added a commit
that referenced
this pull request
Nov 2, 2026
…s are A <tool_call> in the prose before a V4.1 calls block, with a </tool_call> in one of its arguments (a file being written), swallowed the start of the block: the call was dropped and a call quoted in the argument was made instead. A form quoted inside a block could also consume the call written after it, and a call quoted in an unclosed block was made. The call streamer read inside V4.1 blocks, so a quoted <tool_call><function=NAME> streamed as a call when NAME was offered, and the reply's own calls were then never sent. The parser now reads V4.1 blocks first and the other forms only in the text around them (a V4.1 opener inside a V4 block stays that block's text); an unclosed block stays text, whole, as V4's does, and closeCall closes only a call past the last block. The streamer reads a V4.1 block whole: before any call has streamed it leaves the reply's calls to the end, as it always has; after one, the block's calls stream when it closes, in the reply's order, as V4's do. An offered name is matched stripped, as the served lane's parse of its rewritten call strips it. A call to a tool the request did not offer keeps the lane's rewrite. A port of Manrique's 4803479 ("the native side of #20", on the two-node line) to the four-node line's DSML containment design; the test of a <tool_call> around and inside a block is theirs. A reply whose V4.1 blocks have no other call form inside, beside or across them, and no padded name, parses and streams as before. Co-authored-by: Manrique <[email protected]> Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The bug. The DSML reader rewrote each DSML calls block as
<tool_call>{json}</tool_call>text and then parsed that text again, so anything call-like around a call could move its bounds:</tool_call>inside an argument (a file being written, an edit's new text), or a<tool_call>in the prose before a block, cut the call short. The call then reached the client as that rewritten text and never ran.<tool_call>text. That is call syntax the model never wrote, which the conversation then carries back to it.We hit this in long agent sessions: 21 calls in two sessions reached the client as text.
The fix. Each DSML block is read from its own tags. The
<tool_call>forms are parsed only in the text around the blocks, and calls keep the reply's order. The call streamer reads only the text before the first DSML block, so a Qwen-style call quoted inside an argument is never streamed as a call.One deliberate change in behavior: a call to a tool the request did not offer is now returned as a call, so the client answers it the way it answers any unknown tool. Before, it came back as
<tool_call>text. Withparallel_tool_calls: false(one call a reply), it is still skipped.Unchanged where there was no bug. We generated 20,000 replies and parsed each with both call limits (40,000 parses). Every difference from the current reader is in a reply with a stray tag or an unoffered tool. All 21 real leaked calls come back as calls, and each leaks again with the current reader.
Tests.
tests/test_cuda_dsml_calls.pygets 7 new tests (all pass):The four existing tool-call test files (
test_cuda_tool_choice,test_glm_tool_calls,test_think_call,test_cuda_server_stream) give 44 passed and 3 skipped, before and after.Prepared with Claude Code.