fix(daemon): add cross-process locking to registry (bd-5bj)
The global daemon registry (~/.beads/registry.json) could be corrupted when multiple daemons from different workspaces wrote simultaneously. Changes: - Add file locking (flock) for cross-process synchronization - Use atomic writes (temp file + rename) to prevent partial writes - Keep entire read-modify-write cycle under single lock - Add FlockExclusiveBlocking and FlockUnlock to lockfile package This prevents race conditions that caused JSON corruption like `]]`. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -19,3 +19,14 @@ func flockExclusive(f *os.File) error {
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
// FlockExclusiveBlocking acquires an exclusive blocking lock on the file.
|
||||
// This will wait until the lock is available.
|
||||
func FlockExclusiveBlocking(f *os.File) error {
|
||||
return unix.Flock(int(f.Fd()), unix.LOCK_EX)
|
||||
}
|
||||
|
||||
// FlockUnlock releases a lock on the file.
|
||||
func FlockUnlock(f *os.File) error {
|
||||
return unix.Flock(int(f.Fd()), unix.LOCK_UN)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user