fix(coding-agent): acquire the bootstrap lock with an atomic rename - #1006
Closed
Adolanium wants to merge 1 commit into
Closed
fix(coding-agent): acquire the bootstrap lock with an atomic rename#1006Adolanium wants to merge 1 commit into
Adolanium wants to merge 1 commit into
Conversation
Contributor
|
Thank you for the report and proposed work. This root cause is now covered by maintainer-owned stacked PR #1161, authored independently from We did not inspect or reuse this PR's diff, branch, commits, implementation code, or tests; its public description/comments were used only as a bug report. To keep one review surface, this PR is superseded by #1161 and is being closed. The complete review stack is #1158–#1165. It is being left unmerged for human review after CI and review-bot findings are cleared. |
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.
Fixes #1005.
What was broken
acquireBootstrapLockreclaimed a stale lock withrm(lockDir)and then retriedmkdir. Two processes can both judge the same lock stale, and one process'srmcan delete a lock directory the other just created, with the loser's pid write landing inside the winner's directory. Both then return believing they hold the lock, so two venv rebuilds run concurrently and can corrupt the environment. Fresh installs and fleet boots are where several processes start together.The fix
Adopts the pattern the daemon launch lock and session leases already use: create a uniquely named candidate directory, write the pid file inside it, and atomically rename it onto the lock path (rename fails if the target exists). Stale reclamation renames the lock aside before deleting it, so a live lock created in the interim is never touched. One wrinkle: Windows fails a directory rename onto an existing target with
EPERMrather thanEEXIST, so that is treated as a lock-held signal too.Signature and staleness semantics are unchanged.
Testing
test/suite/regressions/1005-bootstrap-lock.test.ts: concurrent acquires serialize, a dead-pid lock is reclaimed with no leftover candidate or stale dirs, and a live lock injected between the stale rename-aside and the delete survives untouched.npx tsx ../../node_modules/vitest/dist/cli.js --run test/suite/regressions/1005-bootstrap-lock.test.ts test/kernel-bootstrap.test.ts: the 3 new tests pass; the 17 kernel-bootstrap failures reproduce identically on unmodified main (the suite's fakes are POSIX-only shell scripts that cannot spawn on Windows).npm run checkclean.Note
Fix
acquireBootstrapLockto use atomic rename preventing concurrent venv rebuildsbootstrap.tsto use an atomic directory rename: creates a UUID+PID candidate directory, writes a PID file, then renames it to the lock path atomically.ENOENTif it disappears.isLockDirExistsErrorto handleEEXIST,ENOTEMPTY, and WindowsEPERMas lock-exists conditions during rename.1005-bootstrap-lock.test.tscovering concurrent acquires, dead-process reclaim, and the live-lock-during-reclaim edge case.Macroscope summarized cf38413.