Repository navigation
Lock a Bootstrap Run's Directory, and Remove an Empty Leftover at a Tree's Name - #2503
Conversation
…ree's Name Two runs sharing a --dir use the same fixed tree names, so one run's staging removal or exit cleanup could delete a tree the other was still extracting into (#1792). Each run now holds an OS lock on <tree>.lock for its whole length, taken before anything that removes a tree: bootstrap.sh takes flock -n on it, and bootstrap.ps1 opens it with FileShare.None, which .NET implements as a flock on Linux, so the two loaders exclude each other there. A dead run releases the lock with its process, and bash closes the lock's descriptor for the tools it runs so a daemon cannot inherit it. A removal that clears a tree and then fails on the directory itself left an unmarked empty directory every later run refused (#1795). With the lock held, an empty directory at a managed name holds nothing to lose and no live run can own it, so both loaders now treat it as theirs. Fixes #1792 Fixes #1795 Co-Authored-By: Claude Opus 5.5 <[email protected]>
…re Honestly A directory find or Get-ChildItem cannot list was read as empty, so bootstrap.sh took it for its own and moved it aside, and bootstrap.ps1 threw out of the cleanup that asked. Both now fail closed, refusing it as somebody else's. bootstrap.ps1 reported every lock failure but a permission or path one as another run holding the lock, and bootstrap.sh reported a WSL open refused by a Windows run's lock as an unwritable directory. Each message now names the cause it can actually tell apart. Drops two assertions the refused-lock tests could not fail, and splits the README sentences this change wrote past the length limit. Co-Authored-By: Claude Opus 5.5 <[email protected]>
… Lock's Cause On Linux pwsh the marker's Test-Path throws on a directory it cannot read, which escaped Invoke-Cleanup before the listing guard was ever reached, so the marker check now runs inside the same try. A plain IOException is a sharing violation or flock conflict, and also any file system error .NET maps to no subclass, such as a read-only mount, so the contention message now names the reason first and calls another run the usual cause rather than the certain one. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Important
This repository does not receive automatic reviews because it has fewer than 10 stars. ⚙️ Run configuration
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## develop #2503 +/- ##
========================================
Coverage 58.50% 58.50%
========================================
Files 16 16
Lines 8066 8066
========================================
Hits 4719 4719
Misses 3347 3347
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
🟢 Approval recommended
Remaining findings are minor documentation and wording nits that do not block approval.
0 open findings
What changed in this PR
Adds per-tree locking for concurrent bootstrap runs and safely removes empty leftover directories.
Changes:
- Adds Bash and PowerShell locking.
- Updates cleanup ownership checks.
- Expands tests and prerequisite documentation.
| File | Summary |
|---|---|
tests/test_bootstrap.py |
Tests locking, cleanup, ownership, and cross-loader behavior. |
host-setup/README.md |
Documents locking and prerequisites. |
host-setup/linux/README.md |
Documents the flock dependency. |
host-setup/bootstrap.sh |
Implements locking and empty-directory checks. |
host-setup/bootstrap.ps1 |
Implements equivalent PowerShell behavior. |
docs/host-setup.md |
Updates host setup requirements. |
🧠 Review effort: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Summary
Two bootstrap runs sharing a
--dirused the same fixed tree names with nothing locking them, and a removal that failed on a tree's final directory left a leftover every later run refused. This change locks the directory for the length of a run and treats that leftover as removable, in both loaders, to the design settled on #1792 and #1795 for thewindowsandwsllanes together.$DIR/<tree>.lockfor its whole length.bootstrap.shtakesflock -non it, andbootstrap.ps1opens it withFileShare.None, which .NET implements as aflockon Linux, so the two loaders exclude each other there.bootstrap.shsets its exit trap, and before thetrywhosefinallyrunsbootstrap.ps1's cleanup. A refused run therefore never reaches the cleanup that would delete the holder's trees.run_toolcloses the lock's descriptor for each tool, so a daemon a tool starts cannot inherit it.bootstrap.shnow checks forflockbesidecurlandtar, and the docs name it.flockand checks pwsh's lock refuses, on Linux. A platform-independent class asserts eachmaintakes the lock before its cleanup is armed.Closes #1792 and #1795 once promoted.
Verification
python3 -m unittest tests.test_bootstrapruns 72 tests, OK, 29 skipped (the Linux-only cases).TestKeptTreeHandlingandTestDirectoryLockOrderpass. WSL's git cannot read a Windows worktree's.gitpointer, soTestScriptPresencefails there on that alone.mcr.microsoft.com/powershellcontainer in both directions. While pwsh holdsFileShare.None,flock -nexits 1. Whileflockholds the file, pwsh's open throwsIOException. Each succeeds once the other releases. Linux CI runs the cross-loader test.tryorder, the unlistable-directory guard, bash'sflock -n, the descriptor close, the bash empty and unlistable checks, and the bash lock and trap order.ruff,mypy,pyright, shellcheck, shfmt, PSScriptAnalyzer and markdownlint are clean. The prose gate is clean with thecommentslabel, which this PR carries for the new loader comments.local-strict-review, three rounds:IOExceptionwas claimed to mean contention only. Both are fixed in efa90ec.🤖 Generated with Claude Code