fix: harden task status locks for transient ENOENT#47
Merged
tctinh merged 2 commits intotctinh:mainfrom Feb 15, 2026
Merged
Conversation
Ensure lock directories exist and retry ENOENT during lock acquisition to handle transient filesystem behavior on Windows. Switch TaskService.update to lock-first read-modify-write to avoid race windows between read and lock/write.
There was a problem hiding this comment.
Pull request overview
Hardens Hive’s on-disk task status locking to avoid transient ENOENT failures (notably on Windows) and removes a TOCTOU window in TaskService.update by switching to lock-first read/modify/write.
Changes:
- Ensure lock parent directories exist and retry lock acquisition on transient
ENOENTinacquireLock/acquireLockSync. - Change
TaskService.updateto acquire the lock before reading and then write viawriteJsonAtomicwhile the lock is held. - Add regression tests covering lock parent directory creation and transient
ENOENTretry behavior.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| packages/hive-core/src/utils/paths.ts | Harden lock acquisition by ensuring lock directories exist and treating ENOENT as retriable. |
| packages/hive-core/src/utils/paths.test.ts | Add tests for nested directory lock acquisition and transient ENOENT retry simulation. |
| packages/hive-core/src/services/taskService.ts | Update task status with lock-first read/modify/write to remove TOCTOU window. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Guard TaskService.update before lock acquisition so missing tasks fail fast without creating task directories via lock path setup. Also adds a regression assertion and aligns new test literals with existing quote style.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Fix ENOENT During
hive_worktree_createStatus Lock UpdateSummary
This PR hardens task status locking so
hive_worktree_createno longer fails when lock-file creation hits transientENOENT(seen on Windows setups).The previous flow could fail after the worktree was successfully created, when updating task status (
status.json.lock) duringTaskService.update.Root Cause
Two issues combined:
acquireLock/acquireLockSync) treated non-EEXISTerrors as fatal and did not recover from transientENOENTat lock-file creation time.TaskService.updateused read-then-lock/write ordering, leaving a race window between readingstatus.jsonand acquiring the file lock.What Changed
1) Lock acquisition hardened for transient
ENOENTFile:
packages/hive-core/src/utils/paths.tsacquireLockandacquireLockSyncnow:ENOENTas retriable (re-ensure directory and retry until timeout).EEXISTstale-lock handling unchanged.2)
TaskService.updatemoved to lock-first read-modify-writeFile:
packages/hive-core/src/services/taskService.tsTaskService.updatenow:finally.This removes the TOCTOU window from the update path.
3) Regression tests added
File:
packages/hive-core/src/utils/paths.test.tsENOENTfromopenSyncand verify lock acquisition retries successfully.Impact
Testing
Executed and passing:
bun test packages/hive-core/src/utils/paths.test.ts packages/hive-core/src/services/taskService.test.tsbun run test(frompackages/hive-core)bun run build(frompackages/hive-core)Issues
Should close issue #45