From 4b272d489de38e2bb4131436bf504ace4ab18129 Mon Sep 17 00:00:00 2001 From: mobilebarn Date: Fri, 27 Mar 2026 21:46:34 +1100 Subject: [PATCH] fix(openclaw-plugin): sanitize memory_store input to prevent context pollution Applies sanitizeUserTextForCapture to the memory_store tool's text input, preventing blocks and metadata from polluting the memory extraction pipeline. Closes volcengine/OpenViking#898 --- examples/openclaw-plugin/index.ts | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/examples/openclaw-plugin/index.ts b/examples/openclaw-plugin/index.ts index 7374d1902..36f8b331b 100644 --- a/examples/openclaw-plugin/index.ts +++ b/examples/openclaw-plugin/index.ts @@ -9,6 +9,7 @@ import type { FindResultItem, PendingClientEntry } from "./client.js"; import { isTranscriptLikeIngest, extractLatestUserText, + sanitizeUserTextForCapture, } from "./text-utils.js"; import { clampScore, @@ -243,6 +244,13 @@ const contextEnginePlugin = { }), async execute(_toolCallId: string, params: Record) { const { text } = params as { text: string }; + const sanitizedText = sanitizeUserTextForCapture(text); + if (!sanitizedText) { + return { + content: [{ type: "text", text: "Nothing to store after sanitizing input (metadata-only content was stripped)." }], + details: { action: "rejected", reason: "empty_after_sanitize" }, + }; + } const role = typeof (params as { role?: string }).role === "string" ? (params as { role: string }).role @@ -251,7 +259,7 @@ const contextEnginePlugin = { const sessionKeyIn = (params as { sessionKey?: string }).sessionKey; api.logger.info?.( - `openviking: memory_store invoked (textLength=${text?.length ?? 0}, sessionId=${sessionIdIn ?? "auto"}, sessionKey=${sessionKeyIn ?? "none"})`, + `openviking: memory_store invoked (textLength=${sanitizedText.length}, sessionId=${sessionIdIn ?? "auto"}, sessionKey=${sessionKeyIn ?? "none"})`, ); let sessionId = sessionIdIn; @@ -269,7 +277,7 @@ const contextEnginePlugin = { details: { action: "rejected", reason: "missing_session_identifier" }, }; } - await c.addSessionMessage(sessionId, role, text, storeAgentId); + await c.addSessionMessage(sessionId, role, sanitizedText, storeAgentId); const commitResult = await c.commitSession(sessionId, { wait: true, agentId: storeAgentId }); const memoriesCount = commitResult.memories_extracted ?? 0; if (memoriesCount === 0) {