Repository navigation
Fix race in concurrent uv bootstrap on hosts without uv on PATH - #139
Merged
Merged
Conversation
On a host with no uv on PATH, every task ran 'pip install uv' into the
same (user site) location. pip installs aren't concurrency-safe, so
concurrent tasks could observe -- and try to execute -- a half-written
uv binary ('Permission denied').
Bootstrap now installs with 'pip install --target' into a unique temp
dir (hostname + pid) and renames it into place under
GROUNDHOG_CACHE_BASE, publishing only a working install; the loser of
a publish race discards its copy and uses the winner's. The bootstrap
dir is suffixed with 'uname -m' so installs sharing a filesystem
across architectures don't collide, and once published, later tasks
skip pip entirely (previously every task re-ran it). The
uv.find_uv_bin() discovery is kept as a fallback.
The GROUNDHOG_CACHE_BASE block moves above uv resolution since the
bootstrap dir lives under it.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
…stale installs - Validate uv by running it (--version) instead of trusting command -v / mode bits at every stage: PATH fast path (a concurrently pip-installed uv can be half-written), reuse gate, publish gate, and final selection. - Repair a stale $UV_BOOT (scratch purges delete bin/uv but leave the dir): clear broken leftovers before publishing instead of letting the [ -d ] guard discard every good rebuild forever. - Salt the bootstrap dir with the groundhog version (uv-bootstrap-<arch>-<version>) so upgrades re-bootstrap a fresh uv; moved the GROUNDHOG_VERSION assignment above the uv resolution block. - Avoid temp-dir collisions across PID namespaces by appending $RANDOM to UV_BOOT_TMP, and extend the EXIT trap to clean up UV_BOOT_TMP so a hard-killed bootstrap doesn't leak it. - Docs: note that the per-user uv bootstrap dir also lives under GROUNDHOG_CACHE_DIR. - Tests: cover version salt, --version validation at each gate, stale-dir repair ordering, trap coverage, and new tmp naming. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
OwenPriceSkelly
force-pushed
the
owen/fix-uv-bootstrap-race
branch
from
September 2, 2026 15:33
626a9fc to
222c454
Compare
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.
Problem
Spotted while verifying #138: on a host with no
uvon PATH, the shell command's bootstrap block runs$PYTHON -m pip install uvon every task, into the same shared location (the user site). pip installs aren't concurrency-safe, so concurrent tasks can observe — and try to execute — a half-writtenuvbinary. Observed as.../bin/uv: Permission deniedwhen 6 tasks bootstrapped at once. It's rarer in practice than the env-creation race (#138) because deployed endpoints usually have uv on PATH, but any uv-less host running concurrent tasks can hit it.Fix
Same publish-by-rename pattern as #138:
pip install --targetinto a unique temp dir ($UV_BOOT.tmp.$(hostname).$$), then atomically renames it to a persistent per-user dir underGROUNDHOG_CACHE_BASE(.../uv-bootstrap-$(uname -m); the arch suffix keeps installs from colliding when the cache base is shared across architectures). Only a working install (-x bin/uv) is published; the loser of a publish race discards its copy and uses the winner's.pip install uveven when it was already installed.uv.find_uv_bin()discovery is kept as a fallback (e.g. the uv PyPI package already installed some other way), andcommand -v uvshort-circuits everything exactly as before.GROUNDHOG_CACHE_BASEblock moves above uv resolution, since the bootstrap dir lives under it. No other reordering.Independent of #138 (different section of the template); both apply cleanly.
Verification
uv 0.12.8(previously this exact setup producedPermission denied), leaving exactly one publisheduv-bootstrap-arm64dir and no temp leftovers. A subsequent warm run reused it without invoking pip.🤖 Generated with Claude Code