Skip to content

installer: the adaptive uv cache selection was unreachable on every writable install - #10626

Merged
danielhanchen merged 41 commits into
mainfrom
uv-cache-adaptive
Sep 14, 2026
Merged

danielhanchen merged 41 commits into
mainfrom
uv-cache-adaptive

Conversation

@danielhanchen

@danielhanchen danielhanchen commented Sep 9, 2026 •

Copy link
Copy Markdown
Member

install.sh has two halves that are each correct to read and wrong in the order they run. The
result is that the adaptive uv cache selection has never executed on a writable install.

What happens

The block below # Keep uv's cache on the same filesystem as the venv it fills exports
UV_CACHE_DIR="$STUDIO_HOME/cache/uv" whenever the caller left it unset. It has to run where it
does rather than later: uv aborts on a cache it cannot create, and several install steps come
before _configure_uv_cache.

_configure_uv_cache runs much further down. Its first case matched any non-blank
${UV_CACHE_DIR-}, set _UV_CACHE_MODE=custom and returned. It cannot tell a caller's choice
from the installer's own default, because from inside the variable the two are the same string.

So on every writable install the pair took the custom branch, and four things followed:

  1. the env -u UV_CACHE_DIR uv cache dir probe never ran;
  2. shared was never selected, so a machine with a populated uv cache re-downloaded
    multi-gigabyte Torch and CUDA wheels into a second one -- the exact duplication the shared
    path was written to avoid;
  3. _prepare_studio_uv_cache_for_launch opens [ "${_UV_CACHE_MODE:-}" = shared ] || return 0,
    so it was dead code for the same reason;
  4. --isolated-uv-cache never reached its own branch either. The directory it produced was
    right by coincidence -- custom and isolated both leave $STUDIO_HOME/cache/uv -- but the
    mode was wrong, so the "already-cached packages may download again" warning the flag exists
    to print was never printed. That one was not in the original report; the test found it.

Why this is by execution order, not by diff

Nothing in either half is wrong to read, which is why it survived review of both. The proof is
the order:

line what runs
~1001, in _unsloth_main if [ -z "${UV_CACHE_DIR:-}" ]; then UV_CACHE_DIR="$STUDIO_HOME/cache/uv"; export UV_CACHE_DIR
~2934, in _unsloth_main _configure_uv_cache
inside it case "${UV_CACHE_DIR-}" in *[![:space:]]*) _UV_CACHE_MODE=custom; return 0

Both live in _unsloth_main's own body -- the installer runs inside one function so a piped
sh reads the whole file before executing any of it -- and neither is nested inside another
function, so the order above is the order they run. The early block only leaves UV_CACHE_DIR
unset when the directory cannot be created or written.

The fix

_UV_CACHE_DIR_INSTALLER_DEFAULT, set true only where the installer assigns its own default and
cleared again on the unwritable-cache fallback. _configure_uv_cache takes the custom branch
only when the flag is not set, so a caller's UV_CACHE_DIR keeps its priority and the
installer's own default falls through to the selection it was always meant to reach.

What waking the selection up then exposed

The selection had never run in production, so everything downstream of it was untested by
construction. The rest of the branch is what running it turned up, in the order it turned up.

A cache we can read is not a cache we can use. uv writes CACHEDIR.TAG into the root and
renames distributions into the buckets, aborting on either, and an ACL answers a different
question than a real create does. So the selection creates and deletes a mktemp file in the
root and in every bucket, and a populated cache that refuses it loses to the Studio cache with a
warning rather than failing the install two minutes later. Only where a bucket should be: uv
names those <kind>-v<N>, and a cache-dir pointed at a mount point has a root-owned
lost+found that must not condemn it.

archive-* is not the bucket rule. It also matches archive-v0.backup and
archive-backup-v0, whose bytes uv cannot reuse, so a cache that is empty in practice read as
warm and won. Warmth now requires the whole -v suffix to be numeric and the kind to be one
uv fills; the write probe deliberately keeps the looser shape, because under-detecting a future
bucket kind costs a fallback while under-probing one lets an unwritable cache through. The
version also cannot be empty: ##*-v strips through the last -v, so archive-v1-v left
nothing behind for *[!0-9]* to match and read as a bucket, and one read-only directory a user
named that way condemned a warm cache. Test-StudioUvBucketName had rejected it from the start,
so that one was an sh/ps1 split as well.

UV_NO_CACHE stands the selection down, and stands the RECORDING down too. The custom and
isolated branches choose a directory without probing, and both returned before this check, so
they recorded a marker naming a cache uv never touched: checked against uv 0.10.7, a caller's
UV_CACHE_DIR is left completely empty under UV_NO_CACHE=1, CACHEDIR.TAG included. Each
branch keeps its own directory; only the marker write is skipped. uv neither reads nor writes a cache under it, so
there is nothing to select: probing touches a cache the caller told uv to leave alone, and a
marker written there names one this install never filled. The literals are clap's, which is what
uv binds the variable to -- y and t were missing from all three copies of this rule.

A rerun keeps the cache it recorded. Otherwise a repair abandoned a Studio cache holding
Torch and CUDA the moment one unrelated wheel made uv's default read as warm, re-downloading
gigabytes to "avoid duplicate downloads". Content cannot decide it, because the launch repoint
leaves backend bytes in the losing cache; that is what the marker is for, and it is the
precedence unsloth studio update already used.

An install from before the marker has no marker, and abandoning its warm
$STUDIO_HOME/cache/uv costs the Torch and CUDA downloads again. So it is a candidate when
there is no marker, or when the marker names a directory that is gone, which is a stale pointer
rather than a decision. It is the LAST candidate, behind uv's default, and the history is why:
the marker arrived in b66d2a4c8 on 2026-09-06 and the early UV_CACHE_DIR block only in
e12963071 the day after, so an install with no marker is old enough that shared was
reachable, and there the launch repoint leaves backend wheels in the Studio cache while the real
bytes sit in the default. Ahead of the default it picked those leftovers. Behind it, a warm
Studio cache still wins whenever the default is cold, which is the install this is for.

A delete that fails is not the same as a probe that is still there. An indexer or a
scanner holding the handle open makes one delete fail and the next succeed, and PowerShell's
Remove-Item -ErrorAction Stop throws outright for a probe something else already removed,
where rm -f exits 0. Condemning the cache on the first failure could divert an install away
from the Studio cache into a shared one already known to be worse, which offline is an install
that used to succeed and then failed. Both sides retry and judge by whether the probe is gone.

A marker naming a directory that is no longer there is stale, not a decision. Treating it
as one suppressed the Studio cache, so a warm one holding Torch and CUDA lost to uv's default --
the abandonment the marker exists to prevent. A recorded cache that still exists and is merely
cold does still fall through to shared, which is the machine that really has moved on.

Creating a probe is not writing to a cache. uv renames distributions into these
directories, so a root that grants create and denies unlink fails the install later rather than
not at all, and leaks the probe into the user's cache. NTFS carries DELETE as its own ACE and an
append-only directory does the same on ext4. The bucket probes had already decided this; the
three root probes disagreed with their own sibling by way of || true and SilentlyContinue,
and now agree.

The root can be writable while the cache is not. A sudo run leaves a root-owned bucket
and a dangling link is an existing path to mkdir(2), so a root-only probe passes a cache uv
aborts on. That question decides three things, and two of them asked only about the root: the
fallback took the Studio cache unconditionally when nothing was warm, since a cold cache never
reaches the warn path, and the launch repoint sent the backend into a cache the candidate probe
had already rejected. One helper per installer now answers for all three.

The launch repoint could point at a dead cache. shared is reachable only when the early
block failed its own write probe on $STUDIO_HOME/cache/uv and unset UV_CACHE_DIR, which is
what lets the selection run at all. Repointing there unconditionally handed the autostarted
backend a cache uv aborts on, after an install that succeeded. It probes first now and keeps the
shared cache otherwise: that is the cache this install actually filled.

Plus the smaller ones the same runs produced: find dying on SIGPIPE under pipefail cleared
a warm verdict; a caller's set -f made the scan's own globs read every cache as empty; a
dangling bucket link is an existing path to mkdir(2), which answers EEXIST; a trailing
separator compared unequal to the same directory written without one, so a marker carrying one
was announced as shared and got the repoint the studio branch exists to avoid; and the sh
marker read was the only one of the three that tolerated neither a BOM nor a CR, which is what
install.ps1 writes under PowerShell 5.1 and what a WSL install sharing $STUDIO_HOME reads.

And unsloth studio update has to agree with the installer about the same machine.
unsloth_cli/commands/studio.py is what an existing installation actually runs, and it matched
bucket names by prefix, so archive-v0.backup counted as warmth. That is fixed. Its candidate
ORDER was already right, and the installers now match it rather than the other way round:
selection for an update is identical to main across every marker state a released install
reaches.

Windows

install.ps1 sets UV_CACHE_DIR in one place, inside the selector, so it never had the
ordering defect and its adaptive selection has always run. What it did not have is any of the
above. Measured by running its own selector: a rerun abandoned a warm Studio cache, UV_NO_CACHE
still probed and recorded, archive-v0.backup counted as warmth, and a populated-but-unwritable
cache was selected -- that last one fails the install outright. Two of those are the same bugs
this branch fixes on POSIX, and unsloth_cli/commands/studio.py already behaved the new way on
Windows, so install.ps1 was the odd one out on its own platform. It now carries the same rules,
plus two of its own: under $ErrorActionPreference = "Stop" a Test-Path inside an ACL-denied
directory throws, and the throw reached the candidate loop's catch, so an unreachable marker took
uv's default down with it; and $scanBlocked was shared across candidates, so the warning named
the wrong cache and suppressed the one that named the right one.

What this changes for people who already have it installed

This is not a no-op, and it is worth being exact about that rather than calling it hardening.
The whole point of the fix is that a code path which has never run on Linux or macOS now runs,
so the installer's behaviour there changes by design. Measured by executing both installers
against real fixtures under dash, bash, busybox ash and pwsh:

situation before after
Linux/macOS install, ~/.cache/uv cold or absent Studio cache Studio cache, unchanged
Linux/macOS install, ~/.cache/uv warm Studio cache (a second copy of Torch/CUDA) the warm cache is reused, and the launch repoints the backend at the Studio cache
any install, UV_CACHE_DIR set by the caller the caller's cache the caller's cache, unchanged
--isolated-uv-cache Studio cache, wrong mode, no warning Studio cache, right mode, and the warning the flag exists to print
rerun or repair with a warm cache recorded by the last install could switch away from it keeps it
an install older than the marker, with a warm Studio cache Studio cache Studio cache, kept deliberately rather than by accident
UV_NO_CACHE set probed and recorded a cache uv was not using stands down, records nothing

The first row is the ordinary case and is unchanged. The second is the fix. Nothing here moves,
renames or deletes an existing venv, cache, shortcut, desktop entry, credential file or marker,
and no other part of either installer changes: an AST-level comparison of every function body and
every top-level statement in both installers, before and after, reports exactly the uv-cache
functions plus the WSL reroute's cache-forwarding block, with no function removed. PATH, the
profile lines, the shims, the desktop entry, the uninstaller and the venv are all untouched, and
scripts/uninstall.sh / scripts/uninstall.ps1 never read the marker or UV_CACHE_DIR, so a
shared-mode install cannot lead an uninstall to delete a user's own uv cache.

Selection is idempotent: every mode was run three times over the same $STUDIO_HOME under each
shell, and run 2 and run 3 produce the same mode, the same directory and the same marker bytes as
run 1, with nothing oscillating.

Known trade-offs

Recorded here rather than argued in a thread, so a reviewer can overrule them.

UV_NO_CACHE with a caller's UV_CACHE_DIR records nothing. The install filled no cache, so
the marker, which means "the cache this install filled", would name one uv never touched. The
cost is that a later update with both variables unset has no pointer to that cache. It is
recoverable by setting UV_CACHE_DIR again, which _with_studio_uv_cache honours on its first
line, and the alternative misdirects every later repair.

The write probe covers any <kind>-v<N> directory, not only kinds uv currently uses. A
read-only future-v9 therefore refuses a cache uv would have been happy with. Under-probing is
worse: uv adds bucket kinds between versions, and letting an unwritable one through fails the
install. A cache that is warm and only failed this probe is still preferred over a cold one.

Marker parsing differs between the three readers on trailing whitespace. POSIX allows a
trailing space in a path and Win32 strips it, so sh and the CLI preserve it while PowerShell
trims. This predates the branch and no writer produces such a marker.

Cross-platform

Run on real runners, not only here: Linux x64, Linux ARM64, Apple Silicon macOS 15 and 26 (the
only hardware MLX runs on), Intel macOS 15, and Windows x64. The Windows ARM64 leg fails to
install sqlite-vec==0.1.9, which has no ARM64 Windows wheel, before it reaches any test. The
POSIX suites also run under every /bin/sh this repo can meet -- dash, bash and busybox ash --
with errexit on and off, because install.sh is #!/bin/sh with set -e on line 5.

Nothing in the diff touches the Studio web UI, so there are no screenshots to attach: the only
user-visible output that changes is the installer's own uv cache step line, and every spelling
of it is listed above.

Test

tests/sh/test_uv_cache_adaptive_selection.sh lifts both halves out of install.sh and runs
them in the order the installer runs them, which is the only arrangement in which the original
defect is visible. It is anchored on text that predates the fix, so it exercises the old code
rather than failing to find it -- an earlier draft anchored on a comment the fix introduces and
"failed" by not extracting anything, which proves nothing. It also runs under every /bin/sh on
the box with errexit both ways: install.sh is #!/bin/sh with set -e on line 5, and an
earlier version of this suite ran one shell without it.

tests/python/test_windows_uv_cache_selection.py is the Windows half, and it asserts behaviour
the same way, by running install.ps1's real selector under pwsh rather than by matching text.
It runs on Linux and macOS CI too, so the Windows path is exercised everywhere pwsh is.

test_uv_cache_adaptive_selection.sh   101 pass    against main            27/101
test_windows_uv_cache_selection.py     53 pass    against install.ps1 as it was  24/53

And the surrounding suites, on this branch: all 64 files under tests/sh,
test_install_uv_cache_root.sh 99/99, test_uv_cache_colocation.sh, test_uv_pinned_release.sh,
test_strixhalo_wsl_reroute.sh, test_cross_platform_parity.py 83/83,
test_windows_python_venv_hardening.py 51/51, test_studio_update_uv_cache.py 80/80,
test_uv_cache_discipline.py and test_ci_shell_suite_coverage.py. sh -n, bash -n and the
PowerShell parser clean. The shell suite is discovered automatically by Backend CI, so no
workflow list needs updating.

The one file here that is not about uv

.github/scripts/Watch-ForCompiler.ps1. The no-compiler lane failed on this branch naming one
compiler process, and the record it named is timestamped 17:51:57.107 while the step it was
scored against did not print its first line until 17:51:58.58. Nothing in install.ps1 can
have spawned it; it belongs to the positive control one step earlier, which compiles a type on
purpose. That is the case $prior exists to subtract, and it did not, because the Security log
is written asynchronously and a record 1.5 seconds old can be absent when $prior samples it
and present by the time the measurement reads back. The record's own TimeCreated is below the
floor either way, so the query now asks for a second more than the window at each end and cuts
the result back by TimeCreated. It narrows what can be counted; nothing a compile inside the
window does stops being counted, and the padded far end also removes the opposite risk of a
bound that rounds the wrong way dropping a real compile in the window's last fraction of a
second. Pinned by a test.

About the green test someone will point at

tests/studio/test_uv_cache_discipline.py passes, 10/10, before and after this change, and it
does not contradict any of the above. It covers the CI cache action under .github/ -- a
different occurrence of the same variable name and a different concern. It says nothing about
installer-side selection.

Provenance

Found by review on #10323 and first raised there, then against #10280. Both are
wrong addresses and neither can fix it: #10323 does not touch install.sh at all, and #10280's
only change to it is a 142-line append that touches neither hunk. The code is main's, so the
fix belongs here rather than riding in on a stacked serving PR.

…ritable install

Two halves of `install.sh`, each correct to read, wrong in the order they run.

The block below `# Keep uv's cache on the same filesystem as the venv it fills` exports
`UV_CACHE_DIR="$STUDIO_HOME/cache/uv"` whenever the caller left it unset. It has to run there
and not later: uv aborts on a cache it cannot create, and several install steps come before
`_configure_uv_cache`.

`_configure_uv_cache` runs much further down, and its first `case` matched any non-blank
`${UV_CACHE_DIR-}`, set `_UV_CACHE_MODE=custom` and returned. It cannot tell a caller's choice
from the installer's own default, because from inside the variable they are the same string.

So on every writable install the two together took the `custom` branch:

* the `env -u UV_CACHE_DIR uv cache dir` probe never ran;
* `shared` was never selected, so a machine with a populated uv cache re-downloaded
  multi-gigabyte Torch and CUDA wheels into a second one;
* `_prepare_studio_uv_cache_for_launch`, which opens
  `[ "${_UV_CACHE_MODE:-}" = shared ] || return 0`, was dead code;
* and `--isolated-uv-cache` never reached its own branch either. The directory it produced was
  right by coincidence -- `custom` and `isolated` both leave `$STUDIO_HOME/cache/uv` -- but the
  mode was wrong, so the "already-cached packages may download again" warning the flag exists to
  print was never printed.

Fixed by recording whether the value is ours: `_UV_CACHE_DIR_INSTALLER_DEFAULT`, set true only
where the installer assigns the default and cleared again on the unwritable-cache fallback. A
caller's `UV_CACHE_DIR` keeps its priority; the installer's own default falls through to the
selection it was always meant to reach.

`tests/sh/test_uv_cache_adaptive_selection.sh` runs the two halves in the order the installer
runs them, which is the only way this is visible -- neither half is wrong on its own. Anchored
on text that predates the fix, so it exercises the old code rather than failing to find it:
against unmodified main it reports 5 failures, and 13/13 with the fix.

Nothing else moved. `test_uv_cache_colocation.sh` 17/17, `test_install_uv_cache_root.sh` all
passed, `test_uv_pinned_release.sh` 72/72, `test_uv_cache_discipline.py` and
`test_ci_shell_suite_coverage.py` 39/39. `sh -n` and `bash -n` clean.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 9, 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-14T03:34:44.254958Z 81c54b5 Manual request
🔒 Security Review ✅ Completed 2026-09-10T02:13:20.972477Z 1375678 New commits
ℹ️ 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.

chatgpt-codex-connector[bot]

This comment was marked as resolved.

@danielhanchen

Copy link
Copy Markdown
Member Author

Confirmed against main: the top-level export at install.sh:790 makes the custom case in _configure_uv_cache always match, so shared mode and _prepare_studio_uv_cache_for_launch never run on a writable install. Will get this reviewed.

chatgpt-codex-connector[bot]

This comment was marked as resolved.

chatgpt-codex-connector[bot]

This comment was marked as resolved.

chatgpt-codex-connector[bot]

This comment was marked as resolved.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: fa9d2e958d

ℹ️ 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".

Comment thread install.sh
Comment on lines +780 to +783
_uv_artifact=$(find -L "$_uv_bucket" -type f \
! -name CACHEDIR.TAG ! -name .git ! -name .gitignore \
! -name '*.lock' ! -name '*.msgpack' ! -name '*.http' ! -name '*.rev' \
-print 2>/dev/null | head -n 1) || true

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Treat inaccessible nested cache entries as unusable

When an artifact bucket itself is writable but one nested cache entry (for example archive-v0/<hash>) is inaccessible, find suppresses that traversal error and another readable artifact can still mark the cache populated while _uv_default_writable remains true. If the install needs the inaccessible entry, uv pip install then fails while reading that directory; detect traversal errors or otherwise validate nested entries before selecting the shared cache.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not taking this one. Validating nested entries means walking a warm cache of hundreds of thousands of files on every install, and it would reverse a contract this repo already pins: tests/sh/test_install_uv_cache_root.sh:241, 'unreadable leaf keeps a warm cache warm', builds a denied archive-v0/ beside a readable one and asserts the cache stays shared. find's 2>/dev/null is there for the same reason. The line is at the directories uv itself creates and renames into, which is what the probe now covers: the root and every existing bucket. A denied entry deeper than that is a cache another account partially owns, and the fallback for it is --isolated-uv-cache.

Comment thread install.sh
# In place, before anything reads it: every branch records, so this is the one point
# every phase of the install and the marker are made to agree on one directory.
_absolutize_uv_cache_dir
UV_CACHE_DIR=$(_absolutize_uv_cache_dir)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Preserve trailing newlines in custom cache paths

When a caller's UV_CACHE_DIR names a legal POSIX path ending in a newline, this command substitution strips that newline from the helper's output, so the installer silently redirects uv to a different sibling path and records that altered value. The previous in-place absolute-path branch left such custom paths untouched; avoid command substitution for this normalization or otherwise preserve trailing newline characters.

Useful? React with 👍 / 👎.

@oobabooga oobabooga Sep 9, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not taking this one. A UV_CACHE_DIR ending in a newline was never carried through an install: _record_uv_cache_choice writes the marker with printf '%s\n' and install.sh:656 reads it back with $(cat ...), which strips trailing newlines, so the update would already resolve a different path than the install used. Preserving it in this one assignment would not make such a path work, only make the two disagree in a new place. Confirmed by writing and re-reading a marker for a path ending in a newline: it comes back without it.

@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 9, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 9, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 9, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 9, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 9, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 9, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 9, 2026
chatgpt-codex-connector[bot]

This comment was marked as resolved.

chatgpt-codex-connector[bot]

This comment was marked as resolved.

chatgpt-codex-connector[bot]

This comment was marked as resolved.

The custom and isolated branches both choose a directory without probing, and
both returned before the UV_NO_CACHE check, so they recorded a marker naming a
cache uv never touched. Checked against uv 0.10.7: with UV_NO_CACHE=1 a caller's
UV_CACHE_DIR is left completely empty, CACHEDIR.TAG included. A later repair
reads that marker and can prefer an unrelated cache that happens to hold bytes.

Both installers were the outliers here, the same way as the earlier fixes on
this branch: unsloth_cli/commands/studio.py has always asked
_uv_no_cache_requested() before choosing or recording anything.

The spelling test is now one helper per installer rather than a case and an
inline -in, so the three copies of clap's literal set cannot drift apart.
Each branch keeps its own directory: a caller's UV_CACHE_DIR is still exported
exactly as written, and isolation still points at the Studio cache. Only the
marker write is skipped, and the custom step line says so.

Tests cover both directions on both sides, since a guard that simply stopped
recording would also pass the first half. The new helper is added to every
extraction list; a name missing from one of those does not fail loudly.
chatgpt-codex-connector[bot]

This comment was marked as resolved.

…10626

The installers stopped abandoning a warm Studio cache on a pre-marker or stale
marker install, and stopped counting `archive-v0.backup` as warmth. The CLI is
what an existing installation actually runs on `unsloth studio update`, and it
had neither, so the update could undo the fix on the same machine.

_uv_cache_has_packages matched bucket names by prefix, which also takes
`archive-v0.backup` and `archive-backup-v0`, whose bytes uv cannot reuse. Its
docstring already claimed the same rule as install.sh. It now validates the
whole `<kind>-v<N>` suffix through a helper that mirrors both installers.

The precedence is POSIX-only, and the asymmetry is historical rather than a
shortcut. install.sh always took its `custom` branch before the marker shipped,
so shared mode was unreachable and nothing else wrote to $STUDIO_HOME/cache/uv:
verified by running the selector from b66d2a4~1. A warm unmarked Studio cache
there is this install's own. install.ps1's selection already worked, so a
pre-marker Windows install could have used the shared cache and repointed the
backend at the Studio one, leaving on-demand wheels there while Torch and CUDA
sit in the shared cache. Windows therefore keeps uv's default ahead of it, which
is what the test being retargeted here was protecting.

A marker naming a cache that still EXISTS and has gone cold stays a decision on
both platforms, so the machine that really moved on still reaches uv's default.
@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
chatgpt-codex-connector[bot]

This comment was marked as resolved.

…10626

Two sites asked _uv_cache_root_is_writable about a cache whose buckets the
candidate probe had already rejected, so both could hand back the cache uv is
about to abort on. A `sudo` run leaves a root-owned bucket and a dangling link
is an existing path to mkdir(2), so the root can be perfectly writable while the
cache is not.

The fallback chose the Studio cache unconditionally when nothing was warm, since
a cold cache never reaches the warn path. Reproduced: a Studio cache holding a
dangling archive-v0 and a cold default selected the Studio cache, and uv fails
on the first bucket it touches. It now falls through to the populated cache that
only failed the probe, then to uv's default when that is usable, which at worst
costs the downloads this cache was never going to save.

The launch repoint had the same root-only question. Reproduced: with a warm
default the selection correctly chose shared, then the repoint sent the
autostarted backend into the rejected Studio cache anyway.

The rule now lives in one helper per installer, _uv_cache_is_writable and
Test-StudioUvCacheUsable, and the candidate probe calls it too, so the three
sites cannot drift. Both new names went into every extraction list in the same
commit: a missing one is `command not found`, which reads as a clean answer.
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 🚀

Reviewed commit: 49ff714226

ℹ️ 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 added a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Sep 14, 2026
danielhanchen added a commit to shimmyshimmer/unsloth-staging-4 that referenced this pull request Sep 14, 2026
I had the history backwards. The marker arrived in b66d2a4 on 2026-09-06 and
the early UV_CACHE_DIR block only in e129630 the day AFTER, so an install old
enough to have no marker is old enough that `shared` was reachable on POSIX, not
too old. In that mode the launch repoint leaves a few on-demand backend wheels in
$STUDIO_HOME/cache/uv while Torch and CUDA sit in uv's default.

Ordering the unmarked Studio cache ahead of the default therefore picked the
leftovers: reproduced as a real offline install that succeeds on main and fails
on this branch. The earlier check that "confirmed" the opposite hardcoded the
early block into its own harness, so it proved nothing about that revision.

The unmarked Studio cache is now the LAST candidate in both installers, which is
the order unsloth_cli/commands/studio.py already used, so the platform split I
added there is gone with it. A warm Studio cache still wins whenever uv's default
is cold, which is the install the rule was added for, and `unsloth studio update`
is now byte-identical to main across all five marker states an install reaches.

Separately, the fallback treated a Studio cache that is WARM but failed the probe
as unusable and moved to a cold default, losing the bytes. A warm cache that only
failed a speculative bucket probe beats a cold one we can write; a cold Studio
cache with an unusable bucket still loses to uv's default, which is the case that
prompted the probe.
@danielhanchen

Copy link
Copy Markdown
Member Author

Correcting something I got wrong earlier in this PR, since it changed the design.

I claimed shared mode was unreachable on POSIX before the uv-cache marker shipped, and said I had verified it by running the selector from b66d2a4c8~1. That check hardcoded the early UV_CACHE_DIR block into its own harness, so it proved nothing about that revision.

The real history is the other way round:

  • b66d2a4c8 added the marker on 2026-09-06
  • e12963071 added the early top-level if [ -z "${UV_CACHE_DIR:-}" ] block on 2026-09-07, the day after

git log -S 'if [ -z "${UV_CACHE_DIR:-}" ]; then' -- install.sh names that commit, and at b66d2a4c8~1 the only match for that assignment is inside _prepare_studio_uv_cache_for_launch.

So an install old enough to have no marker is old enough that shared mode was reachable, not too old for it. In shared mode the launch repoint leaves a few on-demand backend wheels in $STUDIO_HOME/cache/uv while Torch and CUDA sit in uv's default, so ordering the unmarked Studio cache ahead of the default picks the leftovers. Reproduced as a real offline install, with the required package in the default and one unrelated package in Studio: succeeds on main, failed on this branch.

Fixed in 499d364:

  • the unmarked Studio cache is the LAST candidate in install.sh and install.ps1, which is the order unsloth_cli/commands/studio.py already used, so the POSIX/Windows split I had added to the CLI is removed with it
  • a warm Studio cache still wins whenever uv's default is cold, which is the install the rule was added for
  • the fallback no longer abandons a Studio cache that is warm but merely failed the speculative bucket probe in favour of a cold one; a cold Studio cache with an unusable bucket still loses to uv's default

unsloth studio update is now identical to main across all five marker states a v0.1.807-beta era install can reach: marker warm with a warm default, marker warm with a cold default, marker emptied, marker deleted, marker naming a deleted directory.

101 shell assertions under dash and bash with errexit both ways, 53 pwsh cases, 1463 Python tests.

@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

Copy link
Copy Markdown
Member Author

@codex review

str.isdigit() is true for Arabic-Indic and superscript digits, so the helper
added in c592585 counted `archive-v<Arabic-Indic one>` as a bucket where the sh
`*[!0-9]*` case and the PowerShell \A[0-9]+\z both reject it. uv writes ASCII, so
Python was the only one of the three that would have read such a directory as
warmth. Exotic, but it is a three-way rule and the other two already agreed.
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Another round soon, please!

Reviewed commit: 81c54b53bd

ℹ️ 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 added a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Sep 14, 2026
danielhanchen added a commit to shimmyshimmer/unsloth-staging-4 that referenced this pull request Sep 14, 2026
@danielhanchen
danielhanchen merged commit d728b5f into main Sep 14, 2026
62 of 66 checks passed
@danielhanchen
danielhanchen deleted the uv-cache-adaptive branch September 14, 2026 03:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants