Repository navigation
server: keep tool markup quoted in Markdown code spans and fences as prose - #3588
Merged
Merged
Conversation
ashhart
added a commit
that referenced
this pull request
Nov 17, 2026
ashhart
added a commit
that referenced
this pull request
Nov 17, 2026
This was referenced Nov 17, 2026
Closed
…prose Tool-call openers quoted inside Markdown inline code spans (`...`) or fenced code blocks (```...``` or ~~~...~~~) in generated assistant prose were treated as live call openers. Quoted `<tool_call>` tags paired with a following real call's `</tool_call>` and rejected it, quoted `<tool_call>NAME<arg_key>...` fragments naming an offered tool streamed bogus arguments, and complete quoted calls inside prose or code blocks executed as tool calls. Add a linear-time Markdown code-span and fence scanner (reply_code.zig) and wire it into whole parsing (tool_parse.zig), streaming call deltas (tool_stream.zig), single-call prose filtering (tool_policy.zig), prose hiding and thinking-tail lifting (reply_text.zig, reply_tool_tail.zig), LFM2 rewrites (tool_lfm2.zig), logprob ranges (logprob_parts.zig), and EOS call closing (chat_generation.zig). While streaming, an inline backtick span containing a tool opener waits until a matching closer confirms code or a paragraph break or end proves it literal. zig build test-tool-parse-host test-tool-visibility-http-host test-thinking-tail-host, zig build test test-golden dev-tools -Dcpu=apple_m1, zig fmt --check build.zig zig, and python3 tools/pr_check.py --base origin/main pass.
ashhart
force-pushed
the
fix-prose-quoted-tool-calls
branch
from
November 17, 2026 09:32
98f2d0d to
483de20
Compare
Owner
|
Thank you @gilby. This is merged into main with your commits under your own name, so you're listed as a TensorFold contributor. It ships in the next release, credited to you in the changelog and the release notes. |
This was referenced Nov 19, 2026
outcastofmusic
added a commit
to outcastofmusic/TensorFold
that referenced
this pull request
Nov 25, 2026
…ashhart#3588) A reply that showed a call in backticks or a code fence ran it as a live call, and the stream hid it. code_spans.py scans CommonMark inline spans and fences in linear time, as upstream's reply_code.zig does. The whole parsers (Qwen XML, namespaced, Gemma, DSML, LFM2's list), the end-token closer, the streamed deltas, the stream's prose hider, the one-call filter and the thinking split skip a quoted opener. While streaming, an opener that may still turn out quoted waits. ThinkCall leaves an opener quoted in the thinking where it is. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012882unKVWq5Ve1jHg3xizt
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.
What this changes
Tool-call markup quoted inside Markdown inline code spans or fenced code blocks (backtick or tilde fences) in assistant prose previously opened, hid trailing prose, rejected following real calls, or parsed and streamed as live tool calls; a linear-time Markdown code-span and fence scanner keeps code-quoted call markup as prose across whole-reply parsing, SSE streaming, single-call filtering, thinking-tail lifting, LFM2 rewrites, logprob ranges, and EOS call closing while leaving whole-reply bare JSON fences unchanged.
zig/src/server/reply_code.zigis written from scratch following CommonMark inline code-span and fenced code-block rules, andzig/src/server/tool_policy.zigis a structural split fromzig/src/server/tool_stream.zigto keep every file within 600 lines.077998f7d9b14adebec3a2acc2caa47ff7ae6ec7), commit98f2d0df00dafa5c5c478ea6bdc1c3b325d83d55.atc overlap --json: run2026-11-16T16:25:56Zon head98f2d0df00dafa5c5c478ea6bdc1c3b325d83d55against base077998f7d9b14adebec3a2acc2caa47ff7ae6ec7(incomplete due to ATC limitsmyPullRequestsLimit,otherPullRequestsLimit,pullFilesUnavailable,pullRequestsLimit,timeLimit). Overlaps againstworkingTree: Living Weights: slide-forget counting only with --slide-forget, Metal's mask shift for wide pockets (#678) #2026, ricursive: speed up Ripple-65B on two GB10s #2523, ricursive: serve Ripple-65B on two GB10s with up to 1M tokens of context #2522, and Nemotron 3.5 Transcribe: audio input, the 65,536-token window, an hour of audio, MTP drafts #1632 are clean (0 conflictFiles); server: split recipient-addressed replies into reasoning, answer and tool calls #1336 (base3885dceb2) and Muse Spark Open on CUDA, on two GB10s #1295 (base6c5cef894, stacked on server: split recipient-addressed replies into reasoning, answer and tool calls #1336) report conflicts onzig/src/server/chat_generation.zigandzig/src/server/root.zig— both server: split recipient-addressed replies into reasoning, answer and tool calls #1336 and Muse Spark Open on CUDA, on two GB10s #1295 are alreadyCONFLICTING(DIRTY) againstorigin/mainbefore this PR, with server: split recipient-addressed replies into reasoning, answer and tool calls #1336 modifying the same EOSc.finishCutblock inchat_generation.zigand adjacentroot.zigtest imports.Checks on this head
98f2d0df00dafa5c5c478ea6bdc1c3b325d83d55python3 tools/zig/lean_check.py, on the base and on this head: base077998f7d9b14adebec3a2acc2caa47ff7ae6ec7->6578 files, 221 problems(inherited); head98f2d0df00dafa5c5c478ea6bdc1c3b325d83d55->6578 files, 221 problems(python3 tools/zig/lean_new.py->lean: 221 problems, 221 on the base, 0 new;python3 tools/pr_check.py --base origin/main->lean 221 vs 221, 0 new, 0 errors, all 12 changed files<= 600lines).origin/main(077998f7d):zig build test-tool-parse-host --summary allfailed (76 pass, 4 fail (80 total)— all 4 new tests intool_parse_visibility_test.zigred) andzig build test-tool-visibility-http-host --summary allfailed (28 pass, 3 fail (31 total)— all 3 new tests intool_prose_code_http_test.zigred). Mutation checks bypassingcode.checkper module failed as expected (zig build test-tool-parse-host:tool_parse.zig->80 pass, 2 fail;reply_text.zig->80 pass, 2 fail;tool_stream.zig->81 pass, 1 fail;tool_policy.zig->80 pass, 2 fail). Post-fix on98f2d0df00dafa5c5c478ea6bdc1c3b325d83d55:zig build test-tool-parse-host test-tool-visibility-http-host test-thinking-tail-host --summary all(9/9 steps succeeded; 150/150 tests passed—82/82,31/31,37/37),zig build test test-golden dev-tools -Dcpu=apple_m1 --summary all(1076/1076 steps succeeded; 14232/14350 tests passed (118 skipped);test-golden:55/55and322/335equal to server goldens,0 unexpected differences;dev-toolsbuilt),zig build -Dcpu=apple_m1 --summary all(297/297 steps succeeded),zig build test-kernel-contract -Dcpu=apple_m1 --summary all(34/34 steps succeeded; 241/241 tests passed),zig fmt --check build.zig zig(exit 0), andgit diff --check origin/main..HEAD(exit 0).98f2d0df00dafa5c5c478ea6bdc1c3b325d83d55(not pushed yet; will update once CI runs).npm), and live GPU inference benchmarks were not run locally because this host is macOS Apple Silicon (Metal host suite only) and the change only touches post-decode UTF-8 reply-text parsing and SSE filtering inzig/src/server/, which cannot reach inference kernels, weights, or KV caches.Receipt
zig/src/server/cannot reach model forward passes or inference cells.077998f7d9b14adebec3a2acc2caa47ff7ae6ec7, head98f2d0df00dafa5c5c478ea6bdc1c3b325d83d55, Zig0.17.0, Apple M5 Max (48 GB, macOS 27.0.1) running host/Metal-host test targets (-Dcpu=apple_m1); checkpoint and revision: n/a (no weights loaded; unit and HTTP/golden host tests only).tool_parse,reply_text,tool_stream,tool_policy,reply_tool_tail,tool_lfm2,logprob_parts, andchat_generationacross non-streaming and SSE Chat Completions, Anthropic Messages, Responses, and Ollama chat formatting; ran on macOS Apple M5 Max (-Dcpu=apple_m1/ native host); did not run Linux, Windows, CUDA, HIP, XPU, or Metal M1–M4 hardware.tools/bench_concurrent.py --alone --serialortoken_shaagainst"draft": false: n/a — cannot reach token generation, drafting, KV state, or prompt execution.zig/src/server/with no effect on generated tokens or engine throughput; parity with main is covered byzig build test test-golden -Dcpu=apple_m1.tools/bench_openai.py: n/a — cannot reach token decode.ttft_sfromtools/bench_cache.py --require-coldon a long prompt, or "n/a" with the reason when the change cannot reach prompt processing: n/a — cannot reach prompt processing.Checklist