feat: crash recovery, agent experience enrichment, hierarchical retrieval#317
Merged
win4r merged 2 commits intoCortexReach:masterfrom Mar 23, 2026
Merged
Conversation
…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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
{dbPath}/_redo/prevent silent memory loss on mid-extraction crashes. Orphaned markers are recovered on plugin init (configurable:crashRecovery.enabled,crashRecovery.maxAgeHours).agent:{agentId}scope for agent-specific learning.retrievalStrategy.strategyandretrievalStrategy.hierarchical.alpha.New files
src/redo-log.ts— Redo marker CRUD + stale detectionsrc/tool-outcomes.ts— Tool call pattern detection and summarizationsrc/topic-index.ts— Topic cluster index with centroid computationsrc/hierarchical-retriever.ts— Two-pass hierarchical retrieval with score propagationModified files
index.ts— Redo lifecycle wrapping, recovery scan on init, tool summary injection, config parsingsrc/smart-extractor.ts— Agent scope routing for cases/patterns, topic field in metadatasrc/memory-categories.ts— Addedtopic?: stringto CandidateMemorysrc/extraction-prompts.ts— Added topic field to extraction output schemasrc/retriever.ts— ExposedgetEmbedder()on MemoryRetrieverTest plan
test/redo-log.test.mjs— 11 tests: marker lifecycle, stale detection, directory creation, edge casestest/topic-index.test.mjs— 12 tests: build, findRelevant, addMemory, cold start fallback, getStatstest/tool-outcomes.test.mjs— 7 tests: pattern detection, dedup, empty inputReference: https://github.com/CortexReach/memory-lancedb-pro-enhancements
🤖 Generated with Claude Code