fix: eliminate stale FTS results after consolidation#45
Merged
pszymkowiak merged 1 commit intomainfrom Mar 20, 2026
Merged
Conversation
- Rebuild FTS index inside consolidate_topic() transaction to purge ghost entries - Scope memories_au trigger to UPDATE OF topic, summary, keywords only, preventing unnecessary FTS churn from update_access/apply_decay - Add migration to fix trigger on existing databases and rebuild FTS index - Add test reproducing the exact issue scenario
Contributor
Author
📊 Automated PR Analysis
SummaryFixes stale FTS5 search results after memory consolidation by scoping the SQLite UPDATE trigger to only indexed columns (topic, summary, keywords) and rebuilding the FTS index after bulk delete+insert operations. Includes an auto-migration path for existing databases. Review Checklist
Linked issues: #44 Analyzed automatically by wshm · This is an automated analysis, not a human review. |
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
Fixes #44 — after
icm consolidate,icm recallcould return both the consolidated memory and stale fragments from the originals.Root cause: The FTS5 external content table (
content='memories') could accumulate ghost entries in its inverted index because:memories_auUPDATE trigger fired on every update (includingupdate_accessandapply_decay), needlessly churning the FTS index on non-indexed columnsconsolidate_topic()Fix (3 parts):
INSERT INTO memories_fts(memories_fts) VALUES('rebuild')inside theconsolidate_topic()transaction guarantees index consistencyAFTER UPDATE ON memoriestoAFTER UPDATE OF topic, summary, keywords ON memoriessoupdate_access/apply_decayno longer touch the FTS indexTest plan
test_consolidate_no_stale_fts_resultsreproducing the exact issue scenario (store 3, consolidate, verify recall returns only consolidated)cargo fmtclean🤖 Generated with Claude Code