Skip to content

Stop the uninstaller stranding old installs, and deleting directories that are not ours - #10471

Merged
oobabooga merged 26 commits into
mainfrom
uninstall-ownership-gate
Sep 9, 2026
Merged

oobabooga merged 26 commits into
mainfrom
uninstall-ownership-gate

Conversation

@danielhanchen

@danielhanchen danielhanchen commented Sep 8, 2026 •

Copy link
Copy Markdown
Member

What this is

Four uninstaller fixes, split out of #10282. None of them are about Windows on ARM, and two change behaviour on Linux and macOS, so they were the wrong thing to review as a footnote to a Windows installer feature.

1. The ownership gate strands older installs

_is_studio_root (sh) and _IsStudioRoot (ps1) decide whether a root is ours before deleting it. Both only recognise sentinels that postdate two renames:

  • the venv used to be <root>/.venv, not <root>/unsloth_studio
  • before .unsloth-studio-owned existed, neither name carried a marker

On Windows this is sharper than it looks: share/studio.conf is never written there, so all three sentinels a Windows root can present postdate the bin/ shim directory, while install.ps1 still contains a migration path for <root>/.venv. So the installer believes that layout exists and the uninstaller does not. The result is a real install the uninstaller refuses to touch, reporting it as not Unsloth-owned.

The gate now recognises those layouts, under two rules that keep it from recognising anything else.

A venv sentinel counts only at the managed root. The legacy venv's own marker is proof anywhere, since only we write that file. Everything else a pre-marker install can show sits inside the venv, and pip puts it in any venv the wheel is installed into, so it names the wheel and not the owner of the root. Those are read only at the default managed root, which the gate is told about explicitly (_is_studio_root <root> managed, _IsStudioRoot -ManagedDefaultRoot) and which is the only root either installer can create a legacy layout in: both skip the migration for an env-mode root. Otherwise a UNSLOTH_STUDIO_HOME left pointing at a project would delete the project.

And only inside something that is a venv. _is_venv_dir / _IsVenvDir asks for pyvenv.cfg or the interpreter. A file named bin/unsloth with nothing around it is a file with a name.

On Windows the accepted signals are pip's Scripts\unsloth.exe and the package behind it, because antivirus quarantines that .exe out of a venv that still runs and install.ps1:6412 installs and repairs through exactly that condition.

2. ~/.unsloth/studio was deleted with no ownership check

A custom root got the gate. The default one did not:

-    _remove_root_recording_db "$HOME/.unsloth/studio"

studio under ~/.unsloth is an ordinary directory to create by hand. An ungated bare uninstall.sh took it, and then took ~/.unsloth with it through the empty-directory prune that follows, having removed nothing of ours in the process. Now gated on the same sentinels as a custom root, and it says so rather than failing silently.

One difference from a custom root, which the refusal message alone would get wrong: a path the user named is not ours by definition, but this one is. A refused root that still holds studio.db is reported by name, and the run no longer closes with "No studio.db was found". It also does not tell the reader to delete it by hand, which is what the generic removal-failure note would have said and the opposite of what the gate is for.

3. Split-Path -LiteralPath $p -Parent throws

-LiteralPath and -Parent sit in different parameter sets, so the call is ambiguous and fails. Not on some hosts: on every uninstall that reaches it, on Windows PowerShell 5.1 and on pwsh 7 alike.

It shipped because it parses. Every uninstaller test asserted over the source shape with the AST and none of them ran the body, so a call that throws at runtime read as covered. -LiteralPath alone already returns the parent, which is what the call wanted.

Fixing it turns on three code paths that could not run before, and all of them feed something that force-stops processes and runs before the ownership gates. A relative symlink root now expands into generic subdirectories of its target (node, bin, unsloth_studio); a custom root now yields the legacy <parent>\stable-diffusion.cpp sibling; and _RootFromConf now resolves a root out of studio.conf at all, which a stale conf can point at a directory another application has taken over.

So one rule replaces the old one: everything that stops, deletes or edits on behalf of a root takes the list that passed both gates, and nothing takes the unfiltered one. That covers the process sweep, the port-file stopper, the handle scan, the reparse expansion and the PATH cleanup. An explicitly empty list means "nothing qualifies" rather than "do not scope", which PowerShell's truthiness would otherwise turn into a machine-wide sweep on a run with nothing to delete.

4. The remove retry budget was too short

A flat 700ms, four times. torch inductor's compile workers keep plain data handles on files under TORCHINDUCTOR_CACHE_DIR for seconds after the server stops, and neither pass in _StopProcessesLockingRoots can attribute a data handle to a process, so those files are not something the uninstaller can unlock. It reported data left behind on a normal uninstall after any training run. Escalating backoff instead of a flat one.

Split in two, because the escalation and the retry are waiting for different things. Every path keeps 2100ms of its own, exactly the flat 700ms x3 it replaces, so no path is retried less than before; a lock only that path hits is unaffected by what an earlier one spent. The escalation beyond that comes from one budget for the whole run, since what it waits out is wall clock and shared: whatever the first blocked path waits, the next no longer has to. _RemovePath has 18 call sites, so without that a root that can never be deleted would spend the full escalation at every one of them.

Classifying the error instead does not work. A delete-pending file reports access denied rather than a sharing violation, antivirus has been observed doing the same for transient failures, and the PowerShell FileSystem provider mislabels both directions anyway.

The installer claims the root

install.sh and install.ps1 now write $STUDIO_HOME/.unsloth-studio-owned the moment they create the root, before the uv cache and long before the venv writes its own marker.

Only for a root the install is allowed to take over: in env mode $STUDIO_HOME is a directory the user chose, so an empty one, or one already carrying an unambiguous Unsloth marker, and nothing else. A marker written ahead of that decision, on a run that then aborts, would leave somebody's project marked as ours.

That list is deliberately shorter than the installer's own replacement guard, which shares most of it. The guard only refuses to overwrite and can afford a weak signal; this one authorizes a delete, so bin/unsloth, which is any file of that name, is not on it. A root that has one needs no marker anyway, since the uninstaller already recognises it by its symlink target.

The marker path is unlinked and confirmed gone before anything is written, because both the shell redirection and WriteAllText follow a symlink there and would truncate its target, and the unlink can fail on a root we cannot write while that target stays writable. The replacement guard reads the marker too, so a first install that dies after uv venv has put files in the venv is retried rather than refused.

The uninstaller's gate reads its sentinels through links on purpose. Refusing a marker that is a link, or one inside a linked directory, would buy nothing, since anyone who can plant a link at those paths can plant a plain file instead, and it would cost a supported install: relocating a multi-gigabyte venv to another disk and leaving a symlink behind puts a real marker behind a link, and refusing it strands exactly the install this gate exists to keep removable. The link test belongs in the installer's claim, where following one truncates the target rather than reads it. A removal that takes the sentinels and then fails on a locked child puts the marker back, so the retry it asks for is not refused.

Without it, every install that dies in that window leaves a directory the uninstaller can only identify by guessing from leftovers, and each guess is a chance to delete somebody else's files. Four review rounds here were spent on exactly that: the guesses were .venv.invalid.*, unsloth_studio.rollback.* and cache/uv, and each needed a further check to stop it matching a hand-made directory. The first two survive, narrowed to the installers' own <stamp>.<pid>[.<n>] name format (install.sh:907, install.ps1:4231 already treat every other spelling as user data) and required to hold a venv. cache/uv is gone; the marker replaces it, and it covers custom roots too, which a managed-root-only sentinel never could.

Tests

tests/studio/test_uninstall_legacy_layout_gate.ps1 and a POSIX twin, tests/sh/test_uninstall_legacy_layout_gate.sh, which extracts the helpers from uninstall.sh and drives them directly. Both assert the accept direction and the refuse direction in both modes, because a gate that accepts everything passes a one-sided test and one that accepts everything at some root passes a one-mode one.

Between them: the install shapes that must stay removable at the managed root, the marker-only shapes a custom root can present, and the directories that must stay refused, including a project whose .venv has unsloth pip-installed, a console script with no venv around it, and a leftover name outside the installers' format. test_uninstall_webview_data.sh drives the whole script for the refused-root reporting.

test_uninstall_reparse_stop_roots.ps1 also picks its link kind by platform now and verifies the link it created actually has a reparse target. It used to ask for a junction unconditionally: on Linux New-Item -ItemType Junction does not throw, it silently creates an ordinary directory, so the test skipped nothing and asserted nothing.

CI

test_uninstall_prebuilt_parity.ps1, test_uninstall_reparse_stop_roots.ps1 and both new gate suites are wired into cross-platform parity CI. They ran in no workflow at all, which is the direct reason fixes 1 through 3 shipped.

… that are not ours

Four fixes to the uninstaller, split out of the Windows on ARM work because none
of them are about Windows on ARM and two change behaviour on Linux and macOS.

1. The ownership gate strands older installs. _is_studio_root and _IsStudioRoot
   only recognise sentinels that postdate two renames: the venv used to be
   <root>/.venv rather than <root>/unsloth_studio, and before
   .unsloth-studio-owned neither name carried a marker at all. On Windows
   share/studio.conf is never written, so all three Windows sentinels postdate
   the bin/ shim directory while install.ps1 still migrates <root>/.venv. Result:
   a real install the uninstaller refuses to touch, reported as "not an
   Unsloth-owned install". Now the legacy venv's own marker counts, as does
   either venv directory carrying pip's console script.

2. ~/.unsloth/studio was removed recursively with no ownership check at all,
   while a custom root got one. "studio" under ~/.unsloth is an ordinary
   directory to create by hand, and an ungated bare run took it, then took
   ~/.unsloth with it through the empty-directory prune, having removed nothing
   of ours. Gated on the same sentinels as a custom root.

3. `Split-Path -LiteralPath $p -Parent` throws. -LiteralPath and -Parent are in
   different parameter sets, so the call is ambiguous and fails on every
   uninstall that reaches it. It parses, which is how it shipped: every
   uninstaller test asserted over the source shape and none ran the body.
   -LiteralPath alone already returns the parent.

4. The remove retry budget was a flat 700ms four times. torch inductor's compile
   workers keep plain data handles on files under TORCHINDUCTOR_CACHE_DIR for
   seconds after the server stops, and neither pass in _StopProcessesLockingRoots
   can attribute a data handle to a process, so the uninstall reported files left
   behind. Escalating backoff instead.

Tests: test_uninstall_legacy_layout_gate.ps1 and its POSIX twin
tests/sh/test_uninstall_legacy_layout_gate.sh, both asserting the accept and the
refuse direction. Against the current uninstaller both fail 3 checks, on Windows
and on Linux alike, and pass with these fixes.

Also wires four uninstaller tests into cross-platform parity CI. They ran in no
workflow at all, which is why 3 shipped.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 8, 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-09T19:30:09.423851Z 6916f54 New commits
🔒 Security Review ✅ Completed 2026-09-09T19:36:41.030023Z 6916f54 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.

danielhanchen added a commit that referenced this pull request Sep 8, 2026
The ownership gate, the ~/.unsloth/studio guard, the Split-Path call that throws
and the remove-retry budget are not about Windows on ARM, and two of them change
behaviour on Linux and macOS. Reviewing them as a footnote to a Windows
installer feature was the wrong shape. They are now #10471, against main, with
the parity CI wiring that runs them.

These files go back to main exactly. Also drops this workflow's references to
test_uninstall_legacy_layout_gate.ps1, which now lives in that PR; the runner
loop already skips a test file it cannot find, so it can be listed again once
#10471 lands.
chatgpt-codex-connector[bot]

This comment was marked as resolved.

@danielhanchen

Copy link
Copy Markdown
Member Author

The one red check here, parity (windows-latest), is not from this PR.

It is test_a_non_ascii_marker_survives_the_rollback in tests/python/test_windows_python_venv_hardening.py, a file this branch does not touch. The same two cases fail identically on main: runs 34092822926, 34109277955, 34116989434 and 34117845683, including at b66d2a4, the last commit to touch that file.

Cause and fix are in #10484: nothing sets the writing end of the PowerShell pipe, so 5.1's OEM code page and pwsh 7's UTF-8 are both decoded with the ANSI one. Once that lands this gate should go green here without a change to this branch.

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

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Chef's kiss.

Reviewed commit: fb7c5092ae

ℹ️ 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 8, 2026
@oobabooga

Copy link
Copy Markdown
Member

@codex security review

@chatgpt-codex-connector

Copy link
Copy Markdown

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

Reviewed commit: a924bca30f

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.

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

This comment was marked as resolved.

@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 8, 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.

@chatgpt-codex-connector

Copy link
Copy Markdown

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

Reviewed commit: ca684d00d5

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

chatgpt-codex-connector[bot]

This comment was marked as resolved.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Swish!

Reviewed commit: 83360846d6

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

@oobabooga

oobabooga commented Sep 8, 2026 •

Copy link
Copy Markdown
Member

Final state, against 0c3d5c928.

Ran everything on a real Windows box (Windows 11 build 26200, Windows PowerShell 5.1.26100.9168, no pwsh installed):

tests\studio\test_uninstall_legacy_layout_gate.ps1     all checks passed
tests\studio\test_uninstall_reparse_stop_roots.ps1     all checks passed
tests\studio\test_uninstall_prebuilt_parity.ps1        all tests passed
tests\studio\test_uninstall_arg_guard.ps1              all checks passed
tests\studio\test_uninstall_dual_install_icon.ps1      all tests passed

and the uninstaller body itself, which no test had ever run: an owned default root is removed with no Split-Path parameter-set error anywhere in the output, a root holding only .unsloth-studio-owned and a cache\uv is removed, and a hand-made root with notes.txt and a studio.db is refused with notes.txt intact, the directory named in the summary, and no advice to delete it.

On Linux, every tests/sh/*.sh and every tests/studio/*.ps1 passes, plus the installer Python suites (292 passed). tests/sh/test_uninstall_legacy_layout_gate.sh also passes under dash. The one exception is test_path_probe_access_denied.ps1, red on this branch's merge base too: it asserts an unreadable parent directory, which does not reproduce under pwsh on Linux.

Two red checks, neither from this branch:

  • linux ubuntu2404-arm-root fails at Assert no source build with built from source: nvidia-npp-cu13 -- these must resolve to wheels on a clean machine. Same failure on fix/issue-10155; it is an aarch64 wheel-availability problem, and nothing here touches package resolution.
  • pre-commit.ci reports scripts/run_ruff_format.py is not executable on every open PR I looked at.

parity is the job this PR wires the new tests into, and for most of this branch's life it was red at AMD venv repair loop tests, which sits above them, so they did not execute at all. That is fixed on main now, and the org queue is deep, so I ran the job on a throwaway clone of this head instead. Both rows green, and all four new steps actually ran:

parity (ubuntu-latest)     Uninstaller prebuilt parity tests        success
                           Uninstaller reparse stop-root tests      success
                           Uninstaller ownership gate tests         success
                           POSIX uninstaller ownership gate tests   success
parity (windows-latest)    Uninstaller prebuilt parity tests        success
                           Uninstaller reparse stop-root tests      success
                           Uninstaller ownership gate tests         success
                           POSIX uninstaller ownership gate tests   skipped (Linux only)

The first attempt at that was red, and for a reason worth recording: Cross-platform parity tests failed 44 cases in test_windows_python_venv_hardening.py. That suite lifts five uv-cache functions out of install.ps1 and runs them alone, and I had put the root claim inside one of them, so every extracted run hit a command-not-found. Moved to the call site in 0c3d5c928; the claim has nothing to do with the uv cache, and putting it there was only ever "this is the first thing that runs". Locally the failure was invisible because those tests skip without pwsh on PATH, which is now how I run them.

Every review item this round raised is fixed rather than argued with, and each fix has a check that fails against the commit before it.

@chatgpt-codex-connector

Copy link
Copy Markdown

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

Reviewed commit: 0c3d5c9281

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

@oobabooga

Copy link
Copy Markdown
Member

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

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

Reviewed commit: 00da4532b7

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

@oobabooga

Copy link
Copy Markdown
Member

Reassessed the whole change from scratch rather than from the review thread, and found one regression that the thread had introduced and every round since had preserved.

A relocated install was refused. The gate required each ownership marker to be a regular file that is not a link, inside a directory that is not a link. Move a multi-gigabyte unsloth_studio venv to another disk, leave a symlink behind, and the marker is a real marker sitting behind a link, so the gate answered "refusing to remove non-Unsloth path" for a genuine install and never removed it. That is the exact failure this PR exists to prevent, aimed at itself.

Driving the real uninstall.sh end to end against five install shapes, with only HOME and the OS probes stubbed:

                 merge base    0c3d5c928    00da4532b
relocated venv   removed       KEPT         removed
plain install    removed       removed      removed
hand-made dir    REMOVED       kept         kept
legacy .venv     removed       removed      removed
relocated root   removed       removed      removed

The middle column is the regression; the first column's hand-made dir: REMOVED is the data loss the PR is for. Same result on the Windows gate for a junctioned unsloth_studio or .venv.

The check also bought nothing. Anyone who can plant a link at those paths can plant a plain file instead, which the gate has always accepted, so it stopped no attack and only lost a supported layout. The link test does belong in install.sh's claim, where following one would truncate the target rather than read it, and it stays there.

Fixed in 00da4532b: the gate reads its sentinels through links again, _is_venv_dir accepts a relocated venv, and the leftover scan keeps its own link check, where the name came from a wildcard rather than from us. Six new checks per suite cover marker-behind-a-link at all four sentinel paths, a relocated venv directory, and a relocated pre-marker venv; all six fail against 0c3d5c928.

Also re-derived the premise while I was in there. Before this PR the default root was removed with no ownership check at all, so on POSIX the legacy shapes were never actually stranded: the only root that can hold them is the one that was ungated. Recognising them is still required, because gating that root is what fix 2 does, but the two halves only make sense together and the description now says so.

Everything else re-verified on 00da4532b: every tests/sh/*.sh and tests/studio/*.ps1, dash for the POSIX gate, and 2793 Python tests with pwsh on PATH. Cross-platform parity green on both rows with all four new steps executing. The one red check is linux ubuntu2404-arm-root, still built from source: nvidia-npp-cu13, which reproduces on unrelated branches.

@danielhanchen

Copy link
Copy Markdown
Member Author

Both red checks here were diagnosed, and neither came from this branch.

Repo tests (CPU) was stale. The five failures all came from main, which was red at the time this branch was last tested, and were fixed there by 4d96157 ("Unbreak main: catch the install.ps1 handoff harness up"). The most recent completed run on main, 0dcea75, is green.

The ordering assertion is a good illustration of why it was never this branch's doing:

assert 376818 > 380790

Those offsets are the merge commit, not this head. On this branch's own tree the markers are the other way round and the assertion passes. #8066 moved the bail inside the restoring try and updated the assertion to match, from "save after the last early return" to saved < bail < restored, which is the stronger invariant now that a finally guarantees the restore. This branch simply predated that.

Merged current main in (cc980b4, no conflicts) and confirmed the previously failing test now passes on the merged tree.

linux ubuntu2404-arm-root is real, but it belongs to the shared installer path rather than to this branch, which is why it also fails on every other open PR:

::error::built from source: nvidia-npp-cu13 -- these must resolve to wheels on a clean machine

nvidia-npp-cu13 is a deprecated stub NVIDIA published when the math libraries dropped the -cuNN suffix; the CUDA 13 runtime is plain nvidia-npp. Split out as #10587 with the detail, since it is unrelated to uninstall ownership and should not ride along here. This leg should clear once that lands and main is merged again.

@danielhanchen

Copy link
Copy Markdown
Member Author

Independent verification of this PR on the hardware, by uninstalling a real 4.86 GB install and rebuilding it. Worth recording because the run started as a check of the Windows-on-ARM branch, found four bugs, and then established that all four are ones this PR already fixes. That makes this a correctness fix for stock Windows, not only a tidy-up.

The root cause, confirmed on 5.1

PSVersion: 5.1.28000.2704
Split-Path -LiteralPath 'C:\Users\P14\temp\x\y.txt' -Parent
  -> AmbiguousParameterSet,Microsoft.PowerShell.Commands.SplitPathCommand
Split-Path -LiteralPath 'C:\Users\P14\temp\x\y.txt'
  -> C:\Users\P14\temp\x

-LiteralPath with -Parent is an unresolvable parameter set on Windows PowerShell 5.1 and works only on pwsh 7. install.ps1 is documented as irm ... | iex, and stock Windows runs that in 5.1, so this is the default path for real users rather than an edge case. CI is green on it because CI has pwsh 7.

main today carries eight of those calls in scripts/uninstall.ps1. This branch carries none: it uses the no-switch form, which resolves cleanly and already returns the parent, plus [System.IO.Path]::GetDirectoryName where a lexical answer is wanted. Line 162 says as much in passing.

What that silently broke on main, and what this branch does about it

The deny list did not fire. The "parent of USERPROFILE" rule sits inside a try{}catch{}, so on 5.1 the throw was swallowed and the rule never ran. That path is C:\Users on a real machine. Reproduced by pointing UNSLOTH_STUDIO_HOME at the parent of USERPROFILE with a studio sentinel present: the main version recursively deleted it, taking a sibling profile's data file with it. This branch's version prints refusing to remove unsafe path. Re-checked the rule in isolation against this branch's code on 5.1:

USERPROFILE     = C:\Users\P14
parent computed = [C:\Users]
deny rule fires for 'C:\Users' = True

studio.conf discovery was dead. _RootFromConf always returned $null on 5.1, contradicting the script's own header. A root reachable only through LOCALAPPDATA\Unsloth Studio\studio.conf survived the uninstall with its studio.db intact while the summary claimed "No studio.db was found".

Two call sites were not even inside a try, so every 5.1 run printed two red errors plus a bogus refusing to remove unsafe path: with an empty path, and legacy sibling stable-diffusion.cpp cleanup never ran.

A locked file left the tree permanently un-removable. Remove-Item -Recurse deletes what it can, fails on the locked child, and in doing so destroys all four ownership sentinels. Every later run then hits refusing to remove non-Unsloth path forever, with studio.db still on disk. This one is not version specific. _RestoreOwnerMarker on this branch is exactly the fix, and its comment describes the same failure.

The rest of the run

Real uninstall of a 4.86 GB install root: 72,821 entries and 63,623 files removed in 97.8 s, root absent, zero "could not remove". Reinstall into the same path then succeeded, exit 0 in 13m17s, unsloth 2026.9.3, and woa/torch-index.txt re-persisted. So leftovers do not block reinstall. A second uninstall produced a byte-identical listing, so it is idempotent. A junction pointing out of the root was unlinked rather than followed, and the file it pointed at survived. The HF hub cache was untouched.

One thing worth stating plainly for anyone reading the summary: the databases are not kept. studio.db, auth.db and rag.db all go with the root, deliberately, and the script says so. Only the Hugging Face hub cache is preserved. Every in-root cache is removed.

Two repo tests could not run unelevated here rather than failing: test_uninstall_reparse_stop_roots.ps1 needs admin or Developer Mode for New-Item -ItemType SymbolicLink, and three of the shell tests need real symlinks that git-bash's ln -s does not produce. Noting those as not-run rather than passed. The four bugs above are invisible to the existing PowerShell tests because none of them drive a real removal.

# Conflicts:
#	.github/workflows/cross-platform-parity-ci.yml
#	scripts/uninstall.ps1
#	scripts/uninstall.sh
@oobabooga

Copy link
Copy Markdown
Member

@codex review

1 similar comment
@oobabooga

Copy link
Copy Markdown
Member

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. More of your lovely PRs please.

Reviewed commit: bae21d3575

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

@oobabooga

Copy link
Copy Markdown
Member

I drove this end to end on a throwaway Windows runner (run), under Windows PowerShell 5.1 rather than pwsh 7:

  • A real install.ps1 --no-torch produces 77,861 files.
  • Two installs and three uninstalls in a row: install, uninstall, reinstall over the same path, uninstall again, then uninstall a third time on a path that is already gone.
  • All five come back clean, with no parameter-set error and no "could not remove".
  • The five uninstaller suites pass under both 5.1 and pwsh 7.

The same job runs an adversarial matrix against this branch and against main on the same runner. Of seventeen assertions, every genuine install shape behaves identically. The five that differ all go in the direction of deleting less:

scenario this branch main
hand-made ~/.unsloth/studio kept, named in the summary removed
a user file inside it kept deleted
freeform unsloth_studio.rollback.user-data kept removed
ownership marker after a partial removal restored lost
directory named by a stale UNSLOTH_STUDIO_HOME kept deleted

The last row is the strongest case for the change. The uninstaller reads UNSLOTH_STUDIO_HOME from the environment and removes whatever path it names, which is what its help text promises. On main nothing checks that the path is an Unsloth install first, so a variable left over in a shell profile, or pointing at a directory since reused for something else, takes that whole tree and the user files in it. In the scenario above it was another profile's directory holding a plain data file. This branch prints refusing to remove non-Unsloth path instead.

The change touches only install.sh, install.ps1, scripts/uninstall.sh and scripts/uninstall.ps1. The .unsloth-studio-owned marker it starts writing does nothing on its own, and an older uninstaller ignores it.

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