Repository navigation
Stop the uninstaller stranding old installs, and deleting directories that are not ours - #10471
Conversation
… 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.
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
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.
|
The one red check here, It is 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. |
|
Codex Review: Didn't find any major issues. Chef's kiss. Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
|
@codex security review |
|
Security review completed. No security issues were found in this pull request. Reviewed commit: Only the user who started this review can view the report in Codex. ℹ️ About Codex security reviews in GitHubThis is an experimental Codex feature. Security reviews are triggered when:
Once complete, Codex will leave suggestions, or a comment if no findings are found. |
…er a partial removal
|
Codex Review: Didn't find any major issues. 👍 Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
|
Codex Review: Didn't find any major issues. Swish! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
|
Final state, against Ran everything on a real Windows box (Windows 11 build 26200, Windows PowerShell 5.1.26100.9168, no pwsh installed): and the uninstaller body itself, which no test had ever run: an owned default root is removed with no On Linux, every Two red checks, neither from this branch:
The first attempt at that was red, and for a reason worth recording: 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. |
|
Codex Review: Didn't find any major issues. What shall we delve into next? Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
|
@codex review |
|
Codex Review: Didn't find any major issues. 🚀 Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
|
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 Driving the real The middle column is the regression; the first column's 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 Fixed in 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 |
|
Both red checks here were diagnosed, and neither came from this branch.
The ordering assertion is a good illustration of why it was never this branch's doing: 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 Merged current main in (cc980b4, no conflicts) and confirmed the previously failing test now passes on the merged tree.
|
|
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
What that silently broke on main, and what this branch does about itThe deny list did not fire. The "parent of USERPROFILE" rule sits inside a
Two call sites were not even inside a A locked file left the tree permanently un-removable. The rest of the runReal 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, One thing worth stating plainly for anyone reading the summary: the databases are not kept. Two repo tests could not run unelevated here rather than failing: |
# Conflicts: # .github/workflows/cross-platform-parity-ci.yml # scripts/uninstall.ps1 # scripts/uninstall.sh
|
@codex review |
1 similar comment
|
@codex review |
|
Codex Review: Didn't find any major issues. More of your lovely PRs please. Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
|
I drove this end to end on a throwaway Windows runner (run), under Windows PowerShell 5.1 rather than pwsh 7:
The same job runs an adversarial matrix against this branch and against
The last row is the strongest case for the change. The uninstaller reads The change touches only |
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:<root>/.venv, not<root>/unsloth_studio.unsloth-studio-ownedexisted, neither name carried a markerOn Windows this is sharper than it looks:
share/studio.confis never written there, so all three sentinels a Windows root can present postdate thebin/shim directory, whileinstall.ps1still 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 aUNSLOTH_STUDIO_HOMEleft pointing at a project would delete the project.And only inside something that is a venv.
_is_venv_dir/_IsVenvDirasks forpyvenv.cfgor the interpreter. A file namedbin/unslothwith nothing around it is a file with a name.On Windows the accepted signals are pip's
Scripts\unsloth.exeand the package behind it, because antivirus quarantines that.exeout of a venv that still runs andinstall.ps1:6412installs and repairs through exactly that condition.2.
~/.unsloth/studiowas deleted with no ownership checkA custom root got the gate. The default one did not:
- _remove_root_recording_db "$HOME/.unsloth/studio"studiounder~/.unslothis an ordinary directory to create by hand. An ungated bareuninstall.shtook it, and then took~/.unslothwith 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.dbis 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 -Parentthrows-LiteralPathand-Parentsit 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.
-LiteralPathalone 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.cppsibling; and_RootFromConfnow resolves a root out ofstudio.confat 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_DIRfor seconds after the server stops, and neither pass in_StopProcessesLockingRootscan 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.
_RemovePathhas 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.shandinstall.ps1now write$STUDIO_HOME/.unsloth-studio-ownedthe 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_HOMEis 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
WriteAllTextfollow 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 afteruv venvhas 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.*andcache/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:4231already treat every other spelling as user data) and required to hold a venv.cache/uvis 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.ps1and a POSIX twin,tests/sh/test_uninstall_legacy_layout_gate.sh, which extracts the helpers fromuninstall.shand 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
.venvhas unsloth pip-installed, a console script with no venv around it, and a leftover name outside the installers' format.test_uninstall_webview_data.shdrives the whole script for the refused-root reporting.test_uninstall_reparse_stop_roots.ps1also 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 LinuxNew-Item -ItemType Junctiondoes 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.ps1and 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.