Repository navigation
fix(memory-lancedb): reject envelope metadata sludge (incl. marker-free shapes) - #88806
Conversation
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Adds envelope/transport metadata sanitization to the memory-lancedb extension to prevent contaminated text (envelope brackets, inbound-meta sentinels, media annotations, etc.) from being captured or recalled as long-term memories. Also exposes the bundled chat-channel id list as a new plugin-sdk entrypoint so the extension can detect marker-free [<channel> <from>] envelope prefixes without hardcoding channel ids.
Changes:
- New plugin-sdk entrypoint
chat-channel-idsre-exportingCHAT_CHANNEL_ORDERasBUNDLED_CHAT_CHANNEL_IDS(+ wired intopackage.jsonexports andplugin-sdk-entrypoints.json). - New
looksLikeEnvelopeSludge/sanitizeForMemoryCapturehelpers in memory-lancedb, plus integration intoshouldCapture, the auto-recall path (overfetch + filter), the auto-capture hook, andformatRelevantMemoriesContext. - Updated
escapeMemoryForPromptto strip[media attached: ...]annotations and conditionally collapse spaces/tabs while preserving newlines.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| src/plugin-sdk/chat-channel-ids.ts | New SDK module re-exporting bundled chat-channel ids/types. |
| scripts/lib/plugin-sdk-entrypoints.json | Registers the new chat-channel-ids entrypoint. |
| package.json | Adds export mapping for ./plugin-sdk/chat-channel-ids. |
| extensions/memory-lancedb/index.ts | Adds envelope-sludge detection/sanitization and integrates into capture, recall, and prompt formatting. |
| extensions/memory-lancedb/index.test.ts | Adds extensive tests for new sanitization, detection, escaping, and recall-path overfetch behavior. |
| docs/.generated/plugin-sdk-api-baseline.sha256 | Updated SDK API baseline checksums to reflect new entrypoint. |
|
Codex review: needs maintainer review before merge. Reviewed June 1, 2026, 12:45 AM ET / 04:45 UTC. Summary PR surface: Source +672, Tests +758, Docs +1, Config +4, Other +1. Total +1436 across 9 files. Reproducibility: yes. Source inspection shows Review metrics: 2 noteworthy metrics.
Merge readiness Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch. Rank-up moves:
Risk before merge
Maintainer options:
Next step before merge
Security Review detailsBest possible solution: Land this after maintainer acceptance of the SDK contract and memory-filter compatibility tradeoff, keeping the conservative sender-prefix gates and regression coverage. Do we have a high-confidence way to reproduce the issue? Yes. Source inspection shows Is this the best way to solve the issue? Yes, this is an acceptable bounded fix for the PR: keep the extension inside the plugin boundary by adding a narrow SDK subpath, sanitize before capture, and filter before auto-recall injection. The longer-term ideal would be passing clean user body separately from envelope text, but that is broader than this repair. AGENTS.md: found and applied where relevant. Codex review notes: model gpt-5.5, reasoning high; reviewed against 296cd8c91292. Label changesLabel changes:
Label justifications:
Evidence reviewedPR surface: Source +672, Tests +758, Docs +1, Config +4, Other +1. Total +1436 across 9 files. View PR surface stats
What I checked:
Likely related people:
What the crustacean ranks mean
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics. How this review workflow works
|
|
Addressed every actionable ClawSweeper P1 and Copilot inline finding in P1.1 (ClawSweeper) -- DM body corruption P1.2 (ClawSweeper) -- Public SDK subpath C1 (Copilot) -- Empty channel list guard C2 (Copilot) -- Sentinel loop ordering C3 (Copilot) -- Named constants C4 (Copilot) -- already fixed in Verification
|
…sentinel ordering Address ClawSweeper P1 plus Copilot P2 findings on PR openclaw#88806. - P1.1: gate sender-prefix strip in sanitizeForMemoryCapture so we only remove a leading `<X>: ` from the envelope body when X equals the literal `(self)` sentinel (direct fromMe contract) or matches a whitespace-separated token of the captured envelope header. Prevents legitimate DM bodies like `TODO: fix this` from being truncated to `fix this`. Both INBOUND_ENVELOPE_PREFIX_RE patterns now capture the inside-bracket text so the gate has the contract data it needs. - P1.2: document the new `openclaw/plugin-sdk/chat-channel-ids` subpath in docs/plugins/sdk-subpaths.md (Channel subpaths accordion). The extensions boundary forbids extensions from importing core internals, so a public Plugin SDK subpath is the right seam; documenting it makes it a tracked contract. - C1: guard the marker-free known-channel detector against an empty BUNDLED_CHAT_CHANNEL_IDS list so the alternation cannot degenerate into `(?:)` and flag every `[...]` prefix as an envelope. - C2: pick the EARLIEST line-anchored sentinel across the whole INBOUND_META_SENTINELS list each pass instead of acting on each sentinel's first match independently. Removes the order-dependent preservation of metadata that belonged to an outer sentinel's plain-text body. Bounded retry loop preserves prior behavior of stripping back-to-back sentinels at the very start. - C3: extract DEFAULT_AUTO_RECALL_OVERFETCH_LIMIT and DEFAULT_AUTO_RECALL_RESULT_CAP from the inline literals so the over-fetch vs cap relationship is documented at the constant declaration. Tests: - node scripts/run-vitest.mjs run extensions/memory-lancedb (113 pass) - node scripts/run-oxlint-shards.mjs --only=extensions --threads=4 (clean) - pnpm build (green) - pnpm plugin-sdk:api:check (clean)
bcb42b3 to
ba5e3bf
Compare
|
Land-ready after maintainer fixups. Summary:
Verification:
|
|
Follow-up landed on I could not push the fixups back to the contributor branch because the fork rejected maintainer pushes ( Proof run after the fixup:
Thanks @amittell. For future PRs, enabling “Allow edits by maintainers” lets us push small fixups directly to the PR branch before merge. |
|
Follow-up CI fix landed on This preserves clean colon-delimited slash commands like Additional proof:
|
Supersedes #73787. Closes the timestamp-free envelope coverage gap flagged in the clawsweeper review of #73787 (#issuecomment-4340178019).
Behavior addressed
formatInboundEnvelopeinsrc/auto-reply/envelope.tsproduces a leading bracket header whose markers (+elapsed, host, ip, date) are all conditional. WhenpreviousTimestampis undefined and host/ip/date are absent, the emitted shape is[<channel> <from>] <body>with no markers. The priorlooksLikeEnvelopeSludgeregex keyed on elapsed/date markers and missed this case, allowing channel/sender metadata to persist in long-term memory captures.Change
The new commit (
1a5dca094d) adds anINBOUND_ENVELOPE_KNOWN_CHANNEL_PREFIX_REregex that matches the marker-free[<channel-id> <from-label>]shape using a canonical channel-id list. Concretely:openclaw/plugin-sdk/chat-channel-ids(src/plugin-sdk/chat-channel-ids.ts) re-exportsCHAT_CHANNEL_ORDERfromsrc/channels/ids.tsasBUNDLED_CHAT_CHANNEL_IDS.extensions/memory-lancedb/index.tsimportsBUNDLED_CHAT_CHANNEL_IDSand treats a leading[<known-channel-id> <from-label>]as envelope sludge regardless of marker presence. The existing marker-based path is preserved so unknown-channel envelopes still get filtered when an unambiguous marker is present.The channel-id list and
formatInboundEnvelopenow read the same canonical source, so the detector cannot drift from the formatter.Real behavior proof
Behavior addressed: Timestamp-free
formatInboundEnvelopeoutputs of shape[<channel-id> <from-label>] <body>were not being stripped before auto-capture, leaking channel and sender metadata into long-term memory.Real environment tested: Live OpenClaw gateway on rh-bot.lan, pid 65734, build SHA 23804e6 (upgrade-v2026.5.28 with this PR cherry-picked). The fix is deployed and active. Verification driver imports the deployed
extensions/memory-lancedb/index.jsbundle that the running gateway has loaded for its memory plugin, exposingBUNDLED_CHAT_CHANNEL_IDS(22 known channels: feishu, googlechat, nostr, msteams, mattermost, nextcloud-talk, matrix, line, telegram, discord, slack, signal, imessage, whatsapp, irc, qqbot, twitch, synology-chat, tlon, zalo, zalouser, xiaomi).Exact steps or command run after this patch:
Evidence after fix:
Observed result after fix: All seven envelope shapes match expectations against the deployed runtime. The gap case (marker-free
[telegram alice]envelope) is now filtered. Existing marker-present envelopes still filter. The three false-positive guards (user[note]prose, markdown link syntax, bare[channel]without from-label) correctly do NOT filter. Sanitize round-trip strips the envelope prefix and returns clean bodyhello world.What was not tested: Full memory_capture + memory_recall round trip through the running gateway with a forged channel inbound. The detector is the canonical filter point; the sanitize round-trip proof above shows the body extraction path also handles the shape.