Skip to content

installer: stop condemning a warm uv cache for a directory uv never writes - #10899

Merged
danielhanchen merged 7 commits into
mainfrom
uv-cache-probe-kinds
Sep 14, 2026
Merged

danielhanchen merged 7 commits into
mainfrom
uv-cache-probe-kinds

Conversation

@danielhanchen

@danielhanchen danielhanchen commented Sep 14, 2026 •

Copy link
Copy Markdown
Member

Follow-up to #10626. Two cases where the adaptive cache selection throws away a cache it should have kept. Both were reproduced against the merged head, both are fixed here, and both new tests fail on main and pass on this branch.

1. A bucket-shaped directory uv never writes condemned the whole cache

_uv_is_bucket_name and Test-StudioUvBucketName accepted any <kind>-v<N> name. The write probe then created and deleted a file in every one of them, and a single failure refused the cache.

That is right for archive-v0, which uv renames downloads into. It is wrong for a directory that merely looks like a bucket. A read-only unused-v999 sitting beside a perfectly good cache refused it, so the install fell back to the empty Studio cache and redownloaded Torch and CUDA it already had. Offline, it failed outright.

Both helpers now also require the KIND to be one uv creates. That list is every CacheBucket in uv 0.12.1, which is the version UV_PINNED_VERSION installs, read from crates/uv-cache/src/lib.rs at that tag:

archive binaries builds environments flat-index git interpreter osv python sdists simple wheels

plus built-wheels, from before it was folded into archive.

Getting this list from the uv on the machine rather than from the uv we pin was wrong, and it mattered: python-v0 and binaries-v0 have been there since uv 0.8.16, and python-v0 is the bucket the installer's own managed-CPython step fills. A kind missing from the list is a bucket that never gets probed, so a python-v0 left read-only by a privileged run would read as usable and the install would fail partway instead of falling back. The parity test now pins UV_PINNED_VERSION too, so bumping uv without re-reading its bucket list fails the test rather than silently leaving the new kind unprobed.

unsloth_cli/commands/studio.py already had a kind list, a narrower one, because it only answers whether a bucket holds package bytes. Its docstring claimed it mirrored the installers; that is now stated accurately instead.

2. tr -d '\r' deleted carriage returns from inside the path

The marker reader in install.sh stripped every CR in the file, not the trailing one. install.ps1 writes the marker with a BOM and CRLF under PowerShell 5.1 and a WSL install shares $STUDIO_HOME with the Windows one, which is what the strip is for, but a cache directory whose own name contains a CR came back as a path that does not exist. The marker then read as stale and the next run quietly chose somewhere else, so the same inputs gave two different answers on consecutive runs.

Now only a trailing CR is removed, which is what Read-StudioUvCacheMarker's Trim() on the PowerShell side already did.

Not changed

A populated but read-only archive-v0 still refuses the cache. That is a real uv bucket: uv aborts renaming a download into it, so refusing is correct for any install that has to download anything. It costs an offline install that already held every wheel it needed, which is the narrower case, and there is no way to tell the two apart before uv runs.

Verification

  • tests/sh/test_uv_cache_adaptive_selection.sh: 104 pass, 0 fail, over dash, bash and BusyBox ash with and without errexit. Against main's install.sh the same file gives 101 pass and exactly the 3 new failures.
  • tests/python/test_cross_platform_parity.py, test_windows_uv_cache_selection.py, test_windows_python_venv_hardening.py, unsloth_cli/tests/test_studio_update_uv_cache.py: 271 pass. The new Windows cases fail against main's install.ps1.
  • New parity assertion pulls the kind list out of both installers and compares the sets against uv's own, so the two cannot drift from each other or from the pin.
  • sh -n, bash -n, dash -n and busybox sh -n on install.sh; System.Management.Automation.Language.Parser.ParseFile on install.ps1; ast.parse on studio.py.
  • Name table checked to agree across dash, bash, BusyBox ash and PowerShell 7: archive-v0, built-wheels-v3, simple-v20, interpreter-v4 and python-v0 accepted; unused-v999, lost+found, archive-v0.backup, archive-v1-v, archive-v0-v1 and Archive-v0 rejected.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 14, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-09-14T05:28:13.717258Z 766e172 Manual request
🔒 Security Review ✅ Completed 2026-09-14T04:16:49.404632Z 26a73a9 Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

danielhanchen added a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Sep 14, 2026
chatgpt-codex-connector[bot]

This comment was marked as resolved.

danielhanchen added a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Sep 14, 2026
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex security review

@chatgpt-codex-connector

Copy link
Copy Markdown

🛡️ Codex Security Review

Security review completed. No security issues were found in this pull request.

Reviewed commit: 26a73a9a38

View security finding report

Only the user who started this review can view the report in Codex.

ℹ️ About Codex security reviews in GitHub

This is an experimental Codex feature. Security reviews are triggered when:

  • You comment "@codex security review"
  • A regular code review gets triggered (for example, "@codex review" or when a PR is opened), and you’re opted in so security review runs alongside code review

Once complete, Codex will leave suggestions, or a comment if no findings are found.

chatgpt-codex-connector[bot]

This comment was marked as resolved.

danielhanchen added a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Sep 14, 2026
chatgpt-codex-connector[bot]

This comment was marked as resolved.

danielhanchen added a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Sep 14, 2026
chatgpt-codex-connector[bot]

This comment was marked as resolved.

chatgpt-codex-connector[bot]

This comment was marked as resolved.

danielhanchen added a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Sep 14, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 14, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 14, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 14, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 14, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 14, 2026
danielhanchen added a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Sep 14, 2026
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. What shall we delve into next?

Reviewed commit: 766e1723f6

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@danielhanchen
danielhanchen merged commit a94ef51 into main Sep 14, 2026
72 of 77 checks passed
@danielhanchen
danielhanchen deleted the uv-cache-probe-kinds branch September 14, 2026 05:43
danielhanchen added a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Sep 14, 2026
unslothai#10899 landed the same core fix on main (_UV_CACHE_DIR_INSTALLER_DEFAULT, so a caller's
UV_CACHE_DIR and the installer's own default stop reading alike), with a probe that goes
further than this branch's: a bucket-kind allowlist, case folding, dangling symlinks and
UV_NO_CACHE. Conflicts in install.sh, install.ps1 and their suites are resolved in favour
of main, and this branch drops its duplicate probe entirely.

Two gaps remain, and are all that is left here:

studio/setup.sh never reads the marker install.sh writes. Run standalone, it defaults to
$STUDIO_HOME/cache/uv, which is the empty one after a shared-mode install, so the update
refetches every wheel. It now reads the marker on the CLI's terms: a caller's UV_CACHE_DIR
wins, UV_NO_CACHE leaves it unset, the marker wins only while its cache holds packages and
uv can still write to it. setup.sh never writes the marker.

_with_studio_uv_cache picked a cache without probing it. setup.sh treats the value it is
handed as the caller's choice and skips its own probe, so a share remounted read-only
since the install aborted every uv command in the update.

The shell and Python probes call the same directories uv's, by install.ps1's and
install.sh's kind list rather than a bare glob, so the four implementations agree.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant