Skip to content

fix: strip <relevant-memories> injected by memory plugin from user messages in WebUI#1863

Open
BingqingLyu wants to merge 1 commit intomainfrom
fork-pr-59697-fix-webui-strip-relevant-memories-from-user-messages
Open

fix: strip <relevant-memories> injected by memory plugin from user messages in WebUI#1863
BingqingLyu wants to merge 1 commit intomainfrom
fork-pr-59697-fix-webui-strip-relevant-memories-from-user-messages

Conversation

@BingqingLyu
Copy link
Copy Markdown
Owner

@BingqingLyu BingqingLyu commented Apr 28, 2026

Summary

  • Memory plugin's before_agent_start hook prepends <relevant-memories>...</relevant-memories> to user prompts before they are stored in session history
  • stripEnvelopeFromMessages() (server) and processMessageText (WebUI) only stripped these tags from assistant messages, never from user messages
  • This caused internal memory context to appear in the user message bubble in WebUI

Root cause

stripRelevantMemoriesTags was only reachable via stripAssistantInternalScaffolding, which is only called for role === "assistant". User messages went through stripInboundMetadata + stripEnvelope, neither of which handles <relevant-memories> XML tags.

Fix

  • Export stripRelevantMemoriesTags from assistant-visible-text.ts
  • chat-sanitize.ts (stripEnvelopeFromMessage): apply stripRelevantMemoriesTags to user-role message content — fixes the chat.history RPC path
  • message-extract.ts (processMessageText): apply stripRelevantMemoriesTags for user-role messages — fixes the WebUI rendering path
  • Add regression tests in chat-sanitize.test.ts and message-extract.test.ts for both string content and array content shapes

Test plan

  • npx vitest run src/gateway/chat-sanitize.test.ts — 11 tests pass
  • npx vitest run ui/src/ui/chat/message-extract.test.ts — 6 tests pass
  • Start OpenClaw with memory-lancedb extension enabled, send a message, verify user bubble shows only the actual message text

Fixes openclaw#59568

🤖 Generated with Claude Code

…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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] WebUI: internal metadata displayed in user message input area

2 participants