fix(memory): harden autoCapture prefix stripping and persist seen-count state#407
fix(memory): harden autoCapture prefix stripping and persist seen-count state#407Robinzhh wants to merge 1 commit intoCortexReach:masterfrom
Conversation
Review: REQUEST-CHANGESThe three bugs you're fixing are real and worth addressing — prefix stripping order, restart-lost seen counts, and subagent prompt pollution all cause data quality issues in production. However, the current implementation doesn't load. Please fix these before re-requesting review: Must fix:
Worth considering (not blocking):
|
Summary
Two minimal patches for the
autoCapturepipeline instripAutoCaptureInjectedPrefixand the seen-count state management.1. Prefix stripping order fix
stripLeadingInboundMetadata(normalized)was called after the webchat timestamp regex and feishu message_id regex, both of which use the^anchor. When a user message included aSender (untrusted metadata)block, the anchor-based regexes could not match because the string started withSenderinstead of the expected prefix.Fix: Move
stripLeadingInboundMetadatato before the channel-specific regexes so the^anchor works correctly.This also covers the feishu channel — the
[message_id: ...]\nou_xxx:prefix has the same^-anchor dependency.2. autoCapture seen-count persistence
autoCaptureSeenTextCountwas a pure in-memoryMap, which reset to zero on every gateway restart. This caused all historical messages in a session to be re-processed by autoCapture, potentially creating duplicate memory entries.Fix: Add a JSON sidecar file (
auto-capture-seen-count.json) to persist and restore the seen-count on startup.3. Subagent skip defense
Skip autoCapture for subagent sessions to prevent
[Subagent Context]/[Subagent Task]prompts from polluting memory.Changes
index.ts: ReorderstripLeadingInboundMetadatabefore channel-specific prefix regexes; add subagent-injected prompt stripping; addloadAutoCaptureSeenCount/persistAutoCaptureSeenCountsidecar persistence; add subagent session skip guard.package-lock.json: Version bump to1.1.0-beta.10.Verification
All fixes verified locally:
stripAutoCaptureInjectedPrefixpipeline test with realistic feishu/webchat inputFEISHU-E2E-03, memory recorde54fefba)