Refactor: Enhance reliability, logging, and process management #30
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 addresses several "silent failure" anti-patterns in the codebase. It introduces robust logging (full tracebacks), significantly improves the reliability of status checks using a PID file, and refactors the backup logic to be cleaner and safer.
🔍 Key Changes
1. Observability & Logging ("Errors should never pass silently")
logger.errorwithlogger.exceptionin the main daemon loop to capture full stack traces during crashes.RotatingFileHandlerbackup count from1to5to prevent history loss during crash loops.setup_logging()function.2. Configuration & Reliability
daemon.pidfile to track the running process.show_statusparsedlaunchctl/systemctlstdout (brittle).show_statuschecks for the PID file and verifies the process is alive usingos.kill(pid, 0).Config.loadnow explicitly catchestomllib.TOMLDecodeErrorand fails fast with a helpful error message instead of silently loading defaults.3. Code Structure
@temporary_indexcontext manager.pulsar_indexis always cleaned up, even if the backup logic crashes.run_backup.4. Git Wrapper Improvements
get_last_commit_timeto raise exceptions instead of returning"Never". This allows the CLI to distinguish between a "New Repository" and a "Broken Repository" (marked asERRORinlist_repos).✅ Checklist