Skip to content

fix(messaging): strip inbound metadata from outbound messages - #220

Open
ralf003 wants to merge 2 commits into
Tencent:mainfrom
ralf003:fix/strip-inbound-metadata
Open

ralf003 wants to merge 2 commits into
Tencent:mainfrom
ralf003:fix/strip-inbound-metadata

Conversation

@ralf003

@ralf003 ralf003 commented Jul 4, 2026

Copy link
Copy Markdown

Problem

OpenClaw core injects inbound metadata (Conversation info, Sender info, Thread starter, Reply target, Forwarded message context, Chat history) into the user message prompt via buildInboundUserContextPrefix(). Core strips these blocks in its normal UI/prompt replay flow with stripInboundMetadata(), but the Weixin channel plugin delivers raw LLM output to the user without removing echoed metadata blocks.

This causes users to occasionally receive garbage messages containing only metadata instead of the actual reply.

Solution

Add stripInboundMetadata() to process outgoing text in the deliver callback after the StreamingMarkdownFilter, removing echoed metadata blocks before the message is sent to the user.

Metadata types handled (aligned with core's strip-inbound-meta.ts)

Type Example
6 inbound meta sentinels Conversation info, Sender, Thread starter, etc.
4 MESSAGE_TOOL_DELIVERY_HINTS Delivery: to send a message, use the \message` tool.` etc.
Chat window context blocks Group chat context (untrusted, chronological):
Untrusted context suffix Terminal Untrusted context (metadata, ...) block
active_memory_plugin blocks <active_memory_plugin>...</active_memory_plugin>
Leading timestamp prefix [Mon 2026-07-05 09:30 GMT+8]

Changes

  • Add src/messaging/strip-meta.ts with stripInboundMetadata() (standalone re-implementation synced with core)
  • Add src/messaging/strip-meta.test.ts with 23 test cases
  • Call stripInboundMetadata() in the deliver callback after StreamingMarkdownFilter

Note

This is a standalone copy of the logic from openclaw core's src/auto-reply/reply/strip-inbound-meta.ts, because stripInboundMetadata is not currently exposed via the plugin SDK. I'll open a core issue requesting SDK exposure so plugins don't need to maintain their own copies.

ralf003 added 2 commits July 4, 2026 21:18
OpenClaw core injects inbound metadata (Conversation info, Sender info,
etc.) into the user message prompt via buildInboundUserContextPrefix().
Core strips these blocks in its normal UI/prompt replay flow, but the
Weixin channel plugin delivers raw LLM output to the user without
removing echoed metadata blocks.

This causes users to occasionally receive garbage messages containing
only metadata JSON.

Fix: add stripInboundMetadata() call in the deliver callback after
StreamingMarkdownFilter processing. The strip-meta module handles all
six metadata block types with optional timestamp prefixes.
Extends stripInboundMetadata() to cover all metadata types that OpenClaw
core handles:

- MESSAGE_TOOL_DELIVERY_HINTS (4 variants) -- sentinel lines removed
- Chat window context blocks -- pattern-matched headers
- Untrusted context suffix -- terminal metadata appended by core
- active_memory_plugin blocks -- memory plugin context wrapper
- Leading timestamp prefix removal
- Blank line cleanup after stripped meta blocks

Previously only handled the 6 INBOUND_META_SENTINELS, missing these 4
additional metadata patterns that core's strip-inbound-meta.ts handles.
Test coverage expanded from 11 to 23 cases.

Ref: openclaw core src/auto-reply/reply/strip-inbound-meta.ts
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.

1 participant