Files
claude-hud/tests
Brandon Wie 086603e7ca fix: treat zero-byte lock file as stale to prevent permanent busy state (#203)
* fix: treat zero-byte lock file as stale to prevent permanent busy state

If the HUD process crashes between fs.openSync(lockPath, 'wx') and
fs.writeFileSync(fd, timestamp), a 0-byte .usage-cache.lock remains.
readLockTimestamp() returns null for unparseable content, and the
existing guard (lockTimestamp != null && expired) never fires, leaving
the cache permanently stuck in 'busy' state.

Add a lockTimestamp === null guard that uses fs.statSync().mtimeMs to
distinguish a crash leftover (old mtime → remove and retry) from an
active writer that is between openSync and writeFileSync (recent mtime
→ return busy). The original != null stale-timestamp path is unchanged.

Closes #202

* test: stabilize stale-lock regression coverage

* test: make usage-api suite self-build for source-only PRs

---------

Co-authored-by: Jarrod Watts <jarrod@cubelabs.xyz>
2026-03-14 11:06:09 +11:00
..
2026-01-03 18:52:12 +11:00