fix(memory): harden memory prune guards#1889
Conversation
|
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 (2)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughThis PR updates the agent-memory system’s retrieval, consolidation, pruning, and lifecycle behavior. It adds stored-vector neighbor lookup, dead-vector cleanup, resumable consolidation scanning, tighter ChangesMemory pruning, consolidation, retrieval
Estimated code review effort: 4 (Complex) | ~60 minutes Sequence Diagram(s)sequenceDiagram
participant Caller
participant RetrievalService
participant EmbeddingProvider
participant VectorStoreManager
Caller->>RetrievalService: retrieve(query, options)
RetrievalService->>RetrievalService: startQueryEmbedding(query, fingerprint)
alt identical query in-flight
RetrievalService-->>Caller: reuse in-flight promise
else distinct query, under concurrency limit
RetrievalService->>EmbeddingProvider: embed(query)
EmbeddingProvider-->>RetrievalService: embedding
else third distinct concurrent query
RetrievalService-->>Caller: degrade to FTS-only
end
RetrievalService->>VectorStoreManager: query vectors, collect dead matches
RetrievalService->>VectorStoreManager: deletePrunableVectorsForMemoryIds(deadIds)
RetrievalService-->>Caller: fused results
sequenceDiagram
participant MaintenanceService
participant VectorStoreManager
participant MemoryVectorStore
participant Repository
MaintenanceService->>Repository: listConsolidationScanRows(cursor)
MaintenanceService->>VectorStoreManager: queryNeighborsByMemoryId(memoryId, topK)
VectorStoreManager->>MemoryVectorStore: queryByMemoryId(memoryId, options)
MemoryVectorStore-->>VectorStoreManager: neighbor matches
VectorStoreManager-->>MaintenanceService: matches
MaintenanceService->>MaintenanceService: select/merge superseding pairs, advance cursor
MaintenanceService->>VectorStoreManager: deletePrunableVectorsForMemoryIds(deadIds)
MaintenanceService->>Repository: clearPrunableEmbeddingRefs(ids)
Possibly related issues
Possibly related PRs
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 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.
Actionable comments posted: 1
🧹 Nitpick comments (1)
test/main/presenter/memoryPresenter.test.ts (1)
4356-4360: 🩺 Stability & Availability | 🔵 Trivial | ⚡ Quick winLoosened assertion may be masking non-determinism.
This assertion was widened to accept either
pending_embeddingorembeddedfor the challenger row post-consolidation, rather than a single deterministic status. Given this PR's broader changes to query-embedding concurrency and pruning, worth confirming whether this reflects a legitimate, understood race (e.g., embedding completion timing relative to consolidation) versus a symptom of a flaky/nondeterministic write ordering that should instead be fixed or awaited deterministically in the test setup.🤖 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 `@test/main/presenter/memoryPresenter.test.ts` around lines 4356 - 4360, The `memoryPresenter.test.ts` expectation for `repo.getById('c1')?.status` is masking a possible race between consolidation and embedding completion. Tighten the test around the relevant `consolidate`/embedding flow so the challenger row reaches one deterministic status before asserting, or explicitly await the async embedding work in the test setup rather than accepting both `pending_embedding` and `embedded`. Use the `buildMemoryProvenanceKey`, `repo.getById`, and consolidation path in the test to locate and make the ordering deterministic.
🤖 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.
Inline comments:
In `@src/main/presenter/memoryPresenter/services/managementService.ts`:
- Around line 114-120: `listMemories` in `managementService.ts` still exposes
internal `working` rows because it only filters out `persona`; update it to use
the shared `isInternalMemoryKind` guard, matching the hardened checks already
used by `restoreMemory`, `forgetMemory`, and `archiveUserMemory`. Locate the
change in `ManagementService.listMemories` and replace the ad hoc kind check
with the internal-memory predicate so the management UI only receives
non-internal memories.
---
Nitpick comments:
In `@test/main/presenter/memoryPresenter.test.ts`:
- Around line 4356-4360: The `memoryPresenter.test.ts` expectation for
`repo.getById('c1')?.status` is masking a possible race between consolidation
and embedding completion. Tighten the test around the relevant
`consolidate`/embedding flow so the challenger row reaches one deterministic
status before asserting, or explicitly await the async embedding work in the
test setup rather than accepting both `pending_embedding` and `embedded`. Use
the `buildMemoryProvenanceKey`, `repo.getById`, and consolidation path in the
test to locate and make the ordering deterministic.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 475c06a5-192b-4a45-a800-b923e99039ce
📒 Files selected for processing (19)
docs/architecture/agent-memory-system/spec.mddocs/issues/memory-recall-hot-path-keyword-recall/spec.mdsrc/main/presenter/memoryPresenter/index.tssrc/main/presenter/memoryPresenter/infra/memoryVectorStore.tssrc/main/presenter/memoryPresenter/infra/vectorStoreManager.tssrc/main/presenter/memoryPresenter/runtimeConstants.tssrc/main/presenter/memoryPresenter/services/maintenanceService.tssrc/main/presenter/memoryPresenter/services/managementService.tssrc/main/presenter/memoryPresenter/services/retrievalService.tssrc/main/presenter/memoryPresenter/types.tssrc/main/presenter/sqlitePresenter/tables/agentMemory.tssrc/shared/contracts/routes/memory.routes.tstest/main/presenter/agentMemoryTable.test.tstest/main/presenter/fakes/memoryFakes.tstest/main/presenter/memoryExtraction.test.tstest/main/presenter/memoryPresenter.test.tstest/main/presenter/memorySearch.test.tstest/main/presenter/memoryVectorStore.test.tstest/main/routes/memoryDto.test.ts
Summary by CodeRabbit
New Features
memory.searchdepth controls with a safer default (50) and tighter max cap (100).Bug Fixes
Documentation
Tests