Fix bd-54: Prevent multiple daemon instances via file locking

- Implemented daemon.lock using flock (Unix) and LockFileEx (Windows)
- Lock acquired before PID file, held for daemon lifetime
- Eliminates race conditions in concurrent daemon starts
- Backward compatible: falls back to PID check for old daemons
- Updated isDaemonRunning() to check lock availability
- All tests pass including new lock and backward compatibility tests

Amp-Thread-ID: https://ampcode.com/threads/T-0e2627f4-03f9-4024-bb4b-21d23d296300
Co-authored-by: Amp <amp@ampcode.com>
This commit is contained in:
Steve Yegge
2025-10-22 13:59:21 -07:00
parent d1d3fcdf02
commit e291f464ee
9 changed files with 475 additions and 76 deletions

View File

@@ -7,6 +7,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]
### Fixed
- **Critical**: Multiple daemon race condition (bd-54)
- Implemented file locking (`daemon.lock`) to prevent multiple daemons per repository
- Uses `flock` on Unix, `LockFileEx` on Windows for process-level exclusivity
- Lock held for daemon lifetime, automatically released on exit
- Eliminates race conditions in concurrent daemon start attempts
- Backward compatible: Falls back to PID check for pre-lock daemons during upgrades
## [0.11.0] - 2025-10-22
### Added