Skip to content

Keep the regenerable caches inside the Studio root - #10597

Merged
danielhanchen merged 68 commits into
mainfrom
portable-runtime-caches-squashed
Sep 20, 2026
Merged

danielhanchen merged 68 commits into
mainfrom
portable-runtime-caches-squashed

Conversation

@danielhanchen

@danielhanchen danielhanchen commented Sep 9, 2026 •

Copy link
Copy Markdown
Member

Replaces #10188, which had grown to 34 commits. Same change, rebased onto current main as a single commit.

The squashed tree is byte-identical to what merging #10188 would have produced: git merge-tree of that branch against origin/main gives tree 875c65f9db1912e4d8e654fef50b3bce98842018, and so did this branch's first commit. The review history, including everything Codex raised and the replies, stays readable on #10188. Since then this branch has picked up a merge of current main and a comment-tightening pass.


Summary

Unsloth's own data already lives under one root, but the caches it creates along
the way do not. Torch inductor, Triton, matplotlib, numba and the CUDA JIT cache
all land in the home directory, and DataDesigner builds ~/.data-designer off
Path.home() at import time. This pins the regenerable, process-scoped ones in
every mode.

Part of #8865, which asks for an install contained in a single directory. This
half needs no new flags and helps default installs too. The installer flags
(--root, --portable) are in a follow-up PR; what this branch adds to
studio/setup.sh and studio/setup.ps1 is only the root derivation the runtime
resolvers below need to agree with.

What moves

Added to the defaults dict in _setup_cache_env, all under the existing
cache_root():

Variable Was
TORCHINDUCTOR_CACHE_DIR /tmp/torchinductor_<user>
TRITON_CACHE_DIR, TRITON_DUMP_DIR ~/.triton/cache, ~/.triton/dump
TORCH_EXTENSIONS_DIR ~/.cache/torch_extensions
CUDA_CACHE_PATH ~/.nv/ComputeCache
MPLCONFIGDIR ~/.config/matplotlib and ~/.cache/matplotlib
NUMBA_CACHE_DIR ~/.cache/numba
DATA_DESIGNER_HOME, DATA_DESIGNER_MANAGED_ASSETS_PATH ~/.data-designer

TRITON_HOME is deliberately not one of them. It is the single lever that would
move all three Triton directories at once, and the third is ~/.triton/override,
which holds hand-written kernels rather than a cache. Moving it would make a
TRITON_KERNEL_OVERRIDE=1 run silently compile something else. The two dedicated
variables outrank the TRITON_HOME derivation, so they move what is regenerable
and leave the overrides alone. A user who sets TRITON_HOME themselves gets no
pin at all.

TORCH_EXTENSIONS_DIR gets a py<ver>_<platform-arch>_<accelerator>_<version>
child rather than a flat path. torch.utils.cpp_extension inserts its own
py<ver>_<accelerator> folder into the default root only, never into one we
supply, so a flat pin would let a py313/cu128 build be loaded by a py312/cu126
process.

DATA_DESIGNER_HOME is read at import time by
data_designer.config.utils.constants, so it has to be set before the Data
Recipes worker imports the package. The workers are spawned, so they copy this
environment and need no change.

Each of these is skipped when the directory it would displace already holds user
files: a matplotlibrc or a stylelib/*.mplstyle, or a ~/.data-designer that
already exists. The probes go through os.lstat and os.scandir rather than
Path.exists/is_dir/glob, which report ENOTDIR, ELOOP and (from 3.14) EACCES
as absence, so a directory that merely cannot be inspected would have read as
empty and the redirect would have hidden the files under it.

diffusion_compile_cache.py also stops hardcoding
~/.cache/unsloth/diffusion_compile_cache. It resolves through cache_root()
per call now, and still reads a bundle from the old path when one is there, so
nobody pays a cold compile for the move alone. A bundle found there is copied
into the new root, so the fallback does not become permanent and the home
directory never becomes the write root.

UNSLOTH_HOME and UNSLOTH_PORTABLE

storage_roots.py grows two resolvers. unsloth_home() reads UNSLOTH_HOME,
the master root that STUDIO_HOME is the studio/ child of, and slots into
studio_root() below UNSLOTH_STUDIO_HOME/STUDIO_HOME and above the
sys.prefix inference. portable_mode() is implied by a master root and can
also be turned on by itself with UNSLOTH_PORTABLE.

llama.cpp, node and whisper.cpp are siblings of studio/ at the master
root, which is the layout studio/setup.sh and scripts/build_whisper_cpp.sh
already install into. node_runtime, stt_ggml_sidecar,
LlamaCppBackend._resolved_studio_root_and_is_legacy, run.py, main.py and
unsloth_cli/commands/studio.py all derive from the master root when there is
one, so discovery and the exported UNSLOTH_LLAMA_CPP_PATH name the same
directory. main.py and run.py also had to stop gating that export on
resolved != legacy alone: a master root pointed at the legacy path still owns
the runtimes beside it.

studio/setup.sh and studio/setup.ps1 install the runtimes at the same root.
They previously derived that parent from the Studio home alone, and the CLI
exports UNSLOTH_STUDIO_HOME=<root>/studio before running them, so with a master
root set they installed llama.cpp, node and whisper.cpp one level below
where the resolvers look and no GGUF model, managed Node or dictation engine
would be found. setup.sh now captures the environment value as _MASTER_ROOT
before section 7 assigns over the name, and setup.ps1 gets
Get-MasterRootOverride. scripts/build_whisper_cpp.sh had the same problem one
level down: it ranked UNSLOTH_STUDIO_HOME above the UNSLOTH_HOME setup.sh
passes it, so the source-build fallback installed under <root>/studio. All
three strip, expand ~, and resolve a relative value against the caller before
deciding, matching Path.resolve(), since Node is chosen before setup.sh's first
cd "$SCRIPT_DIR" and llama.cpp after it. An explicit
UNSLOTH_STUDIO_STAGE_ROOT still outranks the master root, and nothing changes
without UNSLOTH_HOME set.

The ownership guards follow them. _STUDIO_HOME_IS_CUSTOM is false when only
UNSLOTH_HOME is set, since STUDIO_HOME stays legacy, and false is what lets
install_llama_prebuilt.py os.replace() and the source build rm -rf without
checking the Unsloth-owned marker. setup.sh derives _RUNTIME_ROOT_IS_CUSTOM
and setup.ps1 $RuntimeRootIsCustom for exactly the guards that name a runtime
child; the Studio home and its venvs keep the original flag. install.ps1 holds
byte-identical copies of the shared llama.cpp helpers, so those moved too.

scripts/uninstall.sh and scripts/uninstall.ps1 learn the same root, or an
install would strand multi-gigabyte trees. Stricter than the ~/.unsloth
removals beside them: <master> is user-chosen, so llama.cpp, node,
whisper.cpp and stable-diffusion.cpp go only when they carry
.unsloth-studio-owned, an unmarked tree is reported and kept, the root passes
the deny list first, and it is itself removed only once the children leave it
empty.

On the desktop side, UNSLOTH_HOME and UNSLOTH_PORTABLE join
MANAGED_CHILD_SCRUBBED_ENV, so an inherited shell value cannot move the
packaged app's databases and caches, and install.rs now reads that list instead
of naming two variables of its own. Both also join the relative-path guard in
_system_dir_guard.py and its Rust twin, together with the new cache variables:
storage_roots.py fills those only when blank, so a relative value the user set
survives and would name a different folder after a move.

What deliberately does not move

The Hugging Face hub cache stays at ~/.cache/huggingface. It was taken out of
the Unsloth tree on purpose in #4591 so that models downloaded before Unsloth was
installed, or shared with LM Studio, Ollama and plain huggingface_hub, keep
being found instead of downloaded a second time. Redirecting it unconditionally
would undo that.

HF_HOME never moves in any mode. It owns the token path, and credentials should
not follow a cache onto a removable volume.

HF_HUB_CACHE, HF_XET_CACHE, HF_DATASETS_CACHE, HF_ASSETS_CACHE,
HF_MODULES_CACHE and TORCH_HOME move only under UNSLOTH_HOME /
UNSLOTH_PORTABLE, where the user has explicitly asked for one self-contained
directory. Xet is included because huggingface_hub derives it from HF_HOME
and never from HF_HUB_CACHE, so a hub-only redirect would leave the chunk and
shard caches on the host. Modules for the same reason: transformers.utils.hub
reads HF_MODULES_CACHE from <HF_HOME>/modules at import and appends it to
sys.path, so a trust_remote_code load would otherwise leave generated modules
on the host. A user who names their own HF_HOME keeps one Hugging Face cache:
only TORCH_HOME is pinned then, since the rest derive from the home they
chose.

Precedence

Unchanged. An explicit environment variable still wins, then the Settings
download location from #7274, then these defaults. The existing
blank-counts-as-unset guard is reused, so an inherited KEY= cannot pin a cache
to the empty string.

Tests

New studio/backend/tests/test_setup_cache_env_containment.py, 94 cases:
containment of the regenerable set, the "pin only when nothing is stranded" rule
for matplotlib and Data Designer including the inspection-failure paths, the
TORCH_EXTENSIONS_DIR tag, the default install leaving the shared HF cache
alone, portable-only variables staying unset by default, explicit env beating the
default, blank values, and DATA_DESIGNER_HOME being set before the library
would read it.

New tests/test_unsloth_home_root_agreement.py and
tests/test_managed_tools_master_root.py hold the CLI and the backend to the same
answer for a master root, and tests/test_studio_install_workspace_guard.py
holds the scrub list against the resolvers that read the environment, so a new
root variable cannot be honoured by the backend and missed by the desktop.
unsloth_cli/tests/test_export_cache_env.py covers the export /
list-checkpoints path that reaches the backend without
ensure_studio_backend_path(). tests/test_setup_master_root.py runs the
shipped setup.sh and build_whisper_cpp.sh derivations rather than
pattern-matching them, across master root, plain custom Studio home, legacy
default, staging root, and padded, blank, tilde and relative values, and holds
the ownership flag and both uninstallers; tests/sh/test_uninstall_master_root.sh
runs the real uninstall block against fixtures, including the cases where a tree
must be kept. The setup.ps1 and uninstall.ps1 halves that need a real
Windows filesystem are held structurally; where pwsh is on PATH, which it is on
the Linux runners, the PowerShell arms execute rather than skip.

Run here: 166 passing across test_setup_cache_env_containment.py,
test_setup_cache_env_hf_home.py, test_diffusion_compile_cache.py and
test_hf_cache_settings.py; 519 passing and 18 skipped across
test_managed_tools_master_root.py, test_unsloth_home_root_agreement.py,
test_studio_install_workspace_guard.py, test_installer_system32_guard.py,
test_setup_master_root.py, tests/studio/install/test_selection_logic.py and
unsloth_cli/tests/test_export_cache_env.py.

tests/test_studio_root_resilience.py passes standalone on both revisions, 6 on
the merge base and 7 here. An earlier version of this section claimed two
failures there caused by the file not putting studio/backend on sys.path;
that guard is present and identical on both, added by 7f6219e3a, an ancestor of
the merge base.

Fixes ~/unsloth_compiled_cache

unsloth train / inference / export import the backend in-process and never
seeded the cache environment, so they inherited unsloth-zoo's bare relative
UNSLOTH_COMPILE_LOCATION and resolved it against whatever directory the shell
was in. Running from the home directory left an ~/unsloth_compiled_cache that
cache_cleanup then refused to remove, because nothing marked it as ours.

Seeding from ensure_studio_backend_path() covers every command that reaches the
backend, without making unsloth --help pay for importing it. export and
list-checkpoints do not call it, so studio_backend_imports() seeds there too.
unsloth studio run was already fine; it execs run.py, which seeds this itself.


What this changes for an install that already exists

Verified by running the real resolver in both trees under env -i with synthetic homes, across
sixteen install shapes, and diffing every resolved path and every variable setup_cache_env
exports. In all ten non-portable shapes, which is every install anyone has today, no path moves
and no existing environment value changes:

  • default, fresh
  • a legacy ~/.unsloth/studio already on disk
  • UNSLOTH_STUDIO_HOME, and STUDIO_HOME
  • a user's own HF_HOME, HF_HUB_CACHE, UV_CACHE_DIR, TORCH_HOME, TRITON_CACHE_DIR
  • blank overrides, XDG_CACHE_HOME and XDG_DATA_HOME relocated
  • the on-disk shape a v0.1.701-beta desktop install leaves behind

studio_root, studio.db, the auth root and auth.db, assets, datasets, outputs, exports, the
projects root and the Documents root are identical on both sides in every one of them. Login,
shortcuts and the desktop self-update path are untouched: install.sh and
.github/workflows/release-desktop.yml are not in this diff at all.

What does change, and it is the point of the PR, is that the eight variables in the table above
are now set where they were previously unset. The cost is a one-time cold recompile; the old
caches stay on disk rather than being moved or deleted. unsloth train, inference and export
also seed the cache environment now, which is the fix for ~/unsloth_compiled_cache, so those
commands create the cache directories on first run where before they created none.

The Hugging Face model caches do not move by default. That was deliberate in #4591 and stays
that way; they move only under an explicit portable root.

Not pinned into a path that contains a space

torch/_inductor/cpp_builder.py joins its arguments with spaces, interpolates the output path
unquoted, and reparses the result with shlex.split, so a cache directory containing a space
splits mid-path and the C++ build fails outright:

g++: fatal error: input file .../my is the same as output file

Nothing here can fix that quoting, so the five variables a C++ or CUDA toolchain receives on a
command line are left unset when the resolved path has whitespace, and Inductor falls back to its
own whitespace-free temporary directory, which is what shipped before any of this was pinned.
The rest of the caches still move, and an explicit value from the caller is always honoured.

This is not an exotic path: the default Studio root hangs off the profile directory, and
C:\Users\First Last is an ordinary Windows account name.

Known limitation: UNSLOTH_HOME is not yet end to end

The resolvers, the CLI, both setup scripts and both uninstallers agree on the master root, and a
later launch now recovers it: unsloth_home() falls back to the share/.unsloth-master-root
note setup writes, so node, whisper.cpp and llama.cpp are still found beside studio/ once the
UNSLOTH_HOME=... unsloth studio update command's environment is gone. Before that, even a
correctly known studio root sent all three to its studio/ child, one level off from where the
installer had put them.

The outer installers still do not read the variable, so setting UNSLOTH_HOME on its own is not
a working flow end to end: install.sh places Studio at ~/.unsloth/studio while the CLI
resolves <master>/studio and reports that Studio is not set up, and given an explicit
UNSLOTH_STUDIO_HOME=<master>/studio the POSIX launcher writes
UNSLOTH_LLAMA_CPP_PATH=<master>/studio/llama.cpp while setup installs at <master>/llama.cpp.
That variable is explicit, so it outranks the note.

That half belongs to the follow-up PR that adds --root and --portable. Nothing here changes
behaviour for anyone who does not set the variable, and no installer sets it. The note is written
only for a master-root install, so a default tree acquires no root by accident.


What this changes on screen

Settings > System > Storage, the "Models folder" row. It is the only place a user ever sees
where downloaded models live, and it renders cache_home straight from
GET /api/settings/hugging-face-cache, so it is where this PR's effect on the Hugging Face
cache becomes visible.

Two isolated installs, merge base 5f00349e7 on the left and head ed04cb31a on the right,
photographed by one scene driven against both. UNSLOTH_PORTABLE=1 is set on BOTH sides, and
HF_HOME, HF_HUB_CACHE, HF_XET_CACHE and friends are cleared on both: the merge base has no
such variable, so it reads the platform default and the row is unchanged there, which is the
point. An explicit cache home is the one case where this PR deliberately declines to move
anything, so an inherited value would have made the right side correctly show no change.

Settings > System, before and after

The Models folder row, before and after

The input ellipsises a long path, so both halves render only its first ~34 characters and the
picture cannot carry the claim on its own. The full values, read from the same servers that were
photographed:

BEFORE (merge base) AFTER (head)
Models folder shown /mnt/disks/unslothai/daniel1/.cache/huggingface <studio home>/cache/huggingface
cache_home /mnt/disks/unslothai/daniel1/.cache/huggingface <studio home>/cache/huggingface
hub_cache .../.cache/huggingface/hub <studio home>/cache/huggingface/hub
xet_cache .../.cache/huggingface/xet <studio home>/cache/huggingface/xet
source default default
is_custom false false

source and is_custom do not move, which is the part worth checking: the cache is relocated by
the portable default, not by pretending the user set it. Everything else on the page, the disk
figures, the Environment table, the llama.cpp rows, is identical across the pair, which is what
makes it a pair rather than two pictures.

The pair was taken at ed04cb31a. The three review fixes pushed since then touch _usable_dir,
which gates only the six compile-cache variables in _TOOLCHAIN_PATH_KEYS, plus uninstall.sh
and setup.ps1. No Hugging Face variable passes through any of them, so this row has not moved.

Review pass

A simulation pass over this branch found four defects, each reproduced before
being fixed, and all four are now on it:

  • The master-root note was written in two shapes every reader refuses. Containment:
    setup.sh writes it at $STUDIO_HOME/share, and STUDIO_HOME never derives from
    UNSLOTH_HOME, so the documented UNSLOTH_HOME=/mnt/portable unsloth studio update
    on an ordinary install recorded a root all four readers then rejected. And the legacy
    default: UNSLOTH_HOME=$HOME/.unsloth is refused by both uninstallers but was honoured
    by storage_roots, so one command naming the directory the install was already in
    flipped portable_mode() on for every later bare launch and moved HF_HUB_CACHE off
    ~/.cache/huggingface. Neither is recorded now, an old note carrying the legacy root is
    cleared on the next run, and the stranded-runtime case prints what happened.
  • _stored_cache_home treated FileNotFoundError as proof the database is absent. POSIX
    raises NotADirectoryError for a parent that is a file; Windows collapses that into
    FileNotFoundError, so the cache home chosen in Settings was discarded on Windows and
    nowhere else. This branch's own
    test_uninspectable_studio_db_keeps_the_stored_cache_home[not_a_directory] was red on
    windows-latest and green everywhere else.
  • _recorded_master_root cached a note read that failed for a reason other than absence,
    so an EACCES on share/ pinned a long-lived backend to the legacy runtime paths for its
    whole lifetime. forget_recorded_master_root() has no callers in production.
  • _usable_dir left os.close unguarded, and the UNSLOTH_PORTABLE warning promised that
    an off value would leave portable mode off, which a master root overrides.

Differential across three operating systems, base against head, same sixteen files:
ubuntu-latest 0 real failures on both arms, macos-15 the same 5 on both, and
windows-latest 82 on both once the guard above is fixed. The three checks that were red
on the previous head were all failing on main in the same window and are unrelated to this
branch.

What this changes in the UI

Settings, System tab, Storage section, on two installs built from this branch's merge base
(04c9951b4) and its head (2b61d6059), both launched with UNSLOTH_HOME pointing at a master
root and with every ambient HF_* variable cleared:

Models folder, before and after

Models folder moves from the host cache to the install:

/api/settings/hugging-face-cache before after
cache_home <XDG_CACHE_HOME>/huggingface <install>/cache/huggingface
hub_cache <XDG_CACHE_HOME>/huggingface/hub <install>/cache/huggingface/hub
xet_cache <XDG_CACHE_HOME>/huggingface/xet <install>/cache/huggingface/xet
source default default

source staying default is the part worth checking: the relocation does not present itself as
an environment override, so the field stays editable and Settings can still move it. Without a
master root both sides are identical, which is the intended no-op for an ordinary install.

The screenshots were taken at 2b61d6059. They still describe the current head: the only two
files behind that panel, studio/backend/utils/hf_cache_settings.py and
studio/backend/utils/paths/storage_roots.py, are AST-identical between that commit and the
head (comments and docstrings only), and nothing else under studio/ changed in between.

Unsloth's own data already lives under one root, but the caches it creates
along the way do not. Torch inductor, Triton, matplotlib, numba and the CUDA
JIT cache all land in the home directory, and DataDesigner builds
~/.data-designer off Path.home() at import time. This pins the regenerable,
process-scoped ones in every mode.

Part of #8865, which asks for an install contained in a single directory. This
half needs no new flags and helps default installs too.

Added to the defaults dict in _setup_cache_env, all under the existing
cache_root(): TORCHINDUCTOR_CACHE_DIR (was /tmp/torchinductor_<user>),
TRITON_HOME and TRITON_CACHE_DIR (~/.triton), TORCH_EXTENSIONS_DIR
(~/.cache/torch_extensions), CUDA_CACHE_PATH (~/.nv/ComputeCache), MPLCONFIGDIR
(~/.config/matplotlib and ~/.cache/matplotlib), NUMBA_CACHE_DIR (~/.cache/numba),
and DATA_DESIGNER_HOME with DATA_DESIGNER_MANAGED_ASSETS_PATH (~/.data-designer).

DATA_DESIGNER_HOME is read at import time by data_designer's constants module,
so it has to be set before the Data Recipes worker imports the package. The
workers are spawned, so they copy this environment and need no change.

diffusion_compile_cache.py also stops hardcoding
~/.cache/unsloth/diffusion_compile_cache. It resolves through cache_root() per
call now, and still reads a bundle from the old path when one is there, so
nobody pays a cold compile for the move alone.

Fixes ~/unsloth_compiled_cache. unsloth train, inference and export import the
backend in-process and never seeded the cache environment, so they inherited
unsloth-zoo's bare relative UNSLOTH_COMPILE_LOCATION and resolved it against
whatever directory the shell was in. Running from the home directory left an
~/unsloth_compiled_cache that cache_cleanup then refused to remove, because
nothing marked it as ours. Seeding from ensure_studio_backend_path() covers
every command that reaches the backend, without making `unsloth --help` pay for
importing it.

What deliberately does not move: the Hugging Face hub cache stays at
~/.cache/huggingface. It was taken out of the Unsloth tree on purpose in #4591
so that models downloaded before Unsloth was installed, or shared with LM
Studio, Ollama and plain huggingface_hub, keep being found instead of
downloaded a second time. HF_HOME never moves in any mode either: it owns the
token path, and credentials should not follow a cache onto a removable volume.
@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-20T12:27:32.462492Z 76e04c5 Manual request
🔒 Security Review ✅ Completed 2026-09-18T15:24:05.729914Z ed04cb3 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.

@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

Copy link
Copy Markdown

Codex Review: Something went wrong. Try again later by commenting “@codex review”.

Provided git ref 9e5da37cf84ee3d60c8f9d961cb5510a034caa53 does not exist
ℹ️ 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".

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

This comment was marked as resolved.

@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.

@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.

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

Copy link
Copy Markdown

🛡️ Codex Security Review · Automatically triggered

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

Reviewed commit: 5821f0b64e

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.

chatgpt-codex-connector[bot]

This comment was marked as resolved.

Relaxing the note check to containment in storage_roots and both uninstallers left the CLI's
copy on the stricter <master>/studio match. UNSLOTH_HOME=/root with
UNSLOTH_STUDIO_HOME=/root/custom/studio is a real pairing: setup records /root, the Studio
directory is inside it, and it is not the default child. The backend accepts that note and the
CLI declined it, so a later `unsloth studio update` passed setup no master root at all and
refreshed the runtimes under the Studio directory while the backend went on loading the ones at
/root. That is the same split this recovery exists to close, reopened one level up.

Test: the CLI and the backend agree on a nested Studio root, in
tests/test_unsloth_home_root_agreement.py. It fails with the strict rule restored.
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Keep them coming!

Reviewed commit: 94be8b2875

ℹ️ 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 and others added 6 commits September 20, 2026 01:16
Two shapes of the note were being written and then refused by every reader, so
the feature recorded nothing while the file on disk said otherwise. Both were
found by running the shipped setup.sh block against a fixture and handing the
result to the real resolver, not by reading.

Containment. setup.sh writes the note at $STUDIO_HOME/share, and STUDIO_HOME is
derived only from UNSLOTH_STUDIO_HOME/STUDIO_HOME, never from UNSLOTH_HOME.
Every reader requires the Studio directory to lie inside the root the note
names. install.sh does not read UNSLOTH_HOME yet, so the documented case,
UNSLOTH_HOME=/mnt/portable unsloth studio update on an ordinary install, leaves
Studio at ~/.unsloth/studio and puts llama.cpp, node and whisper.cpp at
/mnt/portable, which is exactly the shape all four readers reject. The note is
now skipped there and the stranding is reported with the two ways out, instead
of being recorded in a file nobody reads.

The legacy default root. UNSLOTH_HOME=$HOME/.unsloth names the directory the
install is already in. Both uninstallers refuse that value outright, but
storage_roots honoured it, and honouring it made portable_mode() true on every
later bare launch: HF_HUB_CACHE moved off ~/.cache/huggingface, which is the one
cache this branch promises not to move, and every model already downloaded went
missing. One command that named the default root converted the install
permanently, with nothing set at the time. It is no longer recorded, and a note
an earlier build left carrying it is cleared on the next run, since the writer
only runs when UNSLOTH_HOME is set again and the user who hit this set it once.

Also in storage_roots:

- A note read that fails for a reason other than absence is no longer cached.
  _recorded_master_root memoises per studio path and the backend is long-lived,
  so an EACCES on share/ or an EIO off a mount that came back pinned that
  process to the legacy runtime paths for its whole lifetime, silently, with the
  trees it should have found beside it. Nothing in production calls
  forget_recorded_master_root. A genuine miss is still cached.

- _usable_dir guards os.close like it already guards the unlink. Every other
  failure there is a False; an OSError escaping took _setup_cache_env, and the
  backend start that called it, down with it.

- The UNSLOTH_PORTABLE warning no longer says 0/false/off/no will leave portable
  mode off. An off value is not a veto: a master root is what makes an install
  portable, as the comment three lines below already said.

Tests: five new cases over the gate, the legacy-root sweep, the cached-note
rule and the close guard, plus the setup.ps1 halves held structurally. 205 in
test_setup_cache_env_containment and the cache suites, 356 across the master
root, root agreement, workspace guard and system32 guard suites, 6710 in
tests/studio/install, and all five tests/sh scripts pass; tests/studio/install
matches the merge base exactly.
The skip added here reads os.stat(studio_db_path()) and treats FileNotFoundError
as "no database, nothing to read". On POSIX that is sound: a parent component
that is a file raises NotADirectoryError and one that cannot be traversed raises
PermissionError, each its own type. Windows collapses all of them into
ERROR_PATH_NOT_FOUND, which Python surfaces as FileNotFoundError, so there the
exception means "absent, OR something above it is not a directory, OR I could
not look" and the guard took the first reading. The result was the cache home
chosen in Settings being discarded on Windows and nowhere else.

This is the branch's own new test failing, not a theory:
test_uninspectable_studio_db_keeps_the_stored_cache_home[not_a_directory] is
green on Linux and macOS and red on windows-latest. Measured as a differential
on owned staging runners, base against head, same sixteen files, same three
operating systems: ubuntu-latest has no real failure on either arm, macos-15 has
the same five on both, and windows-latest has 82 on the base and 83 on the head.
The one extra is that test. Nothing else the branch touches moved on any of the
three.

_absence_is_real answers the question the skip actually needs: the nearest
ancestor that can be stat'ed decides. A directory means the tree is real and the
file genuinely is not in it. Anything else means a component is a file or a
reparse point, so the path could never have existed and the caller has learned
nothing. An ancestor that cannot be inspected at all is not proof either way.
Running out of ancestors means nothing on the path exists, which is the machine
that has never opened Studio, and the skip has to hold there or the read builds
the 250 KB database it was added to avoid. Checking only the immediate parent is
not enough: account_path puts studio.db several levels under the Studio home, so
the non-directory is usually further up.

Held by a test that reproduces the Windows error shape rather than the platform,
since the Linux runners cannot raise it, plus its opposite, an absent Studio
home that must still skip. The first fails on the code as it was and passes
after, so it measures the fix rather than restating it.

207 pass in the cache suites, 365 with 1 skipped across the master root, root
agreement, workspace guard and system32 guard suites, 6754 with 32 skipped in
tests/studio/install, 2 in the CLI export suite.
errno is used only inside _WINDOWS_SHAPED_GUARD_PROBE, which is a string run in
a subprocess and imports it itself. The hoisted import was unused at module
level and the source lint blocks on exactly that.
@danielhanchen

Copy link
Copy Markdown
Member Author

Simulated this branch end to end rather than reading it, on this Linux host and on owned staging runners for Windows and Apple Silicon macOS. Four defects, all reproduced first and then fixed on the branch. Three of them were invisible to the suites as written.

issue: REAL | PR as submitted: DEFECTIVE, 4 fixed here | merge: YES

Caches really did land in the home directory, and unsloth export really did write unsloth_compiled_cache/ into whatever directory you ran it from. The branch pins them correctly and does not touch the shared Hugging Face cache on a default install, which I checked by diffing the environment and the created directories between the merge base and this head. But the master-root note was being written in two shapes that every reader then refused, so the feature recorded nothing while the file on disk said otherwise, and one of those shapes silently converted an ordinary install to portable mode for good.

What moved

Behaviour Before this branch PR as submitted Now
UNSLOTH_HOME=/mnt/portable unsloth studio update on an ordinary install runtimes at ~/.unsloth/studio, nothing recorded runtimes at /mnt/portable, note written to ~/.unsloth/studio/share/, then unsloth_home() -> None on the next launch, uninstall.sh _master_root -> [] note skipped, and setup prints NOTE: the managed runtimes were installed under /mnt/portable, but Studio itself lives at ~/.unsloth/studio, which is outside it with the two ways out
UNSLOTH_HOME=$HOME/.unsloth once, then a bare environment forever after portable_mode: False, HF_HUB_CACHE = ~/.cache/huggingface/hub portable_mode: True, HF_HUB_CACHE = ~/.unsloth/studio/cache/huggingface/hub, plus xet, datasets, assets, modules and TORCH_HOME portable_mode: False, HF_HUB_CACHE = ~/.cache/huggingface/hub, and a note an earlier build left is cleared on the next run
A Studio home Windows cannot inspect, with a cache home chosen in Settings n/a the chosen home is discarded, on Windows and nowhere else the database is read, as it already was on Linux and macOS
_setup_cache_env on a mount that came back after an EACCES on share/ n/a None cached for the life of the process; forget_recorded_master_root() is the way out and has zero callers the miss is cached, the failure to look is not
unsloth export, clean $HOME, no new variables sets nothing, creates nothing 15 variables pinned, 21 directories created, no studio.db, nothing in the CWD unchanged, this one was right

The two the readers were refusing

setup.sh writes the note at $STUDIO_HOME/share, and STUDIO_HOME comes only from UNSLOTH_STUDIO_HOME/STUDIO_HOME, never from UNSLOTH_HOME. All four readers require the Studio directory to lie inside the root the note names. Since install.sh does not read UNSLOTH_HOME yet, the documented headline case is exactly the shape they all reject. I ran the shipped setup.sh block against a fixture and handed the result to the real resolver: note written, unsloth_home() None, _master_root empty. It fails safe, but the multi-gigabyte trees are stranded and unfindable, which is the failure the note was added to prevent.

UNSLOTH_HOME=$HOME/.unsloth names the directory the install is already in. Both uninstallers refuse that value outright, storage_roots honoured it, and honouring it passes containment, so one command with a value that looks like a no-op moved the shared model cache permanently with nothing set at the time.

Cross-platform, base against head

Both arms on owned staging runners, same sixteen files, same three operating systems.

base PR as submitted after the fixes
ubuntu-latest 0 real failures 0 0, 1297 passed
macos-15 5 the same 5 the same 5, 1290 passed
windows-latest 82 83 82, 1137 passed

The macOS five and the Windows eighty-two are identical on both arms and are all pre-existing tests in code this branch does not touch. The single extra on Windows was test_uninspectable_studio_db_keeps_the_stored_cache_home[not_a_directory], this branch's own new test: POSIX raises NotADirectoryError for a parent that is a file, Windows collapses it into FileNotFoundError, and the guard read that as "no database". Fixed, and held by a test that reproduces the error shape rather than the platform, which fails on the code as it was.

The three failing checks were not from this branch

desktop linux deb was an apt mirror 404 on bubblewrap and gst-plugins-good; desktop windows was the released installer refusing to run; macos-15 kill@studio-deps completed inside the kill window and tripped its own vacuity guard. All three were failing on main in the same window, and the last was fixed on main by ci/interrupt-marker-rename. Current main is merged in and the head is green.

Correction to the description above

The description says tests/test_studio_root_resilience.py has two failures that reproduce on the merge base because the file does not put studio/backend on sys.path. That guard is present and identical on both revisions, added by 7f6219e3a, an ancestor of the merge base. The file passes standalone on both: 6 on the base, 7 here. I will correct the description.

Not settled

  • _RemovePath in uninstall.ps1 calls Remove-Item -Recurse -Force with no reparse-point check, and this branch newly routes a user-chosen master root's children through it. The primitive is pre-existing and the marker gate stands in front of it, but _RemoveLockFile in the same file guards reparse points for exactly this reason. I did not touch it: an untested change to a deletion path is worse than a reported one, and NTFS junction semantics cannot be exercised here. Worth its own PR with a Windows fixture.
  • Also in uninstall.ps1, the master-root children use a bare Test-Path, which is false for a dangling junction, where uninstall.sh deliberately uses -e || -L. Saved today only by _RemovePath's own early return, and the user is never told the link survived.
  • build_whisper_cpp.sh's _root_value does not expand ~user or strip a trailing slash, unlike the Python resolver. It never cds, so it lands in the same physical directory either way. The ~user half is the P2 already declined above.
  • tests/studio/test_path_probe_access_denied.ps1 is only ever executed by the Windows inference smoke workflow, so its 58 lines are read as text here and remain unverified.

…iter

Found by enumerating the resolver's input space rather than reading it: 512
cells over UNSLOTH_STUDIO_HOME x STUDIO_HOME x UNSLOTH_HOME x UNSLOTH_PORTABLE x
the recorded note, base against head, one subprocess per cell. In 12 of them the
Hugging Face hub cache still moved off ~/.cache/huggingface with nothing set in
the process at all.

The write side was already gated: setup.sh and setup.ps1 refuse to record
$HOME/.unsloth and sweep an old note away. But that only fires when setup runs
again, and the user who hit this set UNSLOTH_HOME once, for one command. Until
the reader declines it too the repair never reaches them, and both uninstallers
were meanwhile refusing the same value outright, so the four readers the branch
claims to keep aligned were not.

_is_legacy_default_root declines it in storage_roots, and the CLI copy gets the
identical rule, which is what test_unsloth_home_root_agreement.py holds. Recorded
roots only: unsloth_home() returns an explicit UNSLOTH_HOME before it ever reads
the note, and narrowing that would change what the variable means rather than
what a stale file is allowed to claim.

Re-run over the same 512 cells: root resolution 480 identical and 32 changed,
which is the new UNSLOTH_HOME feature, with 0 violations; HF_HOME moves in 0
cells; of the 192 cells with no UNSLOTH_HOME and no UNSLOTH_PORTABLE, the caches
move in 30 and all 30 carry a real recorded master root. Legacy-root notes: 12
before, 0 now. Foreign notes: 0 throughout.

Also closes a gap in this file's own tests. Reverting the production hunks and
keeping the tests left 25 of 113 containment tests green, because each asserts
only that some variable is ABSENT, which is equally true when no pinning code
exists: assertions, not negative controls. Three new cases pair each decline with
the pins that must still happen in the same run, so the family fails when the
resolver does nothing. All five new tests fail with the production hunks reverted
and pass here.

119 pass in the containment suite, 147 across it plus the root agreement and
managed tools suites.
The comment beside each read said "One line, first only: a note that grew a
second line is not one we wrote", and neither did that. uninstall.sh took
`head -n 1` and carried on; uninstall.ps1 took `Get-Content -TotalCount 1`. The
second line was never looked for.

That is the four readers disagreeing in the one place it costs something.
storage_roots.py and unsloth_cli/commands/studio.py both read_text().strip() the
WHOLE file, so a two-line note is not a directory to them and they decline it.
The two uninstallers accepted line 1 and went on to authorise removing
<master>/llama.cpp, node, whisper.cpp and stable-diffusion.cpp for a master root
no runtime reader had agreed to. Measured on the fixture, all four readers, one
note:

  storage_roots.unsloth_home()    -> None
  CLI _recorded_master_root()     -> None
  uninstall.sh _master_root()     -> /<master>      <- authorises the delete
  uninstall.ps1 _MasterRoot       -> same shape

Both now refuse when a second non-blank line is present, which is what the
comments already promised. A trailing newline on an ordinary note is not a
second line, and the one-line note keeps working -- both are asserted, so the
refusal cannot pass by reading nothing.

Found by the release-safety fan-out over the install and uninstall paths, then
reproduced against the shipped helpers rather than taken on report.

tests/sh/test_uninstall_master_root.sh grows three cases and runs the real
extracted block: 45 pass here, and the two-line case fails against uninstall.sh
exactly as submitted in this PR. The PowerShell half is held structurally, as
the rest of that file's Windows coverage is.
pre-commit-ci Bot and others added 5 commits September 20, 2026 05:15
Move-Item -Force is not an atomic replace. PowerShell's filesystem provider
deletes the destination and then moves the source, so an interruption between
the two leaves NO note at all, while the complete staging file sits beside it
unreferenced. A backend that looks next reads "no master root" and, since the
miss is cached, keeps that answer for its whole lifetime.

The window cannot be removed under Windows PowerShell 5.1, which has no atomic
replace primitive this code can reach. What can be removed is re-entering it on
every single update to write bytes that are already there, which is every run
after the first. The note is compared first and the write skipped when it
matches, and the staging file is now cleared in a finally rather than left
behind when the move throws.

Two tests, and the second one took two attempts to make honest: the first
version compared LastWriteTime across two runs a millisecond apart, which can
land on one filesystem tick, and it passed against the unfixed writer. It
back-dates the note instead, so any rewrite is unmistakable, and then changes
the value to prove the writer still writes when it should. Both fail against
setup.ps1 exactly as submitted in this PR and pass here.

Found by the release-safety fan-out over idempotency and interrupted runs, then
reproduced against the shipped block under pwsh rather than taken on report.

43 pass in test_setup_master_root, 176 across it plus the containment, root
agreement and managed tools suites, and 45 in tests/sh/test_uninstall_master_root.sh.
_nothing_at's docstring is explicit that Path.exists and is_dir must not be used
because they report ENOTDIR and ELOOP as absence and the redirect would then hide
the user's files. It then took FileNotFoundError at face value, which is the same
reading restricted to one platform: POSIX distinguishes "not there" from "a
parent component is a file" (NotADirectoryError) and "I may not traverse it"
(PermissionError), while Windows collapses all three into ERROR_PATH_NOT_FOUND.

So with a file where ~/.matplotlib belongs, POSIX declined the pin and Windows
took it, moving MPLCONFIGDIR for the whole process and hiding whatever was
underneath. Same defect and same cause as the studio.db guard fixed in
37f23c5, in a second probe, and _nothing_above is the same rule: the nearest
ancestor that can be stat'ed decides, a directory means real absence, anything
else means the path could never have existed, an uninspectable ancestor proves
nothing, and no ancestors at all is the default install and is real absence.

Found by the windows-latest staging leg, on a negative control written for the
POSIX shape and added earlier in this review. base arm 82 real failures,
head 83, the one extra being that test. It is the only new failure on any of the
three operating systems.

Held by a test that reproduces the error shape rather than the platform, since
the Linux runners cannot raise it, with both opposite cases asserted so the fix
cannot pass by declining everything: a genuinely empty present directory still
reads as empty, and a path with nothing along it is still absence. It fails
against storage_roots.py exactly as submitted in this PR.

584 pass with 1 skipped across the eleven suites this branch touches.
@danielhanchen

Copy link
Copy Markdown
Member Author

Ran the full simulation workflow over this branch. Both gates, the twelve steps, and a base arm for every differential. It found four defects beyond the four in my earlier pass, all reproduced before being fixed, all now on the branch.

#10597 | issue: REAL | PR as submitted: DEFECTIVE, 8 fixed by me | merge: YES

Unsloth's own data already lived under one directory, but the caches its toolchain builds along the way did not, and unsloth export wrote a compiled-cache folder into whatever directory you ran it from. This branch pins those under the Studio root and adds an opt-in UNSLOTH_HOME that puts llama.cpp, node and whisper.cpp beside Studio instead of under it. Everyone with a default install notices one cold recompile and nothing else; the people who set UNSLOTH_HOME get an install they can move, and the eight defects below were all in the parts nobody would have noticed until it went wrong.

Before and after, one row per behaviour

# today after the PR as submitted after the fixes verdict
1 unsloth export creates ./unsloth_compiled_cache/ in the CWD, sets no variables 15 variables pinned, 21 directories made, nothing in the CWD, no studio.db unchanged, this one was right REAL
2 TORCHINDUCTOR_CACHE_DIR unset, so /tmp/torchinductor_<user>; Triton, numba, CUDA, matplotlib likewise all under ~/.unsloth/studio/cache/, extensions under .../torch-extensions/py313_linux-x86-64_cu130_2.13.0-cu130 unchanged REAL
3 HF_HUB_CACHE=~/.cache/huggingface/hub unchanged, by design (#4591) unchanged REAL, the row whose after equals its before
4 UNSLOTH_HOME=/mnt/portable unsloth studio update: runtimes stay put runtimes at /mnt/portable, note written where every reader refuses it, uninstall.sh _master_root -> [] note skipped, setup names the stranded root and the two ways out fixed
5 UNSLOTH_HOME=$HOME/.unsloth once portable_mode true forever, hub cache moves off ~/.cache/huggingface. 12 of 512 cells portable_mode false, hub cache unchanged. 0 of 512 fixed
6 a note planted in a legacy tree, under the Tauri scrub unsloth_home -> ~, portable true, caches moved, despite process.rs removing both variables unsloth_home -> None, caches unchanged fixed
7 a Studio home Windows cannot inspect, cache home chosen in Settings the chosen home is discarded, on windows-latest only read, as on Linux and macOS fixed
8 a file where ~/.matplotlib belongs POSIX declines the pin, Windows takes it and hides the config declined on both fixed
9 a two-line master-root note backend None, CLI None, but both uninstallers return <master> and authorise deleting its runtime children all four answer None; a one-line note still resolves fixed
10 unsloth studio update twice on Windows the note is deleted and re-moved every run, re-entering a window where an interruption leaves none, plus an orphaned staging file unchanged bytes left alone, staging file cleared in a finally fixed
11 a transient EACCES on share/, then recovery unsloth_home() None for the life of the process recovers on the next call fixed
12 inference: 117180 tok/s prefill, 76.97 decode, 17.48 ms ttft, 2.228 GB 119594 / 77.58 / 17.13 / 2.228, logits bit-identical unchanged REAL, no change, measured

Gate A, is the PR real

REAL. 574 lines inside changed files execute on the reported path, traced not read: 16 of 16 new resolver functions are hit by unsloth export's import alone. Reverting only the production hunks and keeping the tests breaks 190 tests and both shell suites, with test_setup_master_root 41/41, test_managed_tools_master_root 16/16 and test_unsloth_home_root_agreement 15/15 failing outright. No prior fix: #10188 is this branch's own predecessor, and #9007 names this PR canonical. Proportionate: 1842 production against 4483 test lines, 140 new predicates, 10 removed, 7235 identical.

One thing that survived the revert is worth naming. 25 of 113 containment tests still passed, because each asserts only that a variable is absent, which is equally true when no pinning code exists. Assertions, not negative controls. Three falsifiable ones added; all five new controls fail on the revert.

Gate B

B1 inference. Nothing the diff adds sits in a per-token or per-layer path: 12 changed production files, 0 hot-path functions. Measured anyway, 9 repeats a side, Qwen3-0.6B bf16, batch 4, prompt 512, 128 new tokens, greedy, seed 0: prefill +2.06%, decode +0.79%, ttft -2.02%, peak memory +0.00%, against a base spread of 17.9% / 12.5% / 18.8%. Every delta inside the band, logits checksum identical across arms.

B2 GPU detection. No detection code is touched. The only accelerator-aware code added, _torch_runtime_tag, over 66 cells of 11 accelerator shapes against 6 CUDA_VISIBLE_DEVICES values: 0 raised, 0 varied with the device mask, every incompatible build got its own cache directory, and a missing or unreadable torch fails open to cpu_None.

B3 security and sandbox. No system prompt, chat template or sandbox policy in the diff. Both guards strictly widen, _RELATIVE_PATH_ENV 51 to 63 names and MANAGED_CHILD_SCRUBBED_ENV 2 to 4, at 2.37 to 2.97 us per full scan, per spawn rather than per token. The real finding was row 6: process.rs scrubs UNSLOTH_HOME and UNSLOTH_PORTABLE so that "Tauri uses the legacy Unsloth root whatever the environment says", and a note is a file no env_remove can reach.

Enumeration, 512 routing cells

UNSLOTH_STUDIO_HOME x STUDIO_HOME x UNSLOTH_HOME x UNSLOTH_PORTABLE x the recorded note, base against head, one subprocess per cell because the resolvers read process-wide state. 480 identical, 32 changed and all 32 the new UNSLOTH_HOME feature, 0 violations. HF_HOME moves in 0 cells. Of the 192 with neither variable set, the caches move in 30 and all 30 carry a real recorded master root; legacy-root notes went from 12 to 0 and foreign notes were 0 throughout. This is what found rows 5 and 11.

Cross-platform, base arm against head, same 16 files

base final head
ubuntu-latest 0 real failures 0, 1307 passed
macos-15 5 the same 5, 1300 passed
windows-latest 82 82, 1147 passed

The 33 errors on each arm are No module named torch on runners that do not install it, present on both. Two rounds of this differential each surfaced exactly one new Windows failure, rows 7 and 8; both fixed, and the final arm carries no new failure on any of the three.

For you to weigh, not changed on the branch

  • +233 ms on every CLI backend import, base 1.031 s to head 1.264 s, median of 10, base spread 42 ms. 77 new modules, led by structlog at 26.6 ms and attr at 7.6 ms, pulled in through loggers by a resolver that needs neither. _setup_cache_env itself is 3.8 ms of it.
  • DATA_DESIGNER_HOME is not a regenerable cache. Everything else this branch moves can be rebuilt by recompiling. Recipes and managed assets are user work, and measured: after a downgrade the previous build reads ~/.data-designer and does not find them. Files are retained, so this is discovery rather than loss, but it is the only moved variable whose relocation costs something a downgrade cannot give back.
  • UNSLOTH_PORTABLE=0 cannot veto a master root. Documented, and I corrected the warning text, which used to promise the opposite.

What I could not prove

  • NTFS junction semantics. uninstall.ps1's _RemovePath uses Remove-Item -Recurse -Force with no reparse-point check, and this branch newly routes a user-chosen root's children through it. The primitive is pre-existing and marker-gated, and _RemoveLockFile in the same file does guard reparse points. Not fixed deliberately: an untested edit to a deletion path is worse than a reported one. Its own PR, with a Windows fixture.
  • The same file's master-root children use a bare Test-Path, false for a dangling junction, where uninstall.sh deliberately uses -e || -L. Saved today only by _RemovePath's own early return.
  • A TOCTOU on the POSIX uninstall: the master root is physically resolved, but a pathname is kept rather than a handle, so a co-user who can rename an ancestor between resolution and deletion redirects it. Shape pre-existing; the user-chosen root widens who can reach it.
  • C:\tc. Pre-existing for long-paths-off; this branch also takes it when the Studio path contains whitespace, which is every C:\Users\First Last. It is persisted to the User environment, and the new uninstall cleanup only clears TORCHINDUCTOR_CACHE_DIR when the value sits inside an owned root, so C:\tc survives uninstall.
  • tests/studio/test_path_probe_access_denied.ps1 is only ever executed by the Windows inference smoke workflow; its 58 changed lines are read as text here.
  • windows-11-arm and ubuntu-24.04-arm did not run.

Adversarial pass, found nothing further

_setup_cache_env is idempotent across three calls with no drift. Twelve concurrent first-run seeders against one empty root: 12 ok, 0 failures, 0 leftover write probes. Cache directories created 0755 under umask 022. A dangling symlink at a cache path is popped rather than published. What would have changed my mind: any drift between calls, a surviving probe file, a world-writable mode, or a published path torch would have makedirs'd anyway.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. You're on a roll.

Reviewed commit: 2b61d60594

ℹ️ 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 and others added 5 commits September 20, 2026 08:11
…iscovery seeding caches

Three fixes found while auditing what happens to an existing install.

A note left at <studio>/share/.unsloth-master-root that names the legacy
tree itself passed every containment check, so a bare environment resolved
a master root and the uninstaller then treated a second marked install
under it as a root to remove. Both uninstallers and both setup scripts now
decline a note whose directory is the legacy Studio dir.

A staged update derived the runtime ownership flag from the master root,
so a staging pass could mark runtimes custom when they were still legacy.
The flag is now assigned only when no stage root is in play, and follows
where the runtimes actually land.

Node tool discovery imported the Studio backend path purely to find the
bundled tools and built the whole compiler cache tree as a side effect.
The import now takes a seed_cache_env flag and the discovery path opts out.

Each fix has a regression test checked against the unfixed code.
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

1 similar comment
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@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: 76e04c5feb

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

# exports UNSLOTH_STUDIO_HOME=<root>/studio beside it, so taking that one would install a level
# below where stt_ggml_sidecar._managed_whisper_cpp_dir() looks.
_STUDIO_HOME_ALIAS="${STUDIO_HOME:-}" # read before the name below is reassigned
STUDIO_HOME="$(_root_value "${UNSLOTH_HOME:-}")"

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 Absolutize relative master roots in the whisper builder

When the advertised standalone builder is run with a relative value such as UNSLOTH_HOME=portable ./scripts/build_whisper_cpp.sh, this assignment leaves the root relative and installs under the caller's current directory. The Python resolver now applies Path.resolve() when it later reads the same variable, so a backend launched from another working directory searches a different portable/whisper.cpp and reports dictation unavailable. Normalize a relative UNSLOTH_HOME against the builder's initial working directory, as studio/setup.sh does.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

The divergence is real but this change does not cure it, so I am leaving the builder as it is.

The builder never changes directory, so INSTALL_DIR names the same directory whether or not it is absolutized. Ran the real script both ways with stub git and cmake, from the same working directory, with UNSLOTH_HOME=portable:

base    ==> Installed portable/whisper.cpp/build/bin/whisper-server
patched ==> Installed <cwd>/portable/whisper.cpp/build/bin/whisper-server

both    ./portable/whisper.cpp/build/bin/whisper-server

Same tree, same marker, same clone. Only the log line differs.

The failure you describe is caused by the variable itself being relative, not by where the builder resolves it: the backend re-reads UNSLOTH_HOME and applies Path.resolve() against its OWN working directory, so it still misses an install made from anywhere else. Measured, builder run in a/ and backend started in b/:

builder INSTALL_DIR : <root>/a/portable/whisper.cpp
backend looks in    : <root>/b/portable/whisper.cpp

Absolutizing inside the builder leaves that second line exactly where it was. setup.sh absolutizes for a different reason that does apply there: it picks node before its first cd "$SCRIPT_DIR" and llama.cpp after it, so a relative value would name two different directories within one run.

Worth pinning down properly rather than papering over, and a relative master root is on the list of things to settle before UNSLOTH_HOME is documented.

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.

3 participants