fix: strip <relevant-memories> injected by memory plugin from user messages in WebUI#1863
Open
BingqingLyu wants to merge 1 commit intomainfrom
Open
Conversation
…tory Memory plugin prepends <relevant-memories>...</relevant-memories> blocks to user prompts via the before_agent_start hook. These blocks were only stripped from assistant messages (via stripAssistantInternalScaffolding) but never from user-role messages, causing them to appear in the WebUI user message bubble and in chat.history responses. Changes: - Export stripRelevantMemoriesTags from assistant-visible-text.ts - chat-sanitize.ts: apply stripRelevantMemoriesTags when stripping user messages in stripEnvelopeFromMessage (covers chat.history server path) - message-extract.ts: apply stripRelevantMemoriesTags for user-role messages in processMessageText (covers WebUI rendering path) - Add regression tests in both chat-sanitize.test.ts and message-extract.test.ts Fixes openclaw#59568 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
before_agent_starthook prepends<relevant-memories>...</relevant-memories>to user prompts before they are stored in session historystripEnvelopeFromMessages()(server) andprocessMessageText(WebUI) only stripped these tags from assistant messages, never from user messagesRoot cause
stripRelevantMemoriesTagswas only reachable viastripAssistantInternalScaffolding, which is only called forrole === "assistant". User messages went throughstripInboundMetadata+stripEnvelope, neither of which handles<relevant-memories>XML tags.Fix
stripRelevantMemoriesTagsfromassistant-visible-text.tschat-sanitize.ts(stripEnvelopeFromMessage): applystripRelevantMemoriesTagsto user-role message content — fixes thechat.historyRPC pathmessage-extract.ts(processMessageText): applystripRelevantMemoriesTagsfor user-role messages — fixes the WebUI rendering pathchat-sanitize.test.tsandmessage-extract.test.tsfor both string content and array content shapesTest plan
npx vitest run src/gateway/chat-sanitize.test.ts— 11 tests passnpx vitest run ui/src/ui/chat/message-extract.test.ts— 6 tests passmemory-lancedbextension enabled, send a message, verify user bubble shows only the actual message textFixes openclaw#59568
🤖 Generated with Claude Code