Local UI to run and train LLMs and diffusion models. Supports GGUF, MLX, Qwen3.8, DeepSeek-V4.1, MiniMax-H3, Gemma 4, FLUX and more.
Python agentaichatgptdeepseekfine-tuninggemmaimage-generationllamallmllmsopenaipythonqwenreinforcement-learningself-hostedstable-diffusiontext-to-speechttsuiunsloth
Uninstall the whisper.cpp prebuilt and the node/whisper install locks (#7686)
Daniel Han425c9081a33a
diff --git a/.github/workflows/studio-update-smoke.yml b/.github/workflows/studio-update-smoke.ymlindex 047840e41cf..ef82f2ec292 100644--- a/.github/workflows/studio-update-smoke.yml+++ b/.github/workflows/studio-update-smoke.yml@@ -206,6 +206,10 @@ jobs:leak=0for p in \"$HOME/.unsloth/studio" \+ "$HOME/.unsloth/whisper.cpp" \+ "$HOME/.unsloth/.llama.cpp.install.lock" \+ "$HOME/.unsloth/.node.install.lock" \+ "$HOME/.unsloth/.whisper.cpp.install.lock" \"$HOME/.local/share/unsloth" \"$HOME/Desktop/Unsloth Studio.desktop" \"$HOME/.local/bin/unsloth"; do@@ -215,6 +219,16 @@ jobs:leak=$((leak + 1))fidone+ # Catch-all that does not need updating when a new artifact is added:+ # nothing but Unsloth writes under ~/.unsloth on a runner, so a+ # surviving directory means the uninstaller missed something. This is+ # what caught the node/whisper install locks, which individually look+ # harmless but keep the uninstaller's rmdir from pruning ~/.unsloth.+ if [ -d "$HOME/.unsloth" ]; then+ echo "::error::leak: ~/.unsloth survived the uninstall"+ find "$HOME/.unsloth" | head -40+ leak=$((leak + 1))+ fi[ "$leak" -eq 0 ] || exit 1# Idempotent: re-runs exit 0 on an empty $HOME.sh scripts/uninstall.sh 2>&1 | tail -5diff --git a/.github/workflows/studio-windows-update-smoke.yml b/.github/workflows/studio-windows-update-smoke.ymlindex 6751c452813..80cc5a1f9ba 100644--- a/.github/workflows/studio-windows-update-smoke.yml+++ b/.github/workflows/studio-windows-update-smoke.yml@@ -313,13 +313,27 @@ jobs:foreach ($p in @("$env:USERPROFILE\.unsloth\studio","$env:USERPROFILE\.unsloth\studio\unsloth_studio",- "$env:USERPROFILE\.unsloth\studio\bin\unsloth.exe"+ "$env:USERPROFILE\.unsloth\studio\bin\unsloth.exe",+ "$env:USERPROFILE\.unsloth\whisper.cpp",+ "$env:USERPROFILE\.unsloth\.llama.cpp.install.lock",+ "$env:USERPROFILE\.unsloth\.node.install.lock",+ "$env:USERPROFILE\.unsloth\.whisper.cpp.install.lock")) {if (Test-Path -LiteralPath $p) {Write-Host "::error::leak: $p"$leak++}}+ # Catch-all that does not need updating when a new artifact is added:+ # nothing but Unsloth writes under ~/.unsloth on a runner, so a+ # surviving directory means the uninstaller missed something. Mirrors+ # the POSIX check in studio-update-smoke.yml.+ if (Test-Path -LiteralPath "$env:USERPROFILE\.unsloth") {+ Write-Host "::error::leak: ~/.unsloth survived the uninstall"+ Get-ChildItem -LiteralPath "$env:USERPROFILE\.unsloth" -Force -Recurse -ErrorAction SilentlyContinue |+ Select-Object -First 40 -ExpandProperty FullName+ $leak+++ }if ($leak -gt 0) { exit 1 }# Idempotency.pwsh -NoProfile -File "$PWD\scripts\uninstall.ps1" *>&1 | Select-Object -Last 5diff --git a/scripts/uninstall.ps1 b/scripts/uninstall.ps1index 4a59dac8a07..d0c86c9f581 100644--- a/scripts/uninstall.ps1+++ b/scripts/uninstall.ps1@@ -20,7 +20,10 @@ Usage:Stops running Unsloth Studio servers, then removes the install dir, launcherdata, CLI shim, desktop and Start Menu shortcuts, the user PATH entry and the-PathBackup registry key. The Hugging Face cache is left in place.+PathBackup registry key. In a default-mode install it also removes the shared+prebuilts that sit beside the install dir:+%USERPROFILE%\.unsloth\{llama.cpp,node,whisper.cpp,.cache}. The Hugging Face+cache is left in place, as is anything else you keep under %USERPROFILE%\.unsloth.Options:-Help, -h, --help, -?, /? Print this message and exit without removing anything.@@ -375,6 +378,10 @@ Environment:# build can leave a "<name>.staging-XXXX" tree; removing it lets the empty-dir# cleanup of ~/.unsloth below succeed. No-op in env/custom mode and when absent.$defaultStaging = if ($defaultUnslothHome) { Join-Path $defaultUnslothHome ".staging" } else { $null }+ # Managed whisper.cpp dictation engine (setup.ps1 PHASE 3.4 installs it at+ # $UnslothHome\whisper.cpp), a sibling of studio in default mode. No-op in+ # env/custom mode (nested under the custom root) and when absent.+ $defaultWhisperCpp = if ($defaultUnslothHome) { Join-Path $defaultUnslothHome "whisper.cpp" } else { $null }# Build known-root list FIRST so the port-file kill can verify ownership.$customRoots = @(_CustomStudioRoots)@@ -393,7 +400,7 @@ Environment:_StopStudioProcesses -KnownRoots $knownRoots# Also stop anything holding a handle on the exact paths we delete (llama-server,# the CLI shim, an mp-fork python with a venv DLL) so the dir delete isn't refused.- _StopProcessesLockingRoots -Roots (@($knownRoots) + @($defaultDataDir, $defaultLlamaCpp, $defaultCache, $defaultNode))+ _StopProcessesLockingRoots -Roots (@($knownRoots) + @($defaultDataDir, $defaultLlamaCpp, $defaultCache, $defaultNode, $defaultWhisperCpp))# ── Remove custom-root install trees ──_Step "Removing data and install directories..."@@ -420,9 +427,30 @@ Environment:# custom mode (nested under the custom root, removed with it) and when absent.if ($defaultNode) { _RemovePath $defaultNode }if ($defaultStaging) { _RemovePath $defaultStaging }- # llama.cpp install lock (serializes the shared build); a stray lock keeps+ # Managed whisper.cpp prebuilt (sibling of studio under ~/.unsloth). Only+ # present when a whisper prebuilt matching the pinned llama.cpp build existed+ # at install time, so many installs lack it.+ if ($defaultWhisperCpp) { _RemovePath $defaultWhisperCpp }+ # Prebuilt install locks. Every prebuilt serializes on+ # <parent>\.<name>.install.lock (prebuilt_core.py install_lock_path), so+ # llama.cpp, node and whisper.cpp each leave one; a stray lock keeps# ~/.unsloth from being pruned below. No-op in env/custom mode and when absent.- if ($defaultUnslothHome) { _RemovePath (Join-Path $defaultUnslothHome ".llama.cpp.install.lock") }+ if ($defaultUnslothHome) {+ foreach ($lockName in @(".llama.cpp.install.lock", ".node.install.lock", ".whisper.cpp.install.lock")) {+ _RemovePath (Join-Path $defaultUnslothHome $lockName)+ }+ # Taking over an abandoned lock renames it to .stale.<pid> before unlinking+ # (install_node_prebuilt.py); a crash between the two steps strands the+ # rename, so sweep any leftovers. -Force to see the dot-prefixed names.+ if (Test-Path -LiteralPath $defaultUnslothHome) {+ # -like, not -Filter: the provider's Win32 filter is unreliable for+ # dot-leading names with several dots.+ foreach ($stale in @(Get-ChildItem -LiteralPath $defaultUnslothHome -Force -ErrorAction SilentlyContinue |+ Where-Object { $_.Name -like "*.install.lock.stale.*" })) {+ _RemovePath $stale.FullName+ }+ }+ }# Drop ~/.unsloth itself, but ONLY if now empty -- never nuke unrelated content.if ($defaultUnslothHome -and (Test-Path -LiteralPath $defaultUnslothHome) -and-not (Get-ChildItem -LiteralPath $defaultUnslothHome -Force -ErrorAction SilentlyContinue)) {diff --git a/scripts/uninstall.sh b/scripts/uninstall.shindex f759b9cdffb..04f7eae6423 100755--- a/scripts/uninstall.sh+++ b/scripts/uninstall.sh@@ -28,7 +28,10 @@ is not (dash, busybox sh) the shell exits with "Illegal option -h".Stops running Unsloth Studio servers, then removes the install dir, launcherdata dir, CLI shim, desktop shortcut, macOS .app bundle and Launch Services-entry. The Hugging Face cache at ~/.cache/huggingface is left in place.+entry. In a default-mode install it also removes the shared prebuilts that sit+beside the install dir: ~/.unsloth/{llama.cpp,node,whisper.cpp,.cache}. The+Hugging Face cache at ~/.cache/huggingface is left in place, as is anything+else you keep under ~/.unsloth.On WSL it also removes this distro's Windows-side shortcuts under /mnt/*/Users,strips the Unsloth block from ~/.bashrc, and uses sudo to delete@@ -274,9 +277,24 @@ _unsloth_uninstall_main() {# Normally pruned after activate, but an interrupted build can leave it behind;# removing it lets the rmdir below succeed. No-op in env/custom mode and absent._remove_path "$HOME/.unsloth/.staging"- # llama.cpp install lock (serializes the shared build); a stray one keeps ~/.unsloth- # from being pruned below. No-op in env/custom mode and when absent.+ # Managed whisper.cpp dictation engine (install_whisper_prebuilt.py), a sibling+ # of studio in default mode. Only present when a whisper prebuilt matching the+ # pinned llama.cpp build existed at install time, so many installs lack it.+ _remove_path "$HOME/.unsloth/whisper.cpp"+ # Prebuilt install locks. Every prebuilt serializes on+ # <parent>/.<name>.install.lock (prebuilt_core.py:1129), so llama.cpp, node and+ # whisper.cpp each leave one; a stray lock keeps ~/.unsloth from being pruned+ # below. No-op in env/custom mode and when absent._remove_path "$HOME/.unsloth/.llama.cpp.install.lock"+ _remove_path "$HOME/.unsloth/.node.install.lock"+ _remove_path "$HOME/.unsloth/.whisper.cpp.install.lock"+ # Taking over an abandoned lock renames it to .stale.<pid> before unlinking+ # (install_node_prebuilt.py); a crash between the two steps strands the rename,+ # and a stranded one blocks the rmdir below. Unmatched globs stay literal,+ # hence the existence test.+ for _stale in "$HOME"/.unsloth/.*.install.lock.stale.*; do+ [ -e "$_stale" ] && _remove_path "$_stale"+ done# ROCm-on-WSL helper artifacts (librocdxg build clone + smoke-test venv). No-op# where they don't exist; removing them lets the rmdir below succeed._remove_path "$HOME/.unsloth/librocdxg"diff --git a/tests/sh/test_uninstall_prebuilt_artifacts.sh b/tests/sh/test_uninstall_prebuilt_artifacts.shnew file mode 100644index 00000000000..b6cca4c4b99--- /dev/null+++ b/tests/sh/test_uninstall_prebuilt_artifacts.sh@@ -0,0 +1,137 @@+#!/bin/bash+# SPDX-License-Identifier: AGPL-3.0-only+# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0+# scripts/uninstall.sh must remove the prebuilt siblings of ~/.unsloth/studio,+# then prune ~/.unsloth itself.+#+# Each prebuilt serializes on <parent>/.<name>.install.lock (prebuilt_core.py+# install_lock_path), so llama.cpp, node and whisper.cpp each leave one behind.+# A stray lock is a zero-byte file that looks harmless, but the final+# `rmdir "$HOME/.unsloth"` refuses a non-empty directory, so one missed lock+# keeps the whole tree on disk. whisper.cpp only installs when a prebuilt+# matching the pinned llama.cpp build exists, so a live install often skips it+# and never exercises that path; the fixture below always creates it.+#+# The uninstaller runs for real against a fixture HOME, so this asserts the+# removal OUTCOME rather than the presence of a line in the script.+set -e++SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"+UNINSTALL_SH="$SCRIPT_DIR/../../scripts/uninstall.sh"+PASS=0+FAIL=0++# This suite runs the REAL uninstaller, and overriding HOME does not contain it+# on WSL: the body detects WSL from /proc/version and then reaches host state+# outside the fixture -- powershell.exe deletes Windows-side "Unsloth Studio*.lnk"+# shortcuts and the shared unsloth.ico (uninstall.sh WSL branch), the interop-off+# fallback scans /mnt/{c,d,e}/Users, and `sudo rm -f /etc/profile.d/unsloth-rocm-wsl.sh`+# touches the system. Skip there, exactly like tests/sh/test_uninstall_arg_guard.sh.+if grep -qi microsoft /proc/version 2>/dev/null; then+ echo " SKIP: WSL -- the uninstall body reaches Windows-side state outside the fixture"+ exit 0+fi++_TMP_ROOT=$(mktemp -d)+trap 'rm -rf "$_TMP_ROOT"' EXIT++# Isolate every environment-controlled removal path.+unset UNSLOTH_STUDIO_HOME STUDIO_HOME UNSLOTH_UNINSTALL_ROCM+XDG_RUNTIME_DIR="$_TMP_ROOT/run"+export XDG_RUNTIME_DIR+mkdir -p "$XDG_RUNTIME_DIR"++assert_gone() {+ if [ -e "$2" ] || [ -L "$2" ]; then+ echo " FAIL: $1 (still present: $2)"; FAIL=$((FAIL + 1))+ else+ echo " PASS: $1"; PASS=$((PASS + 1))+ fi+}++assert_kept() {+ if [ -e "$2" ] || [ -L "$2" ]; then+ echo " PASS: $1"; PASS=$((PASS + 1))+ else+ echo " FAIL: $1 (missing: $2)"; FAIL=$((FAIL + 1))+ fi+}++# A default-mode install plus every sibling artifact the prebuilt installers+# can leave under ~/.unsloth. Explicit mktemp template: BSD mktemp with no+# template implies -t and would land outside _TMP_ROOT on macOS.+make_home() {+ FIXTURE_HOME=$(mktemp -d "$_TMP_ROOT/home.XXXXXX")+ mkdir -p "$FIXTURE_HOME/.unsloth/studio/unsloth_studio/bin" \+ "$FIXTURE_HOME/.unsloth/llama.cpp/build/bin" \+ "$FIXTURE_HOME/.unsloth/node/bin" \+ "$FIXTURE_HOME/.unsloth/whisper.cpp/build/bin" \+ "$FIXTURE_HOME/.unsloth/.cache" \+ "$FIXTURE_HOME/.unsloth/.staging" \+ "$FIXTURE_HOME/.local/share/unsloth" \+ "$FIXTURE_HOME/.local/bin"+ : > "$FIXTURE_HOME/.unsloth/studio/unsloth_studio/bin/unsloth"+ : > "$FIXTURE_HOME/.unsloth/studio/unsloth_studio/.unsloth-studio-owned"+ : > "$FIXTURE_HOME/.unsloth/llama.cpp/build/bin/llama-server"+ : > "$FIXTURE_HOME/.unsloth/node/bin/node"+ : > "$FIXTURE_HOME/.unsloth/whisper.cpp/build/bin/whisper-server"+ : > "$FIXTURE_HOME/.unsloth/.llama.cpp.install.lock"+ : > "$FIXTURE_HOME/.unsloth/.node.install.lock"+ : > "$FIXTURE_HOME/.unsloth/.whisper.cpp.install.lock"+ # Taking over an abandoned lock renames it rather than deleting it+ # (install_node_prebuilt.py), so these accumulate across interrupted runs.+ : > "$FIXTURE_HOME/.unsloth/.node.install.lock.stale.12345"+ : > "$FIXTURE_HOME/.unsloth/.llama.cpp.install.lock.stale.6789"+ ln -s "$FIXTURE_HOME/.unsloth/studio/unsloth_studio/bin/unsloth" \+ "$FIXTURE_HOME/.local/bin/unsloth"+}++echo "=== every prebuilt artifact is removed, then ~/.unsloth is pruned ==="++make_home+HOME="$FIXTURE_HOME" sh "$UNINSTALL_SH" > "$_TMP_ROOT/out.log" 2>&1 || {+ echo " FAIL: uninstall exited $?"; FAIL=$((FAIL + 1)); cat "$_TMP_ROOT/out.log"; }++assert_gone "studio install dir" "$FIXTURE_HOME/.unsloth/studio"+assert_gone "llama.cpp prebuilt" "$FIXTURE_HOME/.unsloth/llama.cpp"+assert_gone "node runtime" "$FIXTURE_HOME/.unsloth/node"+assert_gone "whisper.cpp prebuilt" "$FIXTURE_HOME/.unsloth/whisper.cpp"+assert_gone "prebuilt cache" "$FIXTURE_HOME/.unsloth/.cache"+assert_gone "staging dir" "$FIXTURE_HOME/.unsloth/.staging"+assert_gone "llama.cpp install lock" "$FIXTURE_HOME/.unsloth/.llama.cpp.install.lock"+assert_gone "node install lock" "$FIXTURE_HOME/.unsloth/.node.install.lock"+assert_gone "whisper.cpp install lock" "$FIXTURE_HOME/.unsloth/.whisper.cpp.install.lock"+assert_gone "stale node lock" "$FIXTURE_HOME/.unsloth/.node.install.lock.stale.12345"+assert_gone "stale llama.cpp lock" "$FIXTURE_HOME/.unsloth/.llama.cpp.install.lock.stale.6789"+assert_gone "~/.unsloth is pruned" "$FIXTURE_HOME/.unsloth"+assert_gone "CLI shim" "$FIXTURE_HOME/.local/bin/unsloth"++echo "=== user content under ~/.unsloth is never removed ==="++# rmdir refuses a non-empty directory, which is what protects user files. The+# uninstaller must still clear its own artifacts around them.+make_home+mkdir -p "$FIXTURE_HOME/.unsloth/my-own-models"+: > "$FIXTURE_HOME/.unsloth/my-own-models/keep-me.gguf"+: > "$FIXTURE_HOME/.unsloth/notes.txt"+HOME="$FIXTURE_HOME" sh "$UNINSTALL_SH" > "$_TMP_ROOT/out2.log" 2>&1 || {+ echo " FAIL: uninstall exited $?"; FAIL=$((FAIL + 1)); cat "$_TMP_ROOT/out2.log"; }++assert_kept "a user directory survives" "$FIXTURE_HOME/.unsloth/my-own-models/keep-me.gguf"+assert_kept "a user file survives" "$FIXTURE_HOME/.unsloth/notes.txt"+assert_kept "~/.unsloth kept for user content" "$FIXTURE_HOME/.unsloth"+assert_gone "artifacts still cleared" "$FIXTURE_HOME/.unsloth/whisper.cpp"+assert_gone "locks still cleared" "$FIXTURE_HOME/.unsloth/.node.install.lock"++echo "=== a missing ~/.unsloth is a clean no-op ==="++FIXTURE_HOME=$(mktemp -d "$_TMP_ROOT/empty.XXXXXX")+if HOME="$FIXTURE_HOME" sh "$UNINSTALL_SH" > "$_TMP_ROOT/out3.log" 2>&1; then+ echo " PASS: uninstalling a machine with no install exits 0"; PASS=$((PASS + 1))+else+ echo " FAIL: uninstalling a machine with no install exited $?"; FAIL=$((FAIL + 1))+fi++echo ""+echo "Results: $PASS passed, $FAIL failed"+[ "$FAIL" = 0 ]diff --git a/tests/studio/test_uninstall_prebuilt_parity.ps1 b/tests/studio/test_uninstall_prebuilt_parity.ps1new file mode 100644index 00000000000..35fecb78141--- /dev/null+++ b/tests/studio/test_uninstall_prebuilt_parity.ps1@@ -0,0 +1,63 @@+#!/usr/bin/env pwsh+# SPDX-License-Identifier: AGPL-3.0-only+# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0+# scripts/uninstall.ps1 must remove the same ~/.unsloth artifacts as scripts/uninstall.sh.+#+# The two uninstallers are maintained separately, so a prebuilt added to the+# POSIX side (whisper.cpp, the node/whisper install locks) silently keeps+# leaking on native Windows until someone notices. setup.ps1 installs+# whisper.cpp under %USERPROFILE%\.unsloth\whisper.cpp exactly like setup.sh,+# and a single surviving zero-byte lock keeps the empty-dir prune of+# ~/.unsloth from running, so the whole tree stays on disk.+#+# The uninstaller body kills processes and writes to the registry, so it cannot+# be executed here; this asserts PARITY of the artifact list instead, plus that+# uninstall.ps1 still parses.+#+# Run: pwsh -NoProfile -File tests/studio/test_uninstall_prebuilt_parity.ps1++$ErrorActionPreference = "Stop"+$repoRoot = (Resolve-Path ([System.IO.Path]::Combine($PSScriptRoot, "..", ".."))).Path+$shPath = [System.IO.Path]::Combine($repoRoot, "scripts", "uninstall.sh")+$ps1Path = [System.IO.Path]::Combine($repoRoot, "scripts", "uninstall.ps1")++$failures = 0+function Check($name, $cond) {+ if ($cond) { Write-Host " PASS $name" }+ else { Write-Host " FAIL $name" -ForegroundColor Red; $script:failures++ }+}++# uninstall.ps1 must parse (a syntax error would make every Windows uninstall a no-op).+$tokens = $null; $errors = $null+[System.Management.Automation.Language.Parser]::ParseFile($ps1Path, [ref]$tokens, [ref]$errors) | Out-Null+Check "uninstall.ps1 parses" ($null -eq $errors -or $errors.Count -eq 0)+if ($errors -and $errors.Count -gt 0) { $errors | ForEach-Object { Write-Host " $_" } }++$shText = Get-Content -LiteralPath $shPath -Raw+$ps1Text = Get-Content -LiteralPath $ps1Path -Raw++# Every `_remove_path "$HOME/.unsloth/<name>"` in the POSIX uninstaller. Only+# direct children: nested paths are removed with their parent.+$shArtifacts = [regex]::Matches($shText, '_remove_path\s+"\$HOME/\.unsloth/([^"/]+)"') |+ ForEach-Object { $_.Groups[1].Value } | Sort-Object -Unique+Check "found the POSIX artifact list" ($shArtifacts.Count -ge 5)++# WSL-only helpers have no native-Windows counterpart.+$wslOnly = @("librocdxg", "rocm-smoketest")+foreach ($artifact in $shArtifacts) {+ if ($wslOnly -contains $artifact) { continue }+ Check "uninstall.ps1 removes ~/.unsloth/$artifact" ($ps1Text -match [regex]::Escape($artifact))+}++# The stale-lock sweep must exist on both sides: a crash between the rename and+# the unlink in install_node_prebuilt.py strands a `.stale.<pid>` file, and that+# alone blocks the ~/.unsloth prune.+Check "uninstall.sh sweeps stale install locks" ($shText -match '\.install\.lock\.stale\.')+Check "uninstall.ps1 sweeps stale install locks" ($ps1Text -match '\.install\.lock\.stale\.')++# The prune must stay conditional on the dir being empty, so user content is kept.+Check "uninstall.ps1 prunes ~/.unsloth only when empty" `+ ($ps1Text -match 'Get-ChildItem -LiteralPath \$defaultUnslothHome')++if ($failures -gt 0) { Write-Host ""; Write-Host "FAILED ($failures)" -ForegroundColor Red; exit 1 }+Write-Host ""; Write-Host "All tests passed."; exit 0