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
Studio: tell the operator what the refusal path will actually do
danielhanchenad6904445671
diff --git a/studio/backend/run.py b/studio/backend/run.pyindex e5a98de78e9..09fce7ab92c 100644--- a/studio/backend/run.py+++ b/studio/backend/run.py@@ -2343,13 +2343,40 @@ def _terminal_password_gate(# case (docker/studio_run.sh execs `unsloth studio -H 0.0.0.0` and only# supplies a password when the initial-password file is non-empty), so# aborting would stop a container that starts today. Warn and proceed at the- # protection level this launch already had: the bootstrap deadline.+ # protection level this launch already had.+ #+ # Which is sometimes NO protection: with UNSLOTH_STUDIO_BOOTSTRAP_TIMEOUT=0+ # the deadline never arms, so promising a shutdown would be false, and it is+ # the one sentence an operator would act on. Say what will actually happen.+ # Still proceed rather than fail closed: this launch worked before the prompt+ # existed, the operator disabled the deadline deliberately and cancelled the+ # prompt deliberately, and refusing to start would break the very case the+ # paragraph above exists to protect.+ deadline_arms = should_arm_bootstrap_timeout(+ host = host,+ secure = secure,+ api_only = api_only,+ frontend_served = frontend_served,+ is_colab = is_colab,+ requires_change = True,+ timeout_seconds = bootstrap_timeout_seconds(),+ )+ if deadline_arms:+ tail = (+ "Unsloth shuts down after the bootstrap deadline "+ "(UNSLOTH_STUDIO_BOOTSTRAP_TIMEOUT, default 1h) unless the password "+ "is changed."+ )+ else:+ tail = (+ "The bootstrap shutdown deadline is DISABLED for this launch "+ "(UNSLOTH_STUDIO_BOOTSTRAP_TIMEOUT=0), so nothing will stop it "+ "serving that credential."+ )print(" WARNING: continuing with the auto-generated admin password on a bind "- "that is reachable from the network. Unsloth shuts down after the "- "bootstrap deadline (UNSLOTH_STUDIO_BOOTSTRAP_TIMEOUT, default 1h) "- "unless the password is changed. Change it by logging in, or with "- "`unsloth studio reset-password`.",+ f"that is reachable from the network. {tail} Change it by logging in, or "+ "with `unsloth studio reset-password`.",file = sys.stderr,flush = True,)diff --git a/studio/backend/tests/test_password_prompt_backstop.py b/studio/backend/tests/test_password_prompt_backstop.pyindex 82803caa9b2..d01f1122086 100644--- a/studio/backend/tests/test_password_prompt_backstop.py+++ b/studio/backend/tests/test_password_prompt_backstop.py@@ -755,3 +755,44 @@ def test_the_gate_deadlines_a_raw_bind_prompt_and_never_the_tunnel(monkeypatch):_patch_seeded_admin(monkeypatch, requires_change = True)run._terminal_password_gate(tunnel_will_start = True, **_GATE_KWARGS)assert seen["first_key_timeout"] is None+++def test_a_refusal_does_not_promise_a_deadline_that_is_disabled(monkeypatch):+ """With TIMEOUT=0 nothing will shut this instance down; do not say otherwise.++ The refusal path proceeds on purpose, because the launch worked before the+ prompt existed. What it must not do is tell the operator a deadline will+ rescue them when `should_arm_bootstrap_timeout` will not arm one: that is the+ single sentence they would act on.+ """+ monkeypatch.setenv("UNSLOTH_STUDIO_BOOTSTRAP_TIMEOUT", "0")+ stderr = _patch_streams(monkeypatch, tty = True)+ _patch_seeded_admin(monkeypatch, requires_change = True)++ from auth import terminal_prompt+ monkeypatch.setattr(terminal_prompt, "prompt_for_password_change",+ lambda **_kw: False)++ assert run._terminal_password_gate(+ tunnel_will_start = False, **_RAW_BIND_KWARGS+ ) == (True, False)+ err = stderr.getvalue()+ assert "DISABLED for this launch" in err, err+ assert "shuts down after the bootstrap deadline" not in err, err+++def test_a_refusal_still_names_the_deadline_when_one_will_arm(monkeypatch):+ monkeypatch.delenv("UNSLOTH_STUDIO_BOOTSTRAP_TIMEOUT", raising = False)+ stderr = _patch_streams(monkeypatch, tty = True)+ _patch_seeded_admin(monkeypatch, requires_change = True)++ from auth import terminal_prompt+ monkeypatch.setattr(terminal_prompt, "prompt_for_password_change",+ lambda **_kw: False)++ assert run._terminal_password_gate(+ tunnel_will_start = False, **_RAW_BIND_KWARGS+ ) == (True, False)+ err = stderr.getvalue()+ assert "shuts down after the bootstrap deadline" in err, err+ assert "DISABLED" not in err, errdiff --git a/unsloth_cli/commands/studio.py b/unsloth_cli/commands/studio.pyindex a26220619d6..1472d68c6f3 100644--- a/unsloth_cli/commands/studio.py+++ b/unsloth_cli/commands/studio.py@@ -1640,7 +1640,14 @@ def _enforce_password_change_before_exposure(# bind is every network interface, which is the LAN behind a NAT router and# the internet on a cloud box. Naming the wrong one in an error trains people# to ignore it, and would be plainly wrong for `unsloth studio -H 0.0.0.0`.- tunnel_will_start = secure or cloudflare is True+ # The real predicate, not `cloudflare is True`. A non-secure tunnel only+ # starts for a wildcard host, so `--cloudflare -H 192.168.1.50` starts no+ # tunnel and is reachable through the raw bind instead. Naming the wrong one+ # here would tell the operator their credential is about to go on a public+ # Cloudflare URL when it is not, in the one message they are meant to act on.+ tunnel_will_start = _launch_publishes_tunnel(+ cloudflare = cloudflare, host = host, secure = secure, api_only = api_only+ )exposure = "on a public Cloudflare URL" if tunnel_will_start else "on every network interface"# Before public exposure we must PROVE the admin password is no longer the# seeded default. If we cannot (auth DB won't open, or a fresh admin cannot bediff --git a/unsloth_cli/tests/test_studio_password_prompt.py b/unsloth_cli/tests/test_studio_password_prompt.pyindex 6a84774d7ab..f42e885a1b6 100644--- a/unsloth_cli/tests/test_studio_password_prompt.py+++ b/unsloth_cli/tests/test_studio_password_prompt.py@@ -1989,3 +1989,36 @@ def test_read_masked_gives_up_on_a_pty_nobody_types_into(monkeypatch):finally:os.close(master)os.close(slave)+++ "cloudflare,host,secure,expect_tunnel_wording",+ [+ # --secure always publishes a tunnel.+ (None, "127.0.0.1", True, True),+ # --cloudflare tunnels only WILDCARD hosts...+ (True, "0.0.0.0", False, True),+ # ...so a concrete bind is reachable through the raw socket, not a URL.+ (True, "192.168.1.50", False, False),+ (True, "example.com", False, False),+ # No tunnel requested at all.+ (None, "0.0.0.0", False, False),+ (None, "192.168.1.50", False, False),+ ],+)+def test_the_exposure_wording_matches_what_will_actually_happen(+ monkeypatch, tmp_path, cloudflare, host, secure, expect_tunnel_wording+):+ """The prompt must not claim a public Cloudflare URL that never starts.++ `--cloudflare -H 192.168.1.50` requests a tunnel that _launch_publishes_tunnel+ will not start, because a non-secure tunnel needs a wildcard host. Deriving the+ message from the request rather than the predicate told the operator their+ credential was about to go on a public URL when it was going on the LAN.+ """+ studio_mod = _studio()+ monkeypatch.setattr(studio_mod, "_prompt_streams_interactive", lambda: True)+ tunnel = studio_mod._launch_publishes_tunnel(+ cloudflare = cloudflare, host = host, secure = secure, api_only = False+ )+ assert tunnel is expect_tunnel_wording