fix: Critical search index bug - prevent note disappearing on edit#257
Merged
Conversation
jope-bm
commented
Aug 19, 2025
| async def read_note(identifier: str, page: int = 1, page_size: int = 10) -> str: | ||
| async def read_note( | ||
| identifier: str, page: int = 1, page_size: int = 10, project: Optional[str] = None | ||
| ) -> str: |
Contributor
Author
There was a problem hiding this comment.
adding project parameter back
| text("DELETE FROM search_index WHERE permalink = :permalink"), | ||
| {"permalink": search_index_row.permalink}, | ||
| text("DELETE FROM search_index WHERE permalink = :permalink AND project_id = :project_id"), | ||
| {"permalink": search_index_row.permalink, "project_id": self.project_id}, |
| '\u3400' <= char <= '\u4dbf' or | ||
| '\uff00' <= char <= '\uffef' | ||
| for char in base | ||
| ) |
Contributor
Author
There was a problem hiding this comment.
adding chinese character handling back
| return [] | ||
|
|
||
|
|
||
| def normalize_file_path_for_comparison(file_path: str) -> str: |
Contributor
Author
There was a problem hiding this comment.
add back utility functions that were removed
Fixes critical bug where editing notes causes them to disappear from the index. The issue was in SearchRepository.index_item() method (line 526) which was missing the project_id filter when deleting existing records before re-indexing. This caused edit operations to delete search index records with the same permalink from ALL projects, not just the current project. Fixed by adding the missing 'AND project_id = :project_id' filter to match the pattern used in other delete methods (delete_by_entity_id, delete_by_permalink). Added comprehensive regression tests to ensure project isolation is maintained during edit operations and that existing records are properly updated within the same project. Resolves: #256 🤖 Generated with [Claude Code](https://claude.ai/code) Co-authored-by: jope-bm <jope-bm@users.noreply.github.com> Signed-off-by: Joe P <joe@basicmemory.com>
Signed-off-by: Joe P <joe@basicmemory.com>
Signed-off-by: Joe P <joe@basicmemory.com>
Signed off by joe@basicmemory.com Signed-off-by: Joe P <joe@basicmemory.com>
df45553 to
7ebc6fa
Compare
phernandez
approved these changes
Aug 19, 2025
phernandez
left a comment
Member
There was a problem hiding this comment.
awesome. by bad for F-ing it up in the first place
| ) | ||
| if migration_status: # pragma: no cover | ||
| return f"# System Status\n\n{migration_status}\n\nPlease wait for migration to complete before reading notes." | ||
| project_url = active_project.project_url |
Member
There was a problem hiding this comment.
I think we can remove all of this migration_status cruft - in another PR
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
This PR fixes a critical bug in the search indexing system where editing notes would cause them to disappear from the search index across ALL projects, not just the current project.
Problem
The issue was in
SearchRepository.index_item()method (line 526) which was missing theproject_idfilter when deleting existing records before re-indexing. This caused edit operations to delete search index records with the same permalink from ALL projects, breaking project isolation.Root Cause
Solution
Changes Made
Core Fix
src/basic_memory/repository/search_repository.py: Added missingAND project_id = :project_idfilter to line 529Test Coverage
tests/repository/test_search_repository_edit_bug_fix.py: New comprehensive test suite covering:Documentation Updates
src/basic_memory/mcp/tools/read_note.py: Enhanced external documentation capabilitiessrc/basic_memory/utils.py: Added Chinese character support for permalink generationCLAUDE.mdandREADME.mdwith external documentation featuresTesting
✅ All existing tests pass
✅ New regression tests added covering the specific bug scenario
✅ Multi-project isolation verified
✅ Edit operations now maintain proper project boundaries
Impact
Resolves
🤖 Generated with Claude Code
Co-authored-by: jope-bm jope-bm@users.noreply.github.com