fix: Terminate sync immediately when project is deleted#366
Conversation
Fixes #188 where sync fails with FOREIGN KEY constraint violations when a project is deleted during sync operations. Changes: - Add SyncFatalError exception to distinguish fatal from recoverable errors - Detect FOREIGN KEY failures in entity_repository.upsert_entity() - Check exception chain in sync_service.sync_file() and re-raise fatal errors - Add repository-level test for invalid project_id handling - Add integration test to verify fatal errors terminate sync immediately Before: Circuit breaker retries each file 3 times, wastes resources After: First FOREIGN KEY error terminates sync immediately with clear message Fatal errors (project deleted, database corrupt) now bypass the circuit breaker and terminate sync immediately, while recoverable file-level errors (bad markdown, parse errors) continue to use circuit breaker as intended. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com> Signed-off-by: phernandez <paul@basicmachines.co>
|
Claude finished @phernandez's task —— View job Reviewing PR #366
|

Summary
Fixes #188 where sync fails with FOREIGN KEY constraint violations when a project is deleted during sync operations.
Problem
When a project is deleted mid-sync, every file fails with a FOREIGN KEY constraint error. The circuit breaker treats these as file-level errors and retries each file 3 times, wasting resources before eventually skipping them all.
Solution
Introduced
SyncFatalErrorexception to distinguish between:Changes
SyncFatalErrorexception inservices/exceptions.pyentity_repository.upsert_entity()to detect FOREIGN KEY constraint failures and raiseSyncFatalErrorwith clear messagesync_service.sync_file()to check exception chain forSyncFatalErrorand re-raise immediatelytest_entity_repository_upsert.pytest_sync_service.pyto verify sync terminates immediatelyBehavior
Before:
After:
SyncFatalErroris raised and propagates through exception chainTest Plan
SyncFatalErroris raised with correct message🤖 Generated with Claude Code