{{ message }}
fix: Prevent deleted projects from being recreated by background sync (#193) - #370
Merged
Merged
Conversation
…#193) This fix addresses issue #193 where deleted projects would reappear after being removed by the user. The problem occurred in two places: 1. **watch_service.handle_changes()**: Background sync would continue processing file changes for projects that had been deleted from configuration, causing database entries to be recreated for orphaned directories. 2. **project_service.synchronize_projects()**: Project synchronization would re-add projects from the database back to the configuration file, treating the database as the source of truth when it should be the config file. Root cause: When a project was deleted, the directory still existed on disk, and two different mechanisms would resurrect it: - Background sync processing file changes in the deleted project's directory - Project synchronization adding DB-only projects back to config Changes: - watch_service.py: Added check if project exists in config before syncing - project_service.py: Changed synchronize_projects to remove DB-only projects instead of adding them to config (config is source of truth) - test_watch_service.py: Added test_handle_changes_skips_deleted_project - test_project_service.py: Added test_synchronize_projects_removes_db_only_projects This fix ensures config is the single source of truth for project existence, and deleted projects stay deleted even when their directories remain on disk. Signed-off-by: Claude <noreply@anthropic.com> Signed-off-by: phernandez <paul@basicmachines.co>
Contributor
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 issue #193 from basic-memory-cloud where deleted projects would reappear after being removed by the user. This issue affected both local and cloud deployments.
Root Cause
When a project was deleted, the directory still existed on disk, and two different mechanisms would resurrect it:
Evidence from Cloud
Timeline from Logfire for tenant
0a20eb58-970f-ab05-ff49-25a9cdb2179c:The cloud sync worker runs
reconcile_projects_with_config()every 30 seconds, which was callingsynchronize_projects()and re-adding the deleted project back to config from the database.Changes Made
src/basic_memory/sync/watch_service.py(lines 241-251):handle_changes()before processing file changessrc/basic_memory/services/project_service.py(lines 363-371):synchronize_projects()behavior for DB-only projectsTests Added:
test_handle_changes_skips_deleted_projectintests/sync/test_watch_service.pytest_synchronize_projects_removes_db_only_projectsintests/services/test_project_service.pyImpact
This fix ensures that:
reconcile_projects_with_config()function now properly cleans up orphaned DB entriesTest Plan
🤖 Generated with Claude Code