fix(agents): strip tool_call/tool_result XML leaking into channel messages#42260
fix(agents): strip tool_call/tool_result XML leaking into channel messages#42260jnMetaCode wants to merge 1 commit into
Conversation
Greptile SummaryThis PR adds Key changes:
One style note: Stripping whole-line Confidence Score: 4/5
Last reviewed commit: 23c1173 |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 23c117334c
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
23c1173 to
503f969
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 503f969f4f
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
503f969 to
135985a
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 135985a9da
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
135985a to
77c18b9
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 77c18b93da
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
77c18b9 to
65bead0
Compare
65bead0 to
27c6f74
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 27c6f7485c
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| let cleaned = text.replace(/<tool_call\b[^>]*>[\s\S]*?<\/tool_call>/gi, ""); | ||
| cleaned = cleaned.replace(/<tool_result\b[^>]*>[\s\S]*?<\/tool_result>/gi, ""); |
There was a problem hiding this comment.
Match closing tool tags with trailing whitespace
The block-removal regexes require an exact </tool_call> / </tool_result> closer, so XML variants like </tool_call > (valid with whitespace before >) are not removed as blocks. In that case the later stray-tag cleanup deletes only the tags and leaves the inner tool JSON/result text in the user-visible message, which defeats the leak-prevention this sanitizer is intended to provide for model-emitted XML.
Useful? React with 👍 / 👎.
|
Re: trailing whitespace in closing tags — the existing |
|
Friendly ping — cleaned up my PR backlog to make review easier. This fixes tool_call/tool_result XML leaking into user-visible channel messages (reported in #40879). The approach mirrors the existing |
|
Closing this as implemented after Codex review. Current What I checked:
So I’m closing this as already implemented rather than keeping a duplicate issue open. Review notes: reviewed against 7d9172d5e093; fix evidence: release v2026.4.22, commit 00bd2cf7a376. |
Summary
stripToolCallXml()to strip raw<tool_call>/<tool_result>XML blocks that some models emit as plain textextractAssistantText()sanitization chain alongside existingstripMinimaxToolCallXml()andstripModelSpecialTokens()Problem
When a model outputs raw XML tool markup (e.g.
<tool_call>{"name": "subagents", ...}</tool_call>), these blocks leak into user-facing channel messages (Discord, Telegram, etc.) because no sanitization function targets them.Existing strippers handle:
stripMinimaxToolCallXml(): MiniMax-specific<invoke>/</minimax:tool_call>tagsstripDowngradedToolCallText(): text-based[Tool Call: ...]markersstripModelSpecialTokens(): model special tokensBut generic
<tool_call>/<tool_result>XML is not covered.Fix
New
stripToolCallXml()function with:<tool_call>...</tool_call>and<tool_result>...</tool_result>Test plan
stripToolCallXml()(7 cases: paired blocks, attributes, stray tags, empty input, no-op)extractAssistantText()with tool_call XMLCloses #40879