Skip to content

fix: complete metadata stripping for all channel sentinel patterns (#211)#310

Closed
AliceLJY wants to merge 1 commit intomasterfrom
fix/complete-metadata-stripping
Closed

fix: complete metadata stripping for all channel sentinel patterns (#211)#310
AliceLJY wants to merge 1 commit intomasterfrom
fix/complete-metadata-stripping

Conversation

@AliceLJY
Copy link
Collaborator

Summary

Feishu channel metadata was leaking into stored memories because metadata stripping had three coverage gaps. The reporter provided Feishu samples confirming the leak.

Root cause

AUTO_CAPTURE_INBOUND_META_SENTINELS defines 6 sentinel labels, but the three stripping functions only covered a subset:

Sentinel label stripEnvelopeMetadata shouldCapture stripLeadingInboundMetadata
Conversation info Yes Yes Yes (leading only)
Sender Yes Yes Yes (leading only)
Thread starter Missing Missing Yes (leading only)
Replied message Yes Missing Yes (leading only)
Forwarded message context Missing Missing Yes (leading only)
Chat history since last reply Missing Missing Yes (leading only)

Fixes

  • Gap 1 (stripEnvelopeMetadata in src/smart-extractor.ts): Added Thread starter, Forwarded message context, and Chat history since last reply to the regex alternation.
  • Gap 2 (shouldCapture fallback in index.ts): Expanded metadataPattern regex to cover all 6 sentinel labels, with a parenthetical pattern that handles both (untrusted metadata): and (untrusted, for context): forms.
  • Gap 3 (stripLeadingInboundMetadata in index.ts): Rewrote to scan the entire text for sentinel + JSON blocks instead of only stripping from the beginning. Metadata appearing after user content is now removed.

Test plan

  • All 12 existing strip-envelope-metadata tests pass
  • Full test suite passes (0 failures)
  • Manual verification with Feishu samples from the reporter

Fixes #211

🤖 Generated with Claude Code

…pture

- Add 3 missing sentinel labels to stripEnvelopeMetadata regex
- Expand shouldCapture fallback regex to cover all 6 sentinels
- Make stripLeadingInboundMetadata handle non-leading metadata blocks

Fixes #211

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@AliceLJY
Copy link
Collaborator Author

Closing in favor of #229 which takes a better architectural approach (extracted cleanup module + comprehensive tests). Will follow up on #229 with the remaining gaps.

@AliceLJY AliceLJY closed this Mar 22, 2026
@AliceLJY AliceLJY deleted the fix/complete-metadata-stripping branch March 22, 2026 14:48
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] autoCapture includes Feishu metadata in stored memories

2 participants