fix: Prevent deleted projects from being recreated by background sync (#193) (#370)

Signed-off-by: Claude <noreply@anthropic.com>
Signed-off-by: phernandez <paul@basicmachines.co>
This commit is contained in:
Paul Hernandez
2025-10-16 15:16:24 -05:00
committed by GitHub
parent b7497d7484
commit 449b62d947
4 changed files with 152 additions and 3 deletions
+7 -3
View File
@@ -360,11 +360,15 @@ class ProjectService:
}
await self.repository.create(project_data)
# Add projects that exist in DB but not in config to config
# Remove projects that exist in DB but not in config
# Config is the source of truth - if a project was deleted from config,
# it should be deleted from DB too (fixes issue #193)
for name, project in db_projects_by_permalink.items():
if name not in config_projects:
logger.info(f"Adding project '{name}' to configuration")
self.config_manager.add_project(name, project.path)
logger.info(
f"Removing project '{name}' from database (deleted from config, source of truth)"
)
await self.repository.delete(project.id)
# Ensure database default project state is consistent
await self._ensure_single_default_project()
+11
View File
@@ -236,6 +236,17 @@ class WatchService:
# avoid circular imports
from basic_memory.sync.sync_service import get_sync_service
# Check if project still exists in configuration before processing
# This prevents deleted projects from being recreated by background sync
from basic_memory.config import ConfigManager
config_manager = ConfigManager()
if project.name not in config_manager.projects and project.permalink not in config_manager.projects:
logger.info(
f"Skipping sync for deleted project: {project.name}, "
f"change_count={len(changes)}"
)
return
sync_service = await get_sync_service(project)
file_service = sync_service.file_service