Skip to content

Stop the installer rolling back a successful install when a shell profile cannot be written - #9269

Merged
oobabooga merged 4 commits into
unslothai:mainfrom
Lyxot:fix/installer-rollback-after-success
Aug 25, 2026
Merged

oobabooga merged 4 commits into
unslothai:mainfrom
Lyxot:fix/installer-rollback-after-success

Conversation

@Lyxot

@Lyxot Lyxot commented Aug 19, 2026

Copy link
Copy Markdown
Collaborator

Fixes #9254

What happens today

install.sh runs under set -e, and the PATH-persistence helpers append to the user's shell profile with unguarded echo >> "$file". A profile the user cannot write — root-owned dotfiles, managed machines, immutable distributions, container images — therefore ends the installer. The EXIT trap 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:

  ────────────────────────────────────────────────────
  Unsloth Studio Installed
  ────────────────────────────────────────────────────
  launch         unsloth studio -p 8888

./install.sh: line 5537: /home/<user>/.zshrc: Permission denied
                 restoring previous environment after failed install...
                 restored previous environment

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 fish conf.d appends, the rc appends (once for ~/.local/bin, up to six more in the uv loop), and create_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/bin that already holds this run's shim is not a failed install. ln -sfn cannot 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 the unsloth command does not exist — but now says why and gives the absolute command to start Studio with.

Deliberately not changed

create_studio_shortcuts is 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 disables errexit throughout 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 ignores SIGINT with 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.ps1 needs no equivalent change: Add-ToUserPath is wrapped in try/catch and returns $false, and PowerShell has no set -e.

Validation

$ bash tests/sh/test_install_rollback_lifecycle.sh
  PASS: 40
  FAIL: 0
ALL PASSED

New coverage in tests/sh/test_install_rollback_lifecycle.sh runs 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:

  • an unwritable ~/.zshrc and an unwritable fish conf.d file: the install survives, the profile is untouched, the user is told, and the profiles that can be written still get their entry;
  • a real directory at the shim path: the refusal still happens and the committed environment survives it;
  • a read-only bin directory holding an absolute link, a relative link, an unrelated command, and a link that names the right path but resolves nowhere.

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, and sh -n / dash -n / bash -n on the installer.

Lyxot added 2 commits August 19, 2026 15:40
… 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.
@Lyxot
Lyxot requested a review from danielhanchen as a code owner August 19, 2026 07:41
@Lyxot

Lyxot commented Aug 19, 2026

Copy link
Copy Markdown
Collaborator 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: 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".

@chatgpt-codex-connector

Copy link
Copy Markdown

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

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

@danielhanchen

Copy link
Copy Markdown
Member

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.

@chatgpt-codex-connector

Copy link
Copy Markdown

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

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

chatgpt-codex-connector[bot]

This comment was marked as resolved.

@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Aug 24, 2026
@chatgpt-codex-connector

Copy link
Copy Markdown

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

Reviewed commit: d6f32b5816

ℹ️ 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 Aug 24, 2026
@unslothai unslothai deleted a comment from Lyxot Aug 24, 2026
@oobabooga

Copy link
Copy Markdown
Member

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.

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.

[Bug] Installer rolls back the venv after a successful install when the shell profile is not writable

3 participants