Skip to content

Prevent plain text tool call leaks - #86222

Merged
steipete merged 4 commits into
openclaw:mainfrom
fuller-stack-dev:fix/raw-tool-text-delivery
May 25, 2026
Merged

steipete merged 4 commits into
openclaw:mainfrom
fuller-stack-dev:fix/raw-tool-text-delivery

Conversation

@fuller-stack-dev

@fuller-stack-dev fuller-stack-dev commented May 24, 2026 •

Copy link
Copy Markdown
Member

Summary

  • Promote standalone provider text like [tool:read] { ... } into structured tool calls before the xAI tool stream wrapper runs.
  • Share that plain-text tool-call promotion wrapper with LM Studio so xAI and LM Studio cannot drift on parser limits, event shape, or sanitizer behavior.
  • Mark the shared promotion wrapper as bundled-provider-only/deprecated so third-party plugin authors do not treat it as a public SDK contract.
  • Teach the shared tool payload parser and user-facing/outbound sanitizers about [tool:name] pseudo-tool syntax, then strip/reject leaked tool-call-only sends before Discord can echo raw internal tool syntax back into chat.

Testing

  • Node 24.14.0: node scripts/run-vitest.mjs extensions/lmstudio/src/stream.test.ts extensions/xai/stream.test.ts src/plugin-sdk/tool-payload.test.ts src/plugin-sdk/provider-stream-shared.test.ts
  • Node 24.14.0: node scripts/run-vitest.mjs src/agents/model-fallback.probe.test.ts src/agents/pi-embedded-runner-extraparams.test.ts src/agents/pi-embedded-runner.openai-tool-id-preservation.test.ts src/agents/pi-embedded-runner.sanitize-session-history.policy.test.ts src/agents/pi-embedded-runner.sanitize-session-history.test.ts (CI agentic-lane error files: 10 files, 424 tests passed locally; the failed GitHub job is outside this PR diff, and latest main has checks-node-agentic-agents green.)
  • Node 24.14.0: node scripts/run-tsgo.mjs -p tsconfig.core.json --incremental --tsBuildInfoFile .artifacts/tsgo-cache/core.tsbuildinfo
  • Node 24.14.0: node scripts/run-tsgo.mjs -p tsconfig.extensions.json --incremental --tsBuildInfoFile .artifacts/tsgo-cache/extensions.tsbuildinfo
  • Node 24.14.0: node scripts/run-tsgo.mjs -p test/tsconfig/tsconfig.test.src.json --incremental --tsBuildInfoFile .artifacts/tsgo-cache/test-src.tsbuildinfo
  • Node 24.14.0: node scripts/run-tsgo.mjs -p test/tsconfig/tsconfig.extensions.test.json --incremental --tsBuildInfoFile .artifacts/tsgo-cache/extensions-test.tsbuildinfo
  • Node 24.14.0: node scripts/sync-plugin-sdk-exports.mjs --check
  • Node 24.14.0: node scripts/check-plugin-sdk-subpath-exports.mjs
  • git diff --check
  • AUTOREVIEW_AUTO_TESTS=0 .agents/skills/autoreview/scripts/autoreview --mode local

Real behavior proof

  • Behavior addressed: xAI/Grok plain-text tool-call fallbacks such as [tool:message] { ... } are promoted into structured tool calls or stripped from channel-visible output before Discord delivery; LM Studio now uses the same shared promotion wrapper instead of a duplicate provider-local implementation.
  • Real environment tested: OrbStack Docker gateway for the live @spartacus Discord bot in the LibraVDB server, using xai/grok-4.3 on the openclaw:spartacus-latest-main-hotfix image with host ports 18889/18890; current branch commit bae88ff4d9 was also tested locally through the xAI, LM Studio, Plugin SDK parser/export, outbound sanitizer, and send-validation code paths.
  • Exact steps or command run after this patch:
    • curl -fsS http://127.0.0.1:18889/healthz
    • docker logs --tail 80 openclaw-orbstack-bot-openclaw-gateway-1
    • node scripts/run-vitest.mjs extensions/lmstudio/src/stream.test.ts extensions/xai/stream.test.ts src/plugin-sdk/tool-payload.test.ts src/plugin-sdk/provider-stream-shared.test.ts
    • node scripts/run-vitest.mjs src/agents/model-fallback.probe.test.ts src/agents/pi-embedded-runner-extraparams.test.ts src/agents/pi-embedded-runner.openai-tool-id-preservation.test.ts src/agents/pi-embedded-runner.sanitize-session-history.policy.test.ts src/agents/pi-embedded-runner.sanitize-session-history.test.ts
  • Evidence after fix:
$ curl -fsS http://127.0.0.1:18889/healthz
{"ok":true,"status":"live"}

$ docker logs --tail 80 openclaw-orbstack-bot-openclaw-gateway-1
[gateway] agent model: xai/grok-4.3 (thinking=low, fast=off)
[gateway] http server listening (3 plugins: discord, duckduckgo, libravdb-memory; 2.9s)
[discord] channels resolved: 1488730235544273049 (guild:LibraVDB; aliases:guild:1488730235544273049)
[discord] [default] Discord bot probe resolved @Spartacus

$ node scripts/run-vitest.mjs extensions/lmstudio/src/stream.test.ts extensions/xai/stream.test.ts src/plugin-sdk/tool-payload.test.ts src/plugin-sdk/provider-stream-shared.test.ts
Test Files  4 passed (4)
Tests  47 passed (47)
$ node scripts/run-vitest.mjs src/agents/model-fallback.probe.test.ts src/agents/pi-embedded-runner-extraparams.test.ts src/agents/pi-embedded-runner.openai-tool-id-preservation.test.ts src/agents/pi-embedded-runner.sanitize-session-history.policy.test.ts src/agents/pi-embedded-runner.sanitize-session-history.test.ts
Test Files  10 passed (10)
Tests  424 passed (424)
  • Observed result after fix: The live gateway stayed healthy, connected to Discord, and used the expected xAI/Grok runtime; the focused stream tests proved both xAI and LM Studio convert matching fallback text into toolcall_start, toolcall_delta, and done(reason="toolUse") events instead of forwarding raw [tool:...] text, while the outbound sanitizer/send-validation coverage rejects tool-call-only message bodies.
  • What was not tested: I did not post a new public Discord message from this follow-up commit because the code change only migrates LM Studio onto the shared helper; the xAI/Discord runtime was verified through live health/log output plus the focused xAI stream and outbound delivery tests.

@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling extensions: xai size: M triage: needs-real-behavior-proof Candidate: external PR needs after-fix proof from a real setup. labels May 24, 2026
@clawsweeper

clawsweeper Bot commented May 24, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge. Reviewed May 25, 2026, 3:08 AM ET / 07:08 UTC.

Summary
The branch adds [tool:name] plain-text tool-call parsing, shares promotion across xAI and LM Studio, and strips or rejects leaked tool syntax before user-facing delivery.

PR surface: Source +25, Tests +158, Docs +1. Total +184 across 14 files.

Reproducibility: no. high-confidence live reproduction is included. Source inspection shows current main lacks xAI handling for [tool:...] fallback text and the PR tests synthesize the fallback, but the provided runtime proof does not trigger the actual leak.

Review metrics: 2 noteworthy metrics.

  • PR surface: 14 files changed; +439/-256. The diff spans provider streams, Plugin SDK parsing, user-facing sanitization, outbound send validation, tests, and changelog, so message-delivery behavior needs more than unit-only confidence.
  • SDK helper surface: 1 exported helper added. The helper is added to provider-stream-shared, an exposed Plugin SDK subpath, so maintainers should notice the compatibility choice before merge.

Merge readiness
Overall: 🦪 silver shellfish
Proof: 🦪 silver shellfish
Patch quality: 🐚 platinum hermit
Result: blocked until stronger real behavior proof is added.

Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch.

Rank-up moves:

  • Add redacted logs, copied live output, a transcript, or a recording that triggers or replays a Grok [tool:...] fallback and shows raw syntax is not posted to Discord.
  • Get maintainer-visible acceptance for the deprecated public SDK helper, or move it to an internal bundled-provider seam.

Proof guidance:
Needs stronger real behavior proof before merge: The PR body includes terminal logs and focused tests, but it does not show the changed fallback being promoted or stripped before Discord delivery after the patch. 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.

Mantis proof suggestion
A Discord-visible or log-backed proof would materially help verify that raw pseudo-tool text no longer reaches chat. A maintainer can ask Mantis to capture proof by posting a new PR comment that starts with the OpenClaw Mantis account mention, followed by:

visual task: verify an xAI/Grok [tool:message] fallback is promoted or stripped and raw [tool:...] text is not posted in Discord.

Risk before merge

  • The supplied live output proves a healthy xAI Discord gateway, but not the actual [tool:...] fallback being promoted or stripped before chat delivery.
  • Parser or sanitizer false negatives can still leak raw internal syntax, while false positives can suppress intentional standalone [tool:...] text.
  • The new helper is exported from a package-exposed Plugin SDK subpath even though it is marked deprecated and bundled-provider-only, so maintainers should explicitly accept that compatibility signal or move it internal.

Maintainer options:

  1. Require proof and SDK acceptance (recommended)
    Before merge, require redacted fallback delivery proof plus a maintainer-visible decision accepting the deprecated provider-stream helper on a public Plugin SDK subpath.
  2. Move the helper internal
    If the SDK signal is not acceptable, move the promotion helper to an internal or bundled-provider-only location while keeping xAI and LM Studio on one implementation.
  3. Accept current compatibility risk
    Maintainers may intentionally merge the deprecated public helper as-is if they accept the plugin API compatibility signal and rely on follow-up cleanup if needed.

Next step before merge
Needs contributor-supplied real behavior proof and maintainer acceptance of the exported deprecated helper before merge; there is no narrow automated code repair to queue.

Security
Cleared: No concrete security or supply-chain regression was found; the diff reduces leak exposure and does not touch dependencies, CI, lockfiles, secrets, or downloaded code.

Review details

Best possible solution:

Land the parser, promotion, and delivery guard after redacted Discord/log proof shows raw [tool:...] fallback text is not posted, with the helper either accepted as a deprecated bundled-provider seam or moved out of the public SDK surface.

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

No high-confidence live reproduction is included. Source inspection shows current main lacks xAI handling for [tool:...] fallback text and the PR tests synthesize the fallback, but the provided runtime proof does not trigger the actual leak.

Is this the best way to solve the issue?

Unclear as merge-ready. The shared parser and promotion approach matches existing LM Studio handling, but delivery proof and a maintainer decision on the SDK-visible helper are still needed.

AGENTS.md: found and applied where relevant.

Codex review notes: model gpt-5.5, reasoning high; reviewed against 73189e3ecb0c.

Label changes

Label justifications:

  • P1: The PR targets a user-facing agent/channel workflow where internal tool-call syntax can be delivered to chat users.
  • merge-risk: 🚨 compatibility: The diff adds a new helper to a package-exposed Plugin SDK provider-stream subpath, even though it is marked deprecated and bundled-provider-only.
  • merge-risk: 🚨 message-delivery: The diff changes provider stream promotion and outbound sanitization, which can leak or suppress delivered messages if parser behavior is wrong.
  • rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦪 silver shellfish and patch quality is 🐚 platinum hermit.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask. Needs stronger real behavior proof before merge: The PR body includes terminal logs and focused tests, but it does not show the changed fallback being promoted or stripped before Discord delivery after the patch. 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.
Evidence reviewed

PR surface:

Source +25, Tests +158, Docs +1. Total +184 across 14 files.

View PR surface stats
Area Files Added Removed Net
Source 8 280 255 +25
Tests 5 158 0 +158
Docs 1 1 0 +1
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 14 439 255 +184

What I checked:

  • Repository policy read: Full root policy was read and applied; the review followed the PR-specific guidance around plugin SDK compatibility, message-delivery risk, scoped AGENTS files, and real behavior proof. (AGENTS.md:1, 73189e3ecb0c)
  • Scoped extension policy read: The extension guide explicitly prefers shared provider-family helpers over repeated provider-local compat logic, which supports the refactor direction while still making SDK surface compatibility relevant. (extensions/AGENTS.md:1, 73189e3ecb0c)
  • Scoped Plugin SDK policy read: The Plugin SDK guide treats public SDK surface as compatibility-sensitive and asks for narrow provider-facing seams, shaping the compatibility merge risk. (src/plugin-sdk/AGENTS.md:1, 73189e3ecb0c)
  • Current main lacks xAI promotion: Current main's xAI stream wrapper decodes tool-call arguments and then returns createToolStreamWrapper without a plain-text tool-call promotion wrapper. (extensions/xai/stream.ts:357, 73189e3ecb0c)
  • PR wires xAI promotion: The PR head inserts createPlainTextToolCallPromotionWrapper into the xAI wrapper chain before the existing tool-stream wrapper. (extensions/xai/stream.ts:358, f78d7b2328bc)
  • PR adds shared deprecated helper: The PR exports createPlainTextToolCallPromotionWrapper from provider-stream-shared.ts and marks it deprecated/bundled-provider-only, which is still a public subpath compatibility signal. (src/plugin-sdk/provider-stream-shared.ts:298, f78d7b2328bc)

Likely related people:

  • steipete: Recent GitHub history for provider-stream-shared.ts, tool-payload.ts, extensions/xai/stream.ts, and extensions/lmstudio/src/stream.ts includes provider-stream surface reduction, helper deprecation, xAI reasoning wrapper work, and LM Studio plain-text tool promotion. (role: recent SDK and provider-stream contributor; confidence: high; commits: ccf0b96a5635, 827b0de0ce74, 7504fc3a47c1; files: src/plugin-sdk/provider-stream-shared.ts, src/plugin-sdk/tool-payload.ts, extensions/xai/stream.ts)
  • vincentkoc: Recent history shows shared helper dedupe work in xAI and earlier shared tool payload extraction in the Plugin SDK path this PR extends. (role: shared helper and tool payload contributor; confidence: medium; commits: 88c49f9e68fc, be530f085dbe; files: extensions/xai/stream.ts, src/plugin-sdk/tool-payload.ts)
  • shakkernerd: Recent commits adjusted plain tool block parser spacing tests around the parser surface extended by the PR. (role: parser test contributor; confidence: medium; commits: 8c3a0c12966a, 76df5aaac0d5; files: src/plugin-sdk/tool-payload.ts, src/plugin-sdk/tool-payload.test.ts)
What the crustacean ranks mean
  • 🦀 challenger crab: rare, exceptional readiness with strong proof, clean implementation, and convincing validation.
  • 🦞 diamond lobster: very strong readiness with only minor maintainer review expected.
  • 🐚 platinum hermit: good normal PR, likely mergeable with ordinary maintainer review.
  • 🦐 gold shrimp: useful signal, but proof or patch confidence is still limited.
  • 🦪 silver shellfish: thin signal; proof, validation, or implementation needs work.
  • 🧂 unranked krab: not merge-ready because proof is missing/unusable or there are serious correctness or safety concerns.
  • 🌊 off-meta tidepool: rating does not apply to this item.

Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

How this review workflow works
  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

@clawsweeper clawsweeper Bot added rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. P1 High-priority user-facing bug, regression, or broken workflow. merge-risk: 🚨 message-delivery 🚨 May drop, duplicate, misroute, suppress, or wrongly target messages. labels May 24, 2026
@clawsweeper

clawsweeper Bot commented May 24, 2026

Copy link
Copy Markdown
Contributor

ClawSweeper PR egg

🎁 Pass real behavior proof to wake the egg and unlock a hatchable treat.

Where did the egg go?
  • The egg game starts only after the PR passes the real-behavior proof check.
  • Before that, no creature or rarity is rolled. The treat waits for real proof.
  • This is still just collectible flavor: proof affects review readiness, not creature quality.

@openclaw-barnacle openclaw-barnacle Bot added proof: supplied External PR includes structured after-fix real behavior proof. extensions: lmstudio size: L and removed triage: needs-real-behavior-proof Candidate: external PR needs after-fix proof from a real setup. size: M labels May 24, 2026
@clawsweeper clawsweeper Bot added rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. and removed rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. labels May 24, 2026
@fuller-stack-dev

Copy link
Copy Markdown
Member Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented May 25, 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 repository_dispatch).
Result: the existing ClawSweeper review comment will be edited in place when the review finishes.

Re-review progress:

@fuller-stack-dev

Copy link
Copy Markdown
Member Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented May 25, 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 repository_dispatch).
Result: the existing ClawSweeper review comment will be edited in place when the review finishes.

Re-review progress:

@steipete
steipete force-pushed the fix/raw-tool-text-delivery branch from bae88ff to f78d7b2 Compare May 25, 2026 07:01
@steipete
steipete merged commit cd62780 into openclaw:main May 25, 2026
158 of 159 checks passed
@steipete

Copy link
Copy Markdown
Contributor

Landed, thank you @fuller-stack-dev.

Merged as cd62780. I added the maintainer changelog entry on the PR branch before merge: f78d7b2.

Proof:

  • git diff --check
  • node scripts/run-vitest.mjs extensions/lmstudio/src/stream.test.ts extensions/xai/stream.test.ts src/plugin-sdk/tool-payload.test.ts src/plugin-sdk/provider-stream-shared.test.ts -> 4 files, 47 tests passed
  • node scripts/run-vitest.mjs src/agents/model-fallback.probe.test.ts src/agents/pi-embedded-runner-extraparams.test.ts src/agents/pi-embedded-runner.openai-tool-id-preservation.test.ts src/agents/pi-embedded-runner.sanitize-session-history.policy.test.ts src/agents/pi-embedded-runner.sanitize-session-history.test.ts src/agents/pi-embedded-helpers.sanitizeuserfacingtext.test.ts src/infra/outbound/message-action-runner.send-validation.test.ts src/infra/outbound/sanitize-text.test.ts -> 13 files, 584 tests passed
  • CI on refreshed head f78d7b2 is green after rerunning checks-node-agentic-agents in run 26387926116, job 77671345253

The first checks-node-agentic-agents attempt timed out in unrelated src/agents/model-catalog-visibility.test.ts; the targeted rerun passed.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request May 26, 2026
Prevent plain text tool call leaks from xAI/LM Studio fallback streams.

- Promotes plain-text tool-call fallback chunks into structured tool calls.
- Strips leaked internal tool syntax before user-facing/outbound text.
- Adds regression coverage across provider stream wrappers, tool payload parsing, user-facing sanitization, and outbound send validation.

Co-authored-by: fuller-stack-dev <[email protected]>
jameslcowan pushed a commit to jameslcowan/openclaw that referenced this pull request Jun 2, 2026
Prevent plain text tool call leaks from xAI/LM Studio fallback streams.

- Promotes plain-text tool-call fallback chunks into structured tool calls.
- Strips leaked internal tool syntax before user-facing/outbound text.
- Adds regression coverage across provider stream wrappers, tool payload parsing, user-facing sanitization, and outbound send validation.

Co-authored-by: fuller-stack-dev <[email protected]>
sablehead pushed a commit to sablehead/openclaw that referenced this pull request Jun 10, 2026
Prevent plain text tool call leaks from xAI/LM Studio fallback streams.

- Promotes plain-text tool-call fallback chunks into structured tool calls.
- Strips leaked internal tool syntax before user-facing/outbound text.
- Adds regression coverage across provider stream wrappers, tool payload parsing, user-facing sanitization, and outbound send validation.

Co-authored-by: fuller-stack-dev <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling extensions: lmstudio extensions: xai merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 message-delivery 🚨 May drop, duplicate, misroute, suppress, or wrongly target messages. P1 High-priority user-facing bug, regression, or broken workflow. proof: supplied External PR includes structured after-fix real behavior proof. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. size: L 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.

2 participants