fix: eliminate 5+ second delays from stale daemon.lock files (bd-htwx)

Root cause: When a bd daemon crashes, its daemon.lock file remains with
the old PID. If that PID gets reused by an unrelated process, the code
would wait 5 seconds for a socket that will never appear.

Fix: Use flock-based check as authoritative source for daemon liveness.
The OS releases flocks when a process dies, so this is immune to PID reuse.

Changes:
- handleExistingSocket: Check daemon flock before waiting for socket
- acquireStartLock: Verify daemon lock is held before waiting
- handleStaleLock: Use flock check to detect stale startlocks
- lockfile/process_*.go: Add pid <= 0 check to prevent false positives
  (PID 0 signals process group on Unix, not a specific process)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
beads/crew/emma
2025-12-31 13:03:49 -08:00
committed by Steve Yegge
parent e2121a2e07
commit 21de43538d
3 changed files with 46 additions and 11 deletions

View File

@@ -8,5 +8,8 @@ import (
// isProcessRunning checks if a process with the given PID is running
func isProcessRunning(pid int) bool {
if pid <= 0 {
return false // Invalid PID (0 would signal our process group, not a specific process)
}
return syscall.Kill(pid, 0) == nil
}

View File

@@ -10,6 +10,9 @@ const stillActive = 259
// isProcessRunning checks if a process with the given PID is running
func isProcessRunning(pid int) bool {
if pid <= 0 {
return false // Invalid PID
}
handle, err := windows.OpenProcess(windows.PROCESS_QUERY_LIMITED_INFORMATION, false, uint32(pid))
if err != nil {
return false