Repository navigation
fix: tool call text no longer leaks into chat output when provider chunks split a call marker - #169172
Conversation
…l marker
A buffered tail that is still an unfinished call marker ("<funct", "<|channel|>")
was replayed as a false-positive prefix when a complete call preceded it, so the
rest of the call arrived mid-buffer and was emitted as visible text. Hold the
buffer while the tail can still complete into a call, replay only decided
false-positive prefixes, and route trim bookkeeping through one helper so the
done/error/EOF paths share the same chunk-independent decision.
Regression tests cover a replayed false prefix, a stacked function call, and a
stacked Harmony call split across chunks.
Refs openclaw#169161
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Codex review: needs maintainer review before merge. What this changesThis PR buffers split tool-call markers and preserves visible text, reasoning order, and content-block offsets during replay. Example: A provider sends
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review Keep this PR open: it repairs a concrete current-main output defect, the supplied production-path proof covers the repair, and all prior findings are addressed. Priority: P2 Before mergeNone. FindingsNone. Agent review detailsHow this fits togetherThe shared tool-call repair package receives provider text and lifecycle events, applies the existing request-scoped grammar, and emits sanitized stream events and normalized terminal messages. flowchart TD
A[Provider SSE chunks] --> B[Provider stream wrapper]
B --> C[Shared stream normalizer]
C --> D[Canonical call grammar]
C --> E[Bounded suppression]
C --> F[Visible text and reasoning]
C --> G[Normalized terminal message]
Technical reviewBest possible solution: Land the focused shared-normalizer repair while retaining the existing grammar, request tool allowlist, and bounded suppression contract. Do we have a high-confidence way to reproduce the issue? Yes: current-main classification exposes the unfinished suffix for the reported two-chunk input, and supplied SSE/Gateway baseline results independently demonstrate that path; this review ran no target code. Is this the best way to solve the issue? Yes: the repair changes the shared classification owner and preserves replayed text and reasoning rather than filtering leaked output downstream. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 229125877639. Provenance checked
TestingProof path: shipped entry point. SecurityNone. EvidenceWhat I checked:
PR surfaceSource +305, Tests +168, Other +1. Total +474 across 4 files. Added test files: 0. View PR surface stats
Review metrics
LabelsLabel changes:
Label justifications:
Rating scale6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior. WorkflowClawSweeper edits this one comment on every review. Comment HistoryReview history (6 earlier review cycles)
Reviewed October 14, 2026, 12:09 AM ET / 04:09 UTC (Revision 7). |
The split-marker buffering added in the previous commit diverged from the
unsplit stream when an authoritative text_end extended the same content block
("hello\n[read]\n{}\nX\n " lost the call placeholder). Classify
delta-path buffers with the same finalize context as snapshots, keep the block
offset when a text_end extends a buffered snapshot, and track per-content-index
consumed input length so non-authoritative replays slice from the right origin.
Adds three regression tests (plain text and Harmony, delta and text_end split
shapes); stream-normalizer suite 58/58 and packages/tool-call-repair +
normalization-core 445/445 pass, fuzz seed=1 20k iters failures 71 -> 56 and
leakToSplit 18 -> 10 versus the previous commit.
Refs openclaw#169161
The previous uploads kept a CRLF final newline captured from the local working copy; the repository stores these files as LF, so the PR diff picked up a spurious trailing-line change on both files. No code changes. Refs openclaw#169161
check-lint failed on the previous commit because the three added it.each rows exceeded the formatter width; run oxfmt's default formatting on the test file (source file already clean). No behavior change. Refs openclaw#169161
Replays each false-positive prefix segment with its own content block template and unit accounting instead of the latest template, and interleaves the replayed text with queued reasoning in arrival order. Every trim path (delta, done, error, queue overflow, EOF) now drains buffered auxiliary events before clearing the candidate queue. Adds regression tests for the three review repros.
|
Updated after the review at 1. Terminal trims drain buffered auxiliary events. 2. Prefix replay keeps each segment on its original content block. Replay segments are built from the candidate parts, each using its own block's event template and per-block emitted-unit accounting instead of the latest template. The review repro ( 3. Replay preserves text/reasoning arrival order. Queued entries now record the buffer offset they were queued at, and the decided prefix is split at those offsets so text and reasoning replay in the order they arrived. The review repro ( Verification on the changed sources (same mirror harness the PR body describes): On the remaining proof item: this environment cannot run the Telegram Test Server E2E — no test-server credentials, and the Gateway cannot be provisioned from this Windows checkout. The PR body now says so explicitly. If the E2E recording is a hard gate, please point me at who can run the repository E2E skill, or the setup you expect, and I will prepare the script. @clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
Small follow-up commit @clawsweeper re-review |
|
🦞👀 Re-review progress:
|
…lock A trim can drop earlier content blocks whole, so the retained suffix can start inside a later block. Advancing snapshotOffset by the concatenated buffer's removed length made authoritative text_end reconciliation slice at the wrong origin: the f865603 review repro ('[read]' then 'x\n<function=read>' plus text_end) leaked 'ion=read></function>' as visible text. Derive the new origin from the original part that contains the retained suffix so replay slicing and cumulative snapshots agree, and add the cross-block cumulative-snapshot case to the block-index regression.
|
Fixed the remaining P2 from the latest review in Trimmed snapshot origins stay local to the retained block. The repro you gave ( The cumulative-snapshot repro is now part of the block-index regression ( Verification in the same mirror harness as the previous revisions: On the proof item: this environment still cannot run the Telegram Test Server E2E (no test-server credentials; the Gateway cannot be provisioned from this Windows checkout), as noted in the body. If that recording is a hard gate, please point me at who can run the repository E2E skill or what setup you expect, and I will prepare the script. @clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
Read the revision-4 verdict. Confirming my understanding: no code findings remain, and the only open item is the Before asking again, I re-checked both proof paths available from this side:
So the Test Server recording can only come from a credential owner or maintainer running If neither path is available, the reasonable alternatives are a same-repo replacement PR (source PR credited) so the requested-proof lane becomes admissible, or maintainer judgment on the current head. Nothing is left to change on the code side; the head stays |
Keep the stream coordinator below its inherited line budget by moving the existing oversized-payload state machine into a sibling module. Preserve the shared grammar and request tool allowlist, and strengthen marker-split regressions with independent visible-text expectations.
… inventory 6caf20c moved the bounded stream suppression state machine into packages/tool-call-repair/src/stream-normalizer-suppression.ts, but scripts/pr only extracts scripts/pr, scripts/pr-lib, and the paths listed in wrapper-components.txt. Without the entry the extracted anchor cannot resolve ./stream-normalizer-suppression.js, so eager-import-closure fails on the PR wrapper inventory and on the extracted dependency context.
|
Fixed the remaining P2 in Wrapper inventory now covers the extracted suppression module. Exact-head CI on
The change is inventory-only: one added line, no edits to the suppression module, the normalizer, the tests, or any other runtime import. If |
|
Merged via squash.
|
…unks split a call marker (openclaw#169172) * fix(tool-call-repair): keep call text private when chunks split a call marker A buffered tail that is still an unfinished call marker ("<funct", "<|channel|>") was replayed as a false-positive prefix when a complete call preceded it, so the rest of the call arrived mid-buffer and was emitted as visible text. Hold the buffer while the tail can still complete into a call, replay only decided false-positive prefixes, and route trim bookkeeping through one helper so the done/error/EOF paths share the same chunk-independent decision. Regression tests cover a replayed false prefix, a stacked function call, and a stacked Harmony call split across chunks. Refs openclaw#169161 * fix(tool-call-repair): align split-stream replay with the block origin The split-marker buffering added in the previous commit diverged from the unsplit stream when an authoritative text_end extended the same content block ("hello\n[read]\n{}\nX\n " lost the call placeholder). Classify delta-path buffers with the same finalize context as snapshots, keep the block offset when a text_end extends a buffered snapshot, and track per-content-index consumed input length so non-authoritative replays slice from the right origin. Adds three regression tests (plain text and Harmony, delta and text_end split shapes); stream-normalizer suite 58/58 and packages/tool-call-repair + normalization-core 445/445 pass, fuzz seed=1 20k iters failures 71 -> 56 and leakToSplit 18 -> 10 versus the previous commit. Refs openclaw#169161 * chore(tool-call-repair): store the touched files with LF line endings The previous uploads kept a CRLF final newline captured from the local working copy; the repository stores these files as LF, so the PR diff picked up a spurious trailing-line change on both files. No code changes. Refs openclaw#169161 * style(tool-call-repair): format the new test cases with oxfmt check-lint failed on the previous commit because the three added it.each rows exceeded the formatter width; run oxfmt's default formatting on the test file (source file already clean). No behavior change. Refs openclaw#169161 * fix(tool-call-repair): keep trim replay order and drain buffered aux Replays each false-positive prefix segment with its own content block template and unit accounting instead of the latest template, and interleaves the replayed text with queued reasoning in arrival order. Every trim path (delta, done, error, queue overflow, EOF) now drains buffered auxiliary events before clearing the candidate queue. Adds regression tests for the three review repros. * test(tool-call-repair): cover terminal trim drains for done, error, and queue cap * fix(tool-call-repair): keep trimmed snapshot offsets local to their block A trim can drop earlier content blocks whole, so the retained suffix can start inside a later block. Advancing snapshotOffset by the concatenated buffer's removed length made authoritative text_end reconciliation slice at the wrong origin: the f865603 review repro ('[read]' then 'x\n<function=read>' plus text_end) leaked 'ion=read></function>' as visible text. Derive the new origin from the original part that contains the retained suffix so replay slicing and cumulative snapshots agree, and add the cross-block cumulative-snapshot case to the block-index regression. * refactor(tool-call-repair): isolate bounded stream suppression Keep the stream coordinator below its inherited line budget by moving the existing oversized-payload state machine into a sibling module. Preserve the shared grammar and request tool allowlist, and strengthen marker-split regressions with independent visible-text expectations. * fix(pr-wrapper): list the extracted suppression module in the wrapper inventory 6caf20c moved the bounded stream suppression state machine into packages/tool-call-repair/src/stream-normalizer-suppression.ts, but scripts/pr only extracts scripts/pr, scripts/pr-lib, and the paths listed in wrapper-components.txt. Without the entry the extracted anchor cannot resolve ./stream-normalizer-suppression.js, so eager-import-closure fails on the PR wrapper inventory and on the extracted dependency context. --------- Co-authored-by: Peter Steinberger <[email protected]>
Fixes #169161
What Problem This Solves
Fixes: serialized tool-call syntax appears briefly in replies when a provider splits a stream inside a function or Harmony marker.
User Impact
The covered marker splits now produce the same visible text as one-chunk delivery. Literal text, reasoning order, content indexes, terminal snapshots, and the existing request-scoped tool allowlist remain intact. No configuration or prompt changes are required.
Pre-existing limitation: arbitrary malformed false-prefix/cumulative-snapshot replay and the disclosed two-space indentation case are not claimed to be universally chunk invariant. No live Telegram send/receive proof is claimed. ClawSweeper accepts the macOS SSE/Gateway evidence for this unchanged transport path.
Why This Change Was Made
Keep unfinished candidate tails buffered until the existing grammar can decide them. The contributor's replay accounting preserves each content block's offset and interleaves retained reasoning when a decided prefix is replayed. The existing oversized-payload suppression state machine is extracted into a sibling module so the coordinator does not grow past the current line-cap ratchet; its byte bound and behavior are unchanged.
Thanks @JasonBuildAI for the original repair and regression cases. All contributor commits are preserved, followed by a merge from current main and the focused extraction/test follow-up.
Evidence
macOS arm64, isolated state/config/workspace, loopback fixture and Gateway only; shared Ollama models were left loaded.
976cc974fab1912c696d1101bd17a1abf05eb77e: real OpenAI-compatible SSE transport through the production agent wrapper emits no visible text for an unsplit call sequence, but leaks the second call for splits inside<function=,<|channel|>, and<|channel|>comm. Terminal messages agree on two parsedreadcalls. Through a real isolated Gateway, the split function appears in an assistant event before a later replacement clears it; the durable transcript retains the two parsed calls. The empty second call is rejected for missing arguments, rather than executing another action.6caf20c659cac6efa86f143912f2b5ae44167913: scoped-clean, no actionable P0–P2 findings.qwen3:4bturn through the Gateway returned a complete sentence without tools in 46.19 s on the baseline. This is inference control; scripted SSE establishes the malformed-byte regression.Runtime proof (
6caf20c659cac6efa86f143912f2b5ae44167913; unchanged at final headb593f059b977ecb0aeb3b97f7edc40555734406d):The real compatible transport emits no marker text for all three split shapes. With reasoning enabled, the wire replay preserves
[read]→ thinkingchecking→ newline in arrival order, with the same terminal content.A built, isolated Gateway emits only
Fixture complete.for unsplit (8.990 s), split function (4.719 s), split channel (0.473 s), and split commentary (0.637 s); all retain two parsed read calls in history. The replay control retains[read]without leaking the incomplete function (0.402 s). A real Ollamaqwen3:4bturn completes through that Gateway in 22.295 s with no tools. These timings include RPC/history work and are not performance comparisons.OPENCLAW_RUN_NODE_SKIP_DTS_BUILD=1 pnpm buildpassed in 8m24.6s, including bundled-plugin, CLI import, and runtime postbuild checks. The full declaration-bundle attempt was intentionally stopped during its slow shared-package phase; standalonepnpm tsgo:coreand a scoped test typecheck both pass.Scoped type-aware lint and formatting pass. Max-lines, line-cap, assertion-safety, timeout-race, mock-export, config-docs, and plugin-inventory ratchets pass without baseline changes.
Initial exact-head CI 38504961005 found the new suppression helper missing from the archived PR-wrapper inventory. The follow-up registers that file. The contributor independently added the identical inventory fix in
b593f059b977ecb0aeb3b97f7edc40555734406d, which is retained. Its Git tree matches the locally tested correction exactly. Both failing eager-import-closure tests pass (2/2 selected; 46.95 s command wall, 37.08 s Vitest duration). This follow-up changes only inventory metadata, so the runtime proof above is reused. ClawSweeper’s review of6caf20caccepts the Mac SSE/Gateway proof and identifies only this inventory omission; that finding is repaired by the retained contributor commit. Corrected-head CI 38507202210 passes, includingopenclaw/ci-gate. ClawSweeper reviewed exact headb593f059b977ecb0aeb3b97f7edc40555734406d: ready for maintainer review, zero findings, no before-merge items. No earlier-head green result is reused.Independent Codex review of final head
b593f059b977ecb0aeb3b97f7edc40555734406d: scoped-clean, no actionable P0–P2 findings.Production: +674 / -369 lines (net +305); tests: +168 / -0; wrapper inventory: +1 / -0. The added replay accounting is retained because removing it reintroduces observed loss of reasoning, block indexes, or cumulative-snapshot text. The extraction satisfies the per-file ratchet without weakening it; no unrelated code was deleted to disguise the net growth. No dependency, public API, prompt, config, or stored-transcript format changes.