fix: deduplicate embedded Tags footer in compaction restore - #249
Conversation
lindixu6-hash
left a comment
There was a problem hiding this comment.
The duplication fix is valid for auto-captured records, and the submitted tests are failure-sensitive, but the current regex removes any trailing Tags: line whenever structured tags exist, even when the footer is user-authored and does not match those tags.
For example, a memory ending in Tags: user-authored evidence with structured tags ["canonical"] is rendered without that original line and only Tags: canonical remains. Manual/API/imported memories can store arbitrary content plus structured tags, so this is observable content loss.
Please strip the footer only when its normalized value matches the canonical structured tags (or when another reliable auto-capture provenance condition proves it is the generated footer), and add a regression showing a non-matching trailing Tags: line is preserved.
Local verification at 9ad5b8e with an isolated HOME:
- frozen root and web installs
- compaction target: 10/10 passed
- full suite after build: 409/409 passed
- typecheck, Prettier check, and production build passed
- mutation check: reverting only the implementation while retaining the tests produced the expected duplicate-footer failure
So the existing duplication regression is covered; the remaining blocker is preserving unrelated user content.
|
Following up on the requested changes. Are you still planning to address the review feedback? If not, I can close this PR to keep the queue clean; it can always be reopened later. |
|
Skipped: this PR conflicts with |
|
Skipped: this PR conflicts with |
9ad5b8e to
7bec2d4
Compare
Auto-capture embeds a Tags: line in the body; compaction also appends structured tags. Remove the trailing footer only when it matches those tags so user-authored Tags: content is preserved.
7bec2d4 to
ca4b842
Compare
lindixu6-hash
left a comment
There was a problem hiding this comment.
The follow-up at exact head ca4b842b891faf70f5515893c2d309c83ea6e638 resolves the data-loss blocker from my previous review.
flowchart LR
A[Stored memory body] --> B{Trailing Tags footer?}
B -->|No| C[Preserve body]
B -->|Yes| D{Normalized footer equals structured tags?}
D -->|Yes| E[Strip embedded duplicate]
D -->|No| C
C --> F[Append canonical structured Tags line]
E --> F
style E fill:#c8e6c9,color:#1a5e20
style C fill:#bbdefb,color:#0d47a1
The implementation now strips a trailing Tags: footer only when its trimmed, order-independent value matches the structured tags. A non-matching user-authored footer remains intact, while the canonical structured line is still appended. The new regression directly covers the previously demonstrated user-authored evidence / canonical mismatch.
Independent verification:
HOME=$PWD/.test-home bun test tests/compaction-agent-preservation.test.ts— 12 pass, 0 fail;bun run typecheck— pass;- Prettier check on both changed files — pass;
- upstream six-platform package-smoke jobs on this head — all pass.
No remaining blockers. Approved.
Auto-capture embeds a "Tags: ..." footer inside the memory body (added in #131); compaction restore appends its own canonical Tags line, duplicating the tags in the restored context. Strip the embedded footer when a canonical line follows.
Regression from #131.