← Back to PRs

#21611: feat(memory-neo4j): add Phase 3b temporal staleness detection

by tsukhani open 2026-02-20 04:47 View on GitHub →
docs channel: telegram channel: voice-call gateway extensions: memory-lancedb cli scripts commands agents size: XL
## Summary Adds a new sleep cycle phase (3b) that detects and removes memories about past events/dates that are no longer relevant. ### Problem Memories about ephemeral events (ferry bookings, download progress, meeting times) persist indefinitely. The existing decay mechanism uses importance-based half-life but has no concept of temporal relevance — it can't tell that a ferry booking from 2 weeks ago is now useless. ### Solution **Phase 3b: Temporal Staleness Detection** runs between Phase 3 (Decay) and Phase 4 (Cleanup): 1. **Regex pre-filter** in Neo4j catches memories with date/time patterns, progress indicators, or temporal keywords — avoids wasting LLM calls on non-temporal memories 2. **LLM classifier** (`classifyTemporalStaleness`) evaluates each candidate as `stale` or `lasting` 3. Stale memories are invalidated; lasting ones are kept ### Design decisions - **Conservative by default**: returns `lasting` on any LLM failure or uncertainty - **Only checks memories ≥ 3 days old** (configurable via `temporalStalenessMinAgeDays`) — won't remove upcoming events - **Skips core memories** — user-curated memories are never touched - **Regex pre-screen** keeps LLM costs low (typically filters 90%+ of memories) - **Parallel batch processing** like other phases - **Configurable**: `skipTemporalStaleness` to disable entirely ### Files changed - `extractor.ts` — Added `classifyTemporalStaleness()` (+75 lines) - `neo4j-client.ts` — Added `fetchMemoriesForTemporalCheck()` (+35 lines) - `sleep-cycle.ts` — Added Phase 3b implementation (+81 lines) ### Testing - Build ✅ | Lint ✅ | All 42 sleep cycle tests pass ✅ - Tested regex pre-filter against live Neo4j: 17/237 memories matched (efficient filtering)

Most Similar PRs