Skip to content

fix: serialized tool-call XML leaks into chat replies - #138204

Merged
steipete merged 9 commits into
openclaw:mainfrom
ericcaiwx-star:fix/assistant-visible-glm-arg-key
Oct 11, 2026
Merged

steipete merged 9 commits into
openclaw:mainfrom
ericcaiwx-star:fix/assistant-visible-glm-arg-key

Conversation

@ericcaiwx-star

@ericcaiwx-star ericcaiwx-star commented Sep 4, 2026 •

Copy link
Copy Markdown
Contributor

Closes #138198
Related: #153594, #153635

What Problem This Solves

Fixes raw GLM and invocation XML appearing in streamed and final chat replies when a model writes a tool request or a shadow copy as ordinary text.

User Impact

Replies retain visible prose while hiding internal tool XML, including partial streaming prefixes. Completed literal explanations and inline, fenced, or indented code examples remain visible. Native calls continue to execute exactly once. No configuration or migration is required.

Known limitation: artifact-only replies without a native call or visible answer reach the existing empty-reply format failure (chat state aborted, no message). The baseline's already-supported JSON envelope reproduces that terminal behavior. Original transcript bytes remain intact.

Why This Change Was Made

The existing assistant-visible-text.ts sanitizer owns GLM arg_key payloads and bare, antml, and mm invocation forms. Stream fallback, block snapshots, and completed payloads consume that owner. It holds ambiguous opening fragments during streaming, restores terminal literals, and carries XML context only across consecutive same-phase text parts, ending it at native tool/thinking blocks.

This preserves @ericcaiwx-star's contributor commits and incorporates @ruiling-smartbear's distinct invocation cases with Ruilin Gao's co-author credit. The competing reply-token scanner was not carried forward.

Main 6b8e69e470765791cd8ac91d721b497f9b58948b was merged without rebasing. The sole conflict uses main's current subagent QA expectation, removing this branch's superseded assertion correction. One additional unused local binding inherited from main was removed to fix core typecheck error TS6133; environment-consuming callers are unchanged. The separately filed Memory QA issue is outside this repair.

Evidence

Validation head: 84b0dfe52fbad2bd5c53aa513adf59ec59819d32.

  • 210 focused tests pass in 72.91s wall, including the registered Telegram adapter. The tests ran after merging main; sanitizer/test bytes are unchanged by the subsequent unused-binding deletion. The original 30 handler regressions failed on main; six additional native-boundary cases failed before their repair. Final handler suite: 36 cases.
  • Targeted lint and formatting pass. Core types pass after the unused-binding cleanup (6.79s). Required line-cap, max-lines, assertion-safety, timeout-race, mock-export, config-doc, and plugin-inventory ratchets pass.
  • Fresh isolated Codex autoreview on the validation head: scoped-clean through P2.
  • Final full build: passed, 247.22s wall. Final isolated Gateway replay: all 11 cases passed, 26.538s total turn wall time.
  • Production +295/-109 (net +186); tests +323/-4 (net +319); docs +1. Production growth handles streaming ambiguity, terminal restoration, and native block boundaries. The contributor's per-test Gateway boot was replaced by focused handler tests and the actual Gateway replay.

The replay uses the built Gateway's real WebSocket chat.send entry point and a local OpenAI-compatible SSE fixture provider. It covers GLM shadow text; bare, antml, mm, and plain function_calls wrappers; native exec plus a shadow copy; artifact-only GLM/invoke/legacy JSON; and literal/code controls. Baseline main leaked XML. Candidate reply deltas, snapshots, finals, assistant events, and preambles contain no leaked markup; the native control executes once and returns XML_PROOF_OK; literal/code examples preserve exact bytes.

The campaign lead explicitly accepts this isolated Gateway replay as the required boundary proof and overrides proof-only live-Telegram holds. Live Telegram receipt and live GLM generation are not claimed. ClawSweeper reviewed this exact head on October 11 at 00:07 UTC after the single re-review request: no actionable findings. Its proof-only Telegram hold is lead-overridden. Its remaining request for CI attribution is addressed below.

Inherited Memory QA failure

The lead accepted READY-WITH-INHERITED-QA if the remaining CI failure is memory-dreaming-sweep, and filed that issue separately. Actual same-environment attribution used the unmodified scenario/planner/model-selection/profile configuration, fresh isolated state, macOS arm64, Node v26.11.1, pnpm12.9.0, and the smoke-ci mock-openai/Crabline Telegram defaults:

Source Exact SHA Result Wall time
Previous PR head 5eff359970282911ca2d4bf60093423fddd86b5f PASS; all three steps, one candidate/promotion, canary/marker and Light Sleep/REM artifacts, restored configuration 210.31s
Main 0e6b2c23c8d55292b67c6835c22c85dec6d0a575 FAIL; both built-in attempts complete with zero candidates/promotions, then 180000ms promotion-artifact timeout 512.99s

Each checkout was built with OPENCLAW_BUILD_PRIVATE_QA=1 pnpm build qaRuntime, then ran pnpm openclaw --profile <isolated-profile> qa run --repo-root . --qa-profile smoke-ci --concurrency 10 --output-dir <isolated-output> --scenario memory-dreaming-sweep. Matching private-QA flags, a 180000ms transport-readiness setting, separate parent state/config paths, and task TMPDIR were supplied. No model pin, manual retry, or scenario timeout change was used. These local runs establish source attribution; hosted CI uses Linux/Node24.

Current exact-head CI run 38096487544 completed with 47 successful jobs and four inherited failed jobs, so the aggregate gate remains red. No rerun was requested. It tested merge 28e7d321bc7595dab322999ac32ca6bcd7351a50 against main 6cc0e8460192d6dae2f1f3622665755d09b908b7.

In addition to the accepted Memory QA failure, the exact executed main independently reproduces all additional failures:

  • checks-node-compact-small-5: SDK surface budgets fail at exports3672>3656, callables2133>2122, deprecated158>154, and deprecated entrypoint counts1>0/3>0. Main commit eacb83742946 (feat(plugin-sdk): add worker-owned conversation binding APIs #168483) added conversation-binding exports without updating the budgets. The same SDK test fails on main in9.27s (two failing assertions; the Linux-only lifetime case is skipped on macOS); its registered pnpm plugin-sdk:surface:check command separately fails with all five identical messages in4.29s.
  • check-lint-core-2: main's plugin-state-observation-cache.ts:42 shadows cacheKey, and line71 has an unnecessary Number conversion.
  • check-lint-core-4: main's sqlite-worker-plugin-comparison.test.ts:95 captures an unbound Worker method. Both lint files came from main 01e189266093 (perf(plugin-state): reuse committed observations during turns #168635); all three diagnostics reproduce together on exact main in11.99s.

The lint reproduction used node scripts/run-oxlint.mjs --tsconfig config/tsconfig/oxlint.core.json src/plugin-state/plugin-state-observation-cache.ts src/infra/sqlite-worker-plugin-comparison.test.ts. SDK reproduction used node scripts/run-vitest.mjs test/scripts/plugin-sdk-surface-report.test.ts --maxWorkers=1 and the registered command above. All ran with the task TMPDIR on an unmodified checkout of the exact CI main base, after restoring its pinned dependencies. These failed files are outside the PR diff. No budget expansion, lint suppression, or unrelated repair was added. The inherited-only CI exception remains the lead's landing decision; this is not a green-gate claim.

Captured final-head Gateway audit excerpt:

{"id": "glm", "state": "final", "finalText": "Visible\n\nDone.", "leakedSurfaces": {}, "toolStarts": 0}
{"id": "native", "state": "final", "finalText": "Done.", "leakedSurfaces": {}, "toolStarts": 1}
{"id": "glmonly", "state": "aborted", "finalText": "", "leakedSurfaces": {}, "toolStarts": 0}

@clawsweeper

clawsweeper Bot commented Sep 4, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@ericcaiwx-star
ericcaiwx-star marked this pull request as ready for review September 4, 2026 10:58
@clawsweeper clawsweeper Bot added P1 High-priority user-facing bug, regression, or broken workflow. merge-risk: 🚨 message-delivery 🚨 May drop, duplicate, misroute, suppress, or wrongly target messages. proof: telegram-e2e This PR needs Telegram Test Server proof with the repository E2E skill. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Sep 4, 2026
@clawsweeper

clawsweeper Bot commented Sep 4, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge.

What this changes

This PR hides serialized GLM and invocation tool-call XML from streamed and final replies while preserving prose, code examples, and native calls.

Example: The assistant emits Visible followed by <tool_call>exec<arg_key>command</arg_key><arg_value>echo hidden</arg_value></tool_call> and Done.

  • Before: The reply exposes the XML wrapper and command arguments.
  • After: The reply contains Visible\n\nDone., with the XML hidden.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) A useful, coherent repair with focused regression coverage and shipped-Gateway evidence, limited by the unresolved Telegram proof requirement.
Proof confidence 🦐 gold shrimp (3/6) Real behavior proof is necessary before merge. See Before merge.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: Users receive raw tool-call XML and argument values instead of only the assistant's intended reply.
Reason: The linked GLM issue establishes a missing case in an existing sanitizer contract; the patch preserves code examples, native execution, and original transcript bytes without new configuration.

Merge readiness

⛔ Blocked before merge - 1 item remains

Keep this PR open: current main still misses the reported XML dialects, the patch contains useful unique work, and an assigned reviewer is involved; no actionable code defect was found.

Priority: P2
Reviewed head: 84b0dfe52fbad2bd5c53aa513adf59ec59819d32

Before merge

  • Add real behavior proof - The final-head built-Gateway chat.send replay with a local SSE provider exercises the changed shared owner and records clean GLM output plus one native execution, but does not show Telegram Test Server receipts or edits; the complete discussion does not independently verify the claimed exception. Supply that timeline or link item-specific owner acceptance, redacting IPs, API keys, phone numbers, and non-public endpoints. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.

Findings

None.

Tests

  • Missing end-to-end proof: A final-head Telegram Test Server receipt/edit timeline showing hidden split XML and restored terminal literals remains absent unless an owner independently accepts the supplied Gateway replay.
Agent review details

How this fits together

Provider text enters the shared assistant-visible sanitizer, which supplies stream events, block snapshots, and final delivery payloads consumed by chat clients and channel plugins.

flowchart LR
A[Provider content] --> B[Shared text sanitizer]
B --> C[Stream projection]
B --> D[Final payload assembly]
C --> E[Gateway chat events]
C --> F[Channel delivery]
D --> F
Loading

Technical review

Best possible solution:

Land the shared sanitizer repair after the scoped proof requirement is resolved and the native workflow handles inherited CI failures.

Do we have a high-confidence way to reproduce the issue?

Current-main source deterministically leaves the reported GLM toolname/arg_key shape unclassified; the linked report and supplied baseline replay corroborate that path, but this review executed no target code.

Is this the best way to solve the issue?

Extending the existing shared sanitizer addresses the missing grammar at its owner and covers stream and final consumers without executing text as tools or adding a competing reply-token policy.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 9a165c492058.

Provenance checked

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

  • Current main retains the reported grammar gap: The fetched main recognizes JSON and nested XML payloads but not toolname followed by arg_key; its recognized tag set also lacks bare invoke and the added mm invocation forms. (src/shared/text/assistant-visible-text.ts:47, 9a165c492058)
  • Pinned patch fixes the shared owner: The introduced diff extends the existing sanitizer, carries XML context across adjacent same-phase text blocks, stops that context at native boundaries, and uses terminal sanitization for completed payloads. (src/agents/embedded-agent-utils.ts:159, 84b0dfe52fba)
  • Supplied production-entry proof: The complete current body records a built-Gateway chat.send replay on the reviewed head with a local SSE provider; captured output shows clean GLM final text and one native execution. The two downloaded screenshots were inspected and show the older Teams fix from fix: sanitize streamed assistant payload text #101036, rather than this changed behavior. (84b0dfe52fba)
  • Proof exception remains unverified: The full non-bot discussion contains explicit synthetic-proof limitations and later re-review requests, but no independent item-specific acceptance of the body's claimed Telegram exception; obviyus remains assigned.
  • Inherited lint failures independently checked: Hosted annotations identify six line-cap failures outside the introduced diff, rather than the three lint diagnostics described in the body. Those six files are byte-identical between the executed CI main base and the reviewed head, independently establishing inherited source failures. (84b0dfe52fba)
  • Other red checks and landing state: https://github.com/openclaw/openclaw/actions/runs/38096487544 records SDK-budget failures, Memory QA failure, and the failed aggregate gate; the body supplies baseline reproductions for SDK and Memory QA. GitHub reports mergeable true and mergeable_state blocked, so this is not a reported merge conflict or a green CI gate. (84b0dfe52fba)

PR surface

Source +186, Tests +319, Docs +1. Total +506 across 16 files. Added test files: 3.

View PR surface stats
Area Files Added Removed Net
Source 9 295 109 +186
Tests 6 323 4 +319
Docs 1 1 0 +1
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 16 619 113 +506

Review metrics

Metric Value Why it matters
Production versus tests Production +295/−109; tests +323/−4 Production growth supports streaming ambiguity, terminal literal restoration, and native-content boundaries; focused regressions replace the earlier per-test Gateway composition.

Labels

Label changes:

No label changes.

Label justifications:

  • P2: A specific model-output dialect exposes internal markup in otherwise working replies; the repair has limited scope and no demonstrated urgent runtime outage.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask.
  • proof: telegram-e2e: This PR needs Telegram Test Server proof with the repository E2E skill. Telegram users can observe whether split tool-call prefixes remain hidden through previews and edits and whether completed literal examples reappear.

Rating scale

6/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.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only; repair and merge need explicit maintainer commands such as @clawsweeper autofix or @clawsweeper automerge.

History

Review history (36 earlier review cycles; latest 8 shown)
  • reviewed 2026-10-04T23:05:33.030Z sha 119eb96 :: needs real behavior proof before merge. :: none
  • reviewed 2026-10-04T23:29:34.690Z sha 119eb96 :: needs real behavior proof before merge. :: none
  • reviewed 2026-10-10T19:34:40.990Z sha eb09580 :: needs real behavior proof before merge. :: [P2] Keep XML context within adjacent native text blocks | [P2] Update the terminal-recovery assertion for sanitized invocation text
  • reviewed 2026-10-10T20:44:03.984Z sha 5eff359 :: needs real behavior proof before merge. :: none
  • reviewed 2026-10-10T20:54:39.797Z sha 5eff359 :: needs real behavior proof before merge. :: none
  • reviewed 2026-10-10T21:22:05.022Z sha 5eff359 :: needs real behavior proof before merge. :: none
  • reviewed 2026-10-10T22:53:50.540Z sha 5eff359 :: needs real behavior proof before merge. :: none
  • reviewed 2026-10-11T00:06:18.651Z sha 84b0dfe :: needs real behavior proof before merge. :: none

Reviewed October 10, 2026, 8:37 PM ET / October 11, 2026, 00:37 UTC (Revision 37).

@clawsweeper clawsweeper Bot added rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. labels Sep 4, 2026
@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling size: S and removed size: XS labels Sep 4, 2026
@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Sep 4, 2026

@sylvesterkaczmarek sylvesterkaczmarek left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The streaming boundary looks correct. Holding an incomplete <tool_call>exec prefix until it can be classified prevents partial leakage, while requiring the wrapped GLM shape avoids stripping literal exec<arg_key> explanations.

@ericcaiwx-star

Copy link
Copy Markdown
Contributor Author

Addressed the Rank-up moves on 92329ee101a9:

  • Hold one-character GLM tool-name prefixes: the incomplete matcher now uses the same [A-Za-z_][\w./:-]* minimum as the closed form. Covered by holds an incomplete <tool_call>exec prefix (<tool_call>x) and stream phase held GLM one-character tool name.
  • Telegram Test Server: skipped this pass. $telegram-e2e-userbot is not available in this session. Gateway loopback on server.chat.glm-arg-key-delivery.test.ts still proves final chat text; that is not a Telegram event.

Evidence: node scripts/run-vitest.mjs src/shared/text/assistant-visible-text.glm-arg-key.test.ts src/agents/embedded-agent-subscribe.handlers.messages.update-stream-phases.test.ts src/gateway/server.chat.glm-arg-key-delivery.test.ts — all passed. CI: green on 92329ee101a9 (one shard still finishing).

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Sep 4, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event exact_review_queue).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@clawsweeper clawsweeper Bot added the merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. label Sep 4, 2026
@ericcaiwx-star

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

P1s on 92329ee101a addressed in 834da5f4cfd.

  • Closed GLM arg_key payloads now require a tool name. prefix <tool_call><arg_key>secret</arg_key></tool_call> suffix stays visible.
  • Incomplete matcher holds every prefix of <arg_key, including exec<arg_ and exec<arg_ke.
  • Stream-phase cases cover both splits. Existing Use <tool_call><arg> literally. still visible.

No Telegram Test Server this cycle. Gateway loopback remains the channel-visible substitute; not claimed as Telegram.

@clawsweeper

clawsweeper Bot commented Sep 4, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event exact_review_queue).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@ericcaiwx-star

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

Previous exact-review run completed without replacing the durable review. Head is still 834da5f4cfd (CI green). The last written verdict is still 92329ee101a.

P1s from that verdict are already in 834da5f4cfd: required GLM tool name on closed payloads; hold every partial arg_key prefix.

@clawsweeper

clawsweeper Bot commented Sep 4, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event exact_review_queue).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@clawsweeper clawsweeper Bot added rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. and removed proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Sep 4, 2026
@openclaw-barnacle openclaw-barnacle Bot removed the stale Marked as stale due to inactivity label Oct 5, 2026
@openclaw-barnacle

Copy link
Copy Markdown

This assigned pull request has been automatically marked as stale after being open for 27 days.
Please add updates or it will be closed.

@openclaw-barnacle openclaw-barnacle Bot added the stale Marked as stale due to inactivity label Oct 5, 2026
steipete and others added 2 commits October 10, 2026 10:55
Keep GLM shadow text and standalone invocation XML in the shared visible-text sanitizer. Hold incomplete stream prefixes, restore finished literal examples, and retain payload context across adjacent native text parts. Preserve prose, code, and native tool execution.

Incorporates the distinct invocation cases from openclaw#153635 alongside the GLM repair from openclaw#138204. Thanks @ericcaiwx-star and @ruiling-smartbear.

Co-authored-by: Ruilin Gao <[email protected]>
@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation and removed gateway Gateway runtime labels Oct 10, 2026
@steipete

Copy link
Copy Markdown
Contributor

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

Keep XML context within consecutive text parts, including empty text, and stop it at native tool or thinking blocks in final extraction and block snapshots. Retain the terminal retry and warning assertions with the sanitized payload expectation.

Align the QA private-completion projection with the compatible Responses user-role carrier contract merged in openclaw#168546. Keep separate ordered messages and all private nonce, media, and channel-delivery assertions.
@steipete

Copy link
Copy Markdown
Contributor

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@steipete

Copy link
Copy Markdown
Contributor

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@steipete

Copy link
Copy Markdown
Contributor

Merged via explicitly authorized admin squash with attributed pre-existing CI failures.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling channel: telegram Channel integration: telegram docs Improvements or additions to documentation P2 Normal backlog priority with limited blast radius. proof: telegram-e2e This PR needs Telegram Test Server proof with the repository E2E skill. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. size: L stale Marked as stale due to inactivity status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: GLM-style <tool_call>exec<arg_key> shadow text still reaches chat after #61645

4 participants