fix(matrix): sanitize internal tool-trace lines from outbound text (#97372)

Wrap the matrix outbound sanitizeText hook with sanitizeAssistantVisibleText so assistant internal tool-trace scaffolding is stripped before delivery, matching the sibling channel fixes under #90684 (Telegram #95774, Google Chat #95084, IRC #97214).
This commit is contained in:
Masato Hoshino
2026-06-28 11:58:36 -07:00
committed by GitHub
parent 5e1f4c1073
commit 25490d4c42
2 changed files with 25 additions and 1 deletions
+5 -1
View File
@@ -32,7 +32,10 @@ import {
normalizeLowercaseStringOrEmpty,
normalizeOptionalString,
} from "openclaw/plugin-sdk/string-coerce-runtime";
import { chunkTextForOutbound } from "openclaw/plugin-sdk/text-chunking";
import {
chunkTextForOutbound,
sanitizeAssistantVisibleText,
} from "openclaw/plugin-sdk/text-chunking";
import { matrixMessageActions } from "./actions.js";
import { matrixApprovalCapability } from "./approval-native.js";
import { createMatrixPairingText, createMatrixProbeAccount } from "./channel-account-paths.js";
@@ -336,6 +339,7 @@ const matrixChannelOutbound: ChannelOutboundAdapter = {
chunker: chunkTextForOutbound,
chunkerMode: "markdown",
textChunkLimit: 4000,
sanitizeText: ({ text }) => sanitizeAssistantVisibleText(text),
deliveryCapabilities: {
durableFinal: {
text: true,
@@ -0,0 +1,20 @@
// Matrix outbound must strip assistant internal tool-trace scaffolding, matching
// the sibling channel fixes tracked under #90684 (Telegram #95774 / Google Chat
// #95084 / IRC #97214). The hook runs before the markdown->HTML render, so a
// single sanitize cleans both the plain body and the formatted_body.
import { describe, expect, it } from "vitest";
import { matrixPlugin } from "./channel.js";
describe("matrix outbound sanitizeText", () => {
it("strips internal tool-trace banners before outbound delivery", () => {
const text = "Done.\n⚠️ 🛠️ `search repos (agent)` failed";
expect(matrixPlugin.outbound?.sanitizeText?.({ text, payload: { text } })).toBe("Done.");
});
it("preserves ordinary assistant prose while sanitizing", () => {
const text = "The pipeline has 3 open deals.";
expect(matrixPlugin.outbound?.sanitizeText?.({ text, payload: { text } })).toBe(text);
});
});