Repository navigation
Stop the installer rolling back a successful install when a shell profile cannot be written - #9269
Conversation
… written install.sh runs under `set -e`, and the PATH persistence helpers appended to the user's rc files with unguarded `echo >>`. A profile the user cannot write -- root-owned dotfiles, managed machines, immutable distributions, container images -- therefore ended the installer, and the exit trap treats any non-zero status as a failed install: it deleted the environment that had just been built and moved the previous one back, immediately after studio setup announced success. On a reinstall that silently reverted the upgrade; on a first install it reported failure after reporting success. The replacement is now committed as soon as studio setup returns 0, before anything else in that branch runs. The environment is final at that point and the rest of the script only reports progress or wires PATH, the shim and the shortcuts, so nothing down there can restore the previous environment over the new one. That covers the whole tail, including the deliberate refusal when a real directory occupies the shim path. PATH persistence is a convenience rather than part of the install, so both helpers now write each profile through a single redirect -- which also leaves no half-written entry behind -- and warn with the directory to add by hand instead of ending the install. One unwritable profile no longer costs the other five the uv loop writes. Fixes unslothai#9254
…itten `ln -sfn` cannot replace an entry in a read-only bin directory, so a reinstall on a host with a managed `~/.local/bin` -- home-manager, an immutable image, a root-owned directory -- ended the install after studio setup had already succeeded. Nothing was actually wrong: a reinstall rebuilds the environment at the same path, so the link already there resolves to the executable this run installed, and the shim the installer wanted was in place before it started. The shim write now tolerates exactly that case and reports it. The entry is compared with `-ef`, so a link that resolves to this run's executable is kept whatever its spelling, while a link that only names the same path without resolving to it is not. Anything else at the shim path is still fatal -- without the shim the `unsloth` command does not exist -- but it now says why and gives the absolute command to start Studio with instead of the bare `ln` error.
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 3623aabe7a
ℹ️ 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".
|
Codex Review: Didn't find any major issues. Breezy! 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". |
|
Confirmed this on main, where the profile appends still run ahead of _commit_studio_venv_replacement at install.sh:5616, so an unwritable profile reaches the rollback trap after the success banner. Will get this reviewed. |
|
Codex Review: Didn't find any major issues. You're on a roll. 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. Hooray! 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 confirmed that normal reinstalls rebuild the Studio Python environment, and this change commits the new environment immediately after setup succeeds, so an unwritable shell profile warns without restoring the old install. The PR head passed all 40 rollback lifecycle checks and shell syntax checks; running the same coverage against main reproduced the rollback and profile failures. |
Fixes #9254
What happens today
install.shruns underset -e, and the PATH-persistence helpers append to the user's shell profile with unguardedecho >> "$file". A profile the user cannot write — root-owned dotfiles, managed machines, immutable distributions, container images — therefore ends the installer. TheEXITtrap treats any non-zero status as a failed install, so it deletes the environment that was just built and moves the previous one back, immediately after studio setup has printed its success banner:On a reinstall or upgrade this silently reverts the new environment to the previous one — the reporter's post-install checks passed only because the restored venv was itself a working install of the same version. On a first install there is nothing to restore, so the run just reports failure after reporting success. The process exits 1, not 0 as the issue states; the trap re-raises the status.
Root cause
_commit_studio_venv_replacement— the only thing that disarms the rollback trap — ran at the very end of the script. Everything after studio setup returned therefore sat inside the rollback window while doing nothing to the environment:mkdir -p "$_LOCAL_BIN", the refusal when a real directory occupies the shim path,ln -sfn, the fishconf.dappends, the rc appends (once for~/.local/bin, up to six more in the uv loop), andcreate_studio_shortcuts.What changed
The replacement is committed as soon as studio setup returns 0, as the first statement in that branch. The environment is final at that point and the rest of the script only reports progress or wires PATH, the shim and the shortcuts, so no failure there can restore the previous environment over the new one. The failed-setup path is unchanged: no commit, so the gate that exits with setup's status still rolls back.
PATH persistence warns instead of failing. Both helpers write each profile through a single redirect — so an unwritable profile also leaves no half-written entry — and on failure report the directory to add by hand. One unwritable profile no longer costs the other five the uv loop writes. The success path is byte-identical to before.
A read-only
~/.local/binthat already holds this run's shim is not a failed install.ln -sfncannot replace an entry in a directory it cannot write, but a reinstall rebuilds the environment at the same path, so the link already there resolves to the executable this run installed. The entry is compared with-ef, so a link that resolves to it is kept whatever its spelling, while one that merely names the same path is not. Anything else at the shim path stays fatal — without the shim theunslothcommand does not exist — but now says why and gives the absolute command to start Studio with.Deliberately not changed
create_studio_shortcutsis still called unguarded, so a launcher that cannot be written still ends the run non-zero. Guarding that call puts the function on the left of||, which disableserrexitthroughout it in dash, bash and bash-as-sh alike; its unguarded writes then fail silently and it goes on to publish a desktop entry for a launcher that was never written. Restoring that would mean giving every write in ~900 lines its own status, or running the call as an asynchronous subshell — which stops Ctrl-C from reaching it, since an async list ignoresSIGINTwith job control off, and the icon download inside has no timeout. After this change such a failure can no longer touch the environment, so the remaining cost is an exit code and a missing banner; the fix belongs with a restructuring of shortcut creation.install.ps1needs no equivalent change:Add-ToUserPathis wrapped in try/catch and returns$false, and PowerShell has noset -e.Validation
New coverage in
tests/sh/test_install_rollback_lifecycle.shruns install.sh's own post-setup tail, extracted from the setup-succeeded gate to the failed-setup gate, so the cases exercise its real commit call site:~/.zshrcand an unwritable fishconf.dfile: the install survives, the profile is untouched, the user is told, and the profiles that can be written still get their entry;Each production change was mutation-checked: reverting it fails exactly its own assertions and nothing else. Also verified that the profile lines written on the success path are byte-identical to
main, andsh -n/dash -n/bash -non the installer.