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
Windows UI lane: retry the permission suite's auth wipe while the stopped server releases auth.db (#14658)
Daniel Han588e1c4ffefc
diff --git a/.github/scripts/run-studio-permission-browser.sh b/.github/scripts/run-studio-permission-browser.shindex cb8e085c7c8..462ed8627d9 100755--- a/.github/scripts/run-studio-permission-browser.sh+++ b/.github/scripts/run-studio-permission-browser.sh@@ -17,8 +17,29 @@ if [ -n "${STUDIO_PERMISSION_FRONTEND:-}" ]; thenfimkdir -p "$artifact_dir"++# The Windows UI lane calls this right after stopping its own server on the same home, and a+# killed server on Windows can hold auth.db open for a few seconds after `kill` returns. The+# wipe then failed with "Device or resource busy" and the lane went red after every suite had+# passed (runs 39669502772, staging 39764533102). Retry for a bounded time, then fail loudly.+wipe_auth() {+ local tries=0+ until rm -rf "$studio_home/auth" 2>/dev/null; do+ tries=$((tries + 1))+ if [ "$tries" -ge "${STUDIO_AUTH_WIPE_TRIES:-30}" ]; then+ # One last attempt with rm's own error showing; it can still be the one that succeeds.+ if rm -rf "$studio_home/auth"; then+ return 0+ fi+ echo "::error::$studio_home/auth is still held open after $((tries + 1)) tries; a server on this home did not exit" >&2+ return 1+ fi+ sleep 1+ done+}+# Wipe (not reset-password): the boot below must re-seed a fresh .bootstrap_password.-rm -rf "$studio_home/auth"+wipe_authUNSLOTH_API_ONLY=1 unsloth studio -H 127.0.0.1 -p "$port" "$@" \>"$server_log" 2>&1 &studio_pid=$!diff --git a/tests/studio/test_permission_browser_auth_wipe.py b/tests/studio/test_permission_browser_auth_wipe.pynew file mode 100644index 00000000000..4c7f761a0d3--- /dev/null+++ b/tests/studio/test_permission_browser_auth_wipe.py@@ -0,0 +1,106 @@+# SPDX-License-Identifier: AGPL-3.0-only+# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0++"""The permission wrapper waits for a just-stopped server to let go of auth.db.++The Windows UI lane stops its own server and then calls run-studio-permission-browser.sh on the+same UNSLOTH_STUDIO_HOME. A killed server on Windows can hold auth.db open for a few seconds, so+the wrapper's `rm -rf "$studio_home/auth"` failed with "Device or resource busy" and, under+`set -e`, failed the lane after every suite had passed (run 39669502772).+"""++from __future__ import annotations++import os+import re+import shutil+import subprocess+from pathlib import Path++import pytest++REPO = Path(__file__).resolve().parents[2]+SCRIPT = REPO / ".github" / "scripts" / "run-studio-permission-browser.sh"+BASH = shutil.which("bash")+++def _source() -> str:+ return SCRIPT.read_text(encoding = "utf-8")+++def _code(text: str) -> str:+ return "\n".join(re.sub(r"(^|\s)#.*$", "", line) for line in text.split("\n"))+++def _wipe_auth() -> str:+ match = re.search(r"^wipe_auth\(\) \{\n.*?^\}\n", _source(), re.M | re.S)+ assert match, "run-studio-permission-browser.sh no longer defines wipe_auth()"+ return match.group(0)+++def _run(tmp_path: Path, busy_calls: int, tries: int = 30) -> tuple[subprocess.CompletedProcess, int]:+ """Runs the script's wipe_auth with an rm that reports a busy file for its first calls."""+ assert BASH, "bash is required to run the wrapper's own code"+ shims = tmp_path / "bin"+ shims.mkdir()+ calls = tmp_path / "rm_calls"+ real_rm = shutil.which("rm")+ (shims / "rm").write_text(+ "#!/usr/bin/env bash\n"+ f'n=$(( $(cat "{calls}" 2>/dev/null || echo 0) + 1 )); echo "$n" > "{calls}"\n'+ f'if [ "$n" -le {busy_calls} ]; then\n'+ " echo \"rm: cannot remove 'auth/auth.db': Device or resource busy\" >&2; exit 1\n"+ "fi\n"+ f'exec "{real_rm}" "$@"\n',+ encoding = "utf-8",+ )+ (shims / "sleep").write_text("#!/usr/bin/env bash\nexit 0\n", encoding = "utf-8")+ for shim in shims.iterdir():+ shim.chmod(0o755)+ home = tmp_path / "home"+ (home / "auth").mkdir(parents = True)+ (home / "auth" / "auth.db").write_text("x", encoding = "utf-8")+ body = f'set -euo pipefail\nstudio_home="{home}"\n{_wipe_auth()}wipe_auth\necho wiped\n'+ env = dict(os.environ, PATH = f"{shims}{os.pathsep}{os.environ['PATH']}")+ env["STUDIO_AUTH_WIPE_TRIES"] = str(tries)+ result = subprocess.run(+ [BASH, "-c", body], env = env, capture_output = True, text = True, timeout = 60+ )+ return result, int(calls.read_text())+++def test_a_briefly_held_auth_dir_is_wiped_once_released(tmp_path):+ result, calls = _run(tmp_path, busy_calls = 4)+ assert result.returncode == 0, result.stderr+ assert "wiped" in result.stdout+ assert calls == 5+ assert not (tmp_path / "home" / "auth").exists()+++def test_an_auth_dir_that_stays_held_fails_loudly(tmp_path):+ result, calls = _run(tmp_path, busy_calls = 99, tries = 5)+ assert result.returncode != 0+ assert "wiped" not in result.stdout+ assert "still held open" in result.stderr+ assert calls == 6, "five quiet tries and one final attempt that prints rm's own error"+ assert "Device or resource busy" in result.stderr+++def test_a_release_on_the_final_attempt_is_a_success(tmp_path):+ result, calls = _run(tmp_path, busy_calls = 5, tries = 5)+ assert result.returncode == 0, result.stderr+ assert "wiped" in result.stdout+ assert calls == 6+ assert not (tmp_path / "home" / "auth").exists()+++def test_the_wrapper_wipes_only_through_the_retry_before_booting():+ code = _code(_source())+ helper = _code(_wipe_auth())+ outside = code.replace(helper, "")+ assert not re.search(r"rm -rf \"\$studio_home/auth\"", outside), (+ "a bare rm of $studio_home/auth fails the lane while the previous server still holds auth.db"+ )+ calls = [m.start() for m in re.finditer(r"^wipe_auth\s*$", code, re.M)]+ boot = code.index("unsloth studio -H")+ assert calls and calls[0] < boot, "the auth dir must be wiped before the server boots"