fix(consolidation): dedup against live memories within a run (#747)#748
fix(consolidation): dedup against live memories within a run (#747)#748MarvinFS wants to merge 2 commits into
Conversation
…0#747) The mem::consolidate handler snapshots existing memories into `existingMemories` once before the concept-group loop and never refreshes it. A parallel `existingTitles` Set was populated on every create/evolve but never read - dead code. The dedup check therefore scanned only the stale snapshot, so when two concept groups in the same run synthesized the same title, the second group failed to find the memory the first had just created. It fell into the create branch and produced a second isLatest memory with no parent: a duplicate plus an orphaned predecessor, and a broken version chain. Keep the snapshot live instead of carrying an unused index: - Remove the dead `existingTitles` Set. - Push each newly created memory into `existingMemories`. - On evolve, replace the matched predecessor in place. The title match does not filter on isLatest, so appending would leave the superseded row matchable and let a third same-title group evolve it, recreating a second latest; in-place replacement keeps exactly one matchable row per title and a linear A -> B -> C chain. The cross-project guard in the match predicate is untouched, so scoped runs still refuse to evolve another project's identically titled memory. Adds regression tests to test/consolidate-project-scope.test.ts: a two-group collision (asserts one active memory, intact parent chain, no orphan) and a three-group collision (asserts one active memory, linear three-version chain). Both fail on current main and pass with this fix. Signed-off-by: MarvinFS <MarvinFS@users.noreply.github.com>
|
@MarvinFS is attempting to deploy a commit to the rohitg00's projects Team on Vercel. A member of the Team first needs to authorize it. |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughThis PR fixes issue ChangesSame-title memory consolidation fix
Sequence Diagram(s)sequenceDiagram
participant ConceptGroup
participant Consolidate
participant existingMemories
ConceptGroup->>Consolidate: provide observation group (synthesized title)
Consolidate->>existingMemories: search for match by title
alt match found
Consolidate->>Consolidate: evolve matched memory -> evolved
Consolidate->>existingMemories: reflectMemoryInSnapshot(replaced by evolved)
else no match
Consolidate->>Consolidate: create new memory
Consolidate->>existingMemories: reflectMemoryInSnapshot(appended new)
end
Consolidate->>ConceptGroup: continue with next group
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/functions/consolidate.ts (1)
202-210: ⚡ Quick winRemove WHAT-style inline comments and encode intent in code structure.
Line 202–210 and Line 228–231 add explanatory WHAT comments in
src/, which violates the repository rule. Prefer extracting these blocks into clearly named helpers so intent is self-describing without inline narrative comments.As per coding guidelines,
src/**/*.{ts,js}: "No code comments explaining WHAT — use clear naming instead".Also applies to: 228-231
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/functions/consolidate.ts` around lines 202 - 210, The inline WHAT-style comment above the in-memory snapshot update should be removed and the intent encoded in a clearly named helper; extract the replace-or-append logic into a function (for example updateInMemorySnapshot(existingMemories, existingMatch, evolved) or mergeEvolvedMemoryIntoSnapshot) and call it from consolidate so the code reads self-descriptively (use the same helper pattern for the similar block at 228–231). Ensure the new helper contains the existing index/replace-or-push logic operating on existingMemories and is used in place of the comment+inline code so no explanatory WHAT comments remain in src.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@src/functions/consolidate.ts`:
- Around line 202-210: The inline WHAT-style comment above the in-memory
snapshot update should be removed and the intent encoded in a clearly named
helper; extract the replace-or-append logic into a function (for example
updateInMemorySnapshot(existingMemories, existingMatch, evolved) or
mergeEvolvedMemoryIntoSnapshot) and call it from consolidate so the code reads
self-descriptively (use the same helper pattern for the similar block at
228–231). Ensure the new helper contains the existing index/replace-or-push
logic operating on existingMemories and is used in place of the comment+inline
code so no explanatory WHAT comments remain in src.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 4f47a6b0-7b5d-4278-a6f6-30977143148a
📒 Files selected for processing (2)
src/functions/consolidate.tstest/consolidate-project-scope.test.ts
Address CodeRabbit review on rohitg00#748: replace the two inline WHAT-style comments at the create/evolve sites with a single named helper, reflectMemoryInSnapshot, so the snapshot-maintenance intent is carried by the function name and the in-place-replace rationale lives in one doc comment. Behavior is unchanged; the consolidate-project-scope regression tests still pass. Signed-off-by: MarvinFS <MarvinFS@users.noreply.github.com>
What
Fixes the within-run duplication and orphaning in
mem::consolidatereported in #747.The handler snapshots existing memories into
existingMemoriesonce before the concept-group loop and never refreshes it. A parallelexistingTitlesSet was populated on every create/evolve but never read - dead code. The dedup check (existingMemories.find(...)) therefore only ever saw the stale snapshot, so when two concept groups in the same run synthesized the same title, the second group did not find the memory the first had just created. It took the create branch and wrote a secondisLatestmemory with noparentId- a duplicate active memory plus an orphaned predecessor and a broken version chain.Why it happens
Each concept group is its own
provider.compresscall, and distinct concepts frequently compress to the same synthesized title. The snapshot is read once; new memories are persisted viakv.setbut never added back to the in-memory array the dedup scans.The fix
Keep the snapshot live instead of carrying an unused index:
existingTitlesSet.existingMemories.isLatest, so a plain append would leave the now-superseded row matchable and let a third same-title group evolve it, recreating a second latest. In-place replacement keeps exactly one matchable row per title and a linearA -> B -> Cchain.The cross-project guard in the match predicate is untouched, so a scoped run still refuses to evolve another project's identically titled memory (the existing
consolidate-project-scopetests pass unchanged).How to verify
Two regression tests were added to
test/consolidate-project-scope.test.ts:parentId/supersedeschain, no orphan.Both are red on
main(the 2-group case yields 2 active memories / 2 parentless roots, the 3-group case yields 3) and green with this change.Fixes #747
Summary by CodeRabbit
Bug Fixes
Tests