Files
ruflo/v3/@claude-flow/memory/src
ruv 850450f385 feat(memory): #2061 ADR-125 Phase 4 — MemoryConsolidator (sweep + dedup + compactHnsw)
Promotes the Phase 3 consolidator placeholder to a real maintenance pass:

- `MemoryConsolidator.sweepExpired()` — drops entries past `expiresAt`
  from `entries`/`namespaceIndex`/`keyIndex`/`tagIndex` AND from the HNSW
  index (`HNSWIndex.removePoint`). Cleans up emptied namespace/tag sets.
- `MemoryConsolidator.dedup(strategy)` — SHA-256 content hash, then one
  of `keep-newest | keep-oldest | merge-tags`. `merge-tags` unions tag
  sets across duplicates and updates `tagIndex` for newly-added tags.
- `MemoryConsolidator.compactHnsw()` — rebuilds a fresh `HNSWIndex` from
  the current `entries` and swaps pointers atomically. Uses the new
  `HNSWIndex.getConfig()` accessor instead of reaching into private state.
- `MemoryConsolidator.runAll()` — sweep → dedup → compact, returning the
  full `ConsolidationResult` breakdown.

Wiring:
- `UnifiedMemoryService` lazy-loads + memoizes the consolidator via
  `getConsolidator()`. With `consolidator.autoRun: true` a `setInterval`
  fires `runAll()` every 6h (configurable, unref'd to allow process
  exit). `close()` clears the timer before snapshotting.
- `controller-registry.ts` `nightlyLearner` controller now returns a
  thin wrapper bound to `consolidator.runAll()` when a `memoryService`
  is registered (`RuntimeConfig.memoryService`). Falls back to the
  upstream AgentDB `NightlyLearner` when only `agentdb` is registered.
  `isControllerEnabled('nightlyLearner')` updated to enable on either
  signal.

Tests: `src/consolidator.test.ts` covers Acceptance Criterion #4 (1000
expired → 0 remaining + HNSW emptied), all three dedup strategies,
compact-after-sweep size invariant, auto-run timer firing, close()
timer cleanup, and the nightlyLearner controller delegation.

394/13 tests pass (was 385/12).

Refs: #2061, ADR-125 §Phase 4, Acceptance Criterion #4.

Co-Authored-By: RuFlo <ruv@ruv.net>
2026-05-19 17:55:25 -04:00
..
2026-01-04 23:50:45 +00:00
2026-01-04 23:50:45 +00:00
2026-01-05 16:42:40 +00:00
2026-01-04 19:57:32 +00:00
2026-02-08 17:11:18 +00:00
2026-01-05 17:28:09 +00:00
2026-02-08 03:36:33 +00:00
2026-02-08 03:37:26 +00:00
2026-02-08 03:36:39 +00:00
2026-02-08 03:38:14 +00:00
2026-01-05 17:28:09 +00:00
2026-01-05 17:28:09 +00:00
2026-02-08 03:41:11 +00:00