Skip to content

feat: crash recovery, agent experience enrichment, hierarchical retrieval#317

Merged
win4r merged 2 commits intoCortexReach:masterfrom
AliceLJY:feat/crash-recovery-and-hierarchy
Mar 23, 2026
Merged

feat: crash recovery, agent experience enrichment, hierarchical retrieval#317
win4r merged 2 commits intoCortexReach:masterfrom
AliceLJY:feat/crash-recovery-and-hierarchy

Conversation

@AliceLJY
Copy link
Collaborator

Summary

  • Feature 4 — Crash Recovery: Redo markers in {dbPath}/_redo/ prevent silent memory loss on mid-extraction crashes. Orphaned markers are recovered on plugin init (configurable: crashRecovery.enabled, crashRecovery.maxAgeHours).
  • Feature 5 — Agent Experience Enrichment: Tool outcome summarization enriches extraction context. Cases/patterns are routed to agent:{agentId} scope for agent-specific learning.
  • Feature 6 — Hierarchical Retrieval: Two-pass retrieval via topic clusters — first find relevant clusters by centroid cosine similarity, then search within. Cold start fallback to flat retrieval when <100 memories or <3 topics. Configurable via retrievalStrategy.strategy and retrievalStrategy.hierarchical.alpha.

New files

  • src/redo-log.ts — Redo marker CRUD + stale detection
  • src/tool-outcomes.ts — Tool call pattern detection and summarization
  • src/topic-index.ts — Topic cluster index with centroid computation
  • src/hierarchical-retriever.ts — Two-pass hierarchical retrieval with score propagation

Modified files

  • index.ts — Redo lifecycle wrapping, recovery scan on init, tool summary injection, config parsing
  • src/smart-extractor.ts — Agent scope routing for cases/patterns, topic field in metadata
  • src/memory-categories.ts — Added topic?: string to CandidateMemory
  • src/extraction-prompts.ts — Added topic field to extraction output schema
  • src/retriever.ts — Exposed getEmbedder() on MemoryRetriever

Test plan

  • test/redo-log.test.mjs — 11 tests: marker lifecycle, stale detection, directory creation, edge cases
  • test/topic-index.test.mjs — 12 tests: build, findRelevant, addMemory, cold start fallback, getStats
  • test/tool-outcomes.test.mjs — 7 tests: pattern detection, dedup, empty input
  • Full existing test suite passes (30 test files)

Reference: https://github.com/CortexReach/memory-lancedb-pro-enhancements

🤖 Generated with Claude Code

AliceLJY and others added 2 commits March 23, 2026 18:31
…etrieval

Feature 4 — Crash Recovery via Redo Markers:
- Add src/redo-log.ts with write/delete/scan/isStale operations
- Store markers in {dbPath}/_redo/{taskId}.json with atomic create
- Wrap smart extraction in redo marker lifecycle (write before, delete after)
- Scan and recover orphaned markers on plugin init (< 24h by default)
- Config: crashRecovery.enabled (default true), crashRecovery.maxAgeHours (default 24)

Feature 5 — Agent Experience Enrichment:
- Add src/tool-outcomes.ts with summarizeToolOutcomes() for tool call detection
- Append tool outcome summary to conversation text before extraction
- Route cases/patterns to agent:{agentId} scope when agentId is set
- Pass agentId through ExtractPersistOptions to SmartExtractor

Feature 6 — Hierarchical Retrieval with Topic Clusters:
- Add topic?: string field to CandidateMemory and extraction prompt
- Add src/topic-index.ts: build clusters from store, compute centroids,
  find relevant clusters by cosine similarity, cold start fallback
- Add src/hierarchical-retriever.ts: two-pass retrieval with score
  propagation (alpha * intra_score + (1-alpha) * cluster_score)
- Expose getEmbedder() on MemoryRetriever for external access
- Config: retrievalStrategy.strategy ("flat"|"hierarchical", default "flat"),
  retrievalStrategy.hierarchical.alpha (default 0.7)

Tests: redo-log (11 tests), topic-index (12 tests), tool-outcomes (7 tests)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1. [High] Wire hierarchical retriever into actual recall path and tools
   via activeRetriever (was dead code — created but never used)
2. [High] TopicIndex.build: graceful degradation when store.list() returns
   empty vectors — still builds topic membership for ID filtering
3. [High] cases/patterns scope override: also override scopeFilter for dedup
   so dedup searches agent scope, preventing cross-scope merge
4. [Medium] Redo recovery: add claimRedoMarker (atomic rename) to prevent
   concurrent processes from replaying the same marker
5. [Medium] tool_call JSON parsing: use name-only regex instead of trying
   to match nested braces (was stopping at first } in nested JSON)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@win4r win4r merged commit f08b92c into CortexReach:master Mar 23, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants