mirror of
https://github.com/ruvnet/ruflo.git
synced 2026-11-23 21:59:14 +09:00
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>