Skip to content

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.

Studio: stop the prompt waiting twice, and say what it will really do

Daniel Han779f976e2fdf
diff --git a/studio/backend/auth/terminal_prompt.py b/studio/backend/auth/terminal_prompt.py
index a3358517bab..dff56bfd475 100644
--- a/studio/backend/auth/terminal_prompt.py
+++ b/studio/backend/auth/terminal_prompt.py
@@ -277,11 +277,16 @@ def prompt_for_password_change(
out: "TextIO | None" = None,
exposure: str = "on the public internet",
first_key_timeout: "float | None" = None,
+ refusal_aborts: bool = True,
) -> bool:
"""Force a new admin password before exposure; True on success.
Loops until a valid, confirmed password is committed via ``apply_change``.
- Ctrl-C / EOF returns False; the caller must then abort the launch.
+ Ctrl-C / EOF returns False. What that means is the caller's decision, and
+ ``refusal_aborts`` says which one it made so the banner can say the same
+ thing: True for a tunnel, where the caller aborts the launch, False for a raw
+ bind, where the launch proceeds because it worked before this prompt existed.
+ Promising an abort that will not happen is worse than not asking at all.
``exposure`` names where this launch will be reachable. A tunnel really is
the public internet; a raw ``-H 0.0.0.0`` bind is every network interface,
@@ -296,10 +301,15 @@ def prompt_for_password_change(
"""
if out is None:
out = sys.stderr
+ refusal = (
+ "Ctrl+C to abort."
+ if refusal_aborts
+ else "Ctrl+C to skip, and Unsloth starts with the auto-generated password."
+ )
out.write(
"\n"
f"Unsloth Studio will be reachable {exposure}, so set a\n"
- "password now. Ctrl+C to abort.\n\n"
+ f"password now. {refusal}\n\n"
)
out.flush()
# Only the first read is deadlined; once a key arrives someone is there.
@@ -340,7 +350,11 @@ def prompt_for_password_change(
out.flush()
return False
except (KeyboardInterrupt, EOFError):
- out.write("Password change aborted; not exposing Unsloth.\n")
+ out.write(
+ "Password change aborted; not exposing Unsloth.\n"
+ if refusal_aborts
+ else "Password change skipped; leaving the auto-generated admin password in place.\n"
+ )
out.flush()
return False
diff --git a/studio/backend/run.py b/studio/backend/run.py
index cd81a737c15..30d2143fc0e 100644
--- a/studio/backend/run.py
+++ b/studio/backend/run.py
@@ -2167,6 +2167,21 @@ def _prompt_owns_the_terminal() -> bool:
return True
+def _exposure_phrase(*, tunnel_will_start: bool, host: str) -> str:
+ """Name where this launch will actually be reachable.
+
+ A tunnel really is the public internet. A wildcard bind really is every
+ interface. A CONCRETE bind such as `-H 192.168.1.50` is neither: uvicorn
+ listens on that one address, so claiming every interface is untrue, and the
+ operator is more likely to act on the address they typed than on a category.
+ """
+ if tunnel_will_start:
+ return "on the public internet"
+ if is_wildcard_host(host):
+ return "on every network interface"
+ return f"at {host}, which other machines on the network can reach"
+
+
def _terminal_password_gate(
*,
tunnel_will_start: bool,
@@ -2328,7 +2343,11 @@ def _terminal_password_gate(
is_current_password = _is_current_password,
apply_change = _apply_change,
out = sys.stderr,
- exposure = ("on the public internet" if tunnel_will_start else "on every network interface"),
+ exposure = _exposure_phrase(tunnel_will_start = tunnel_will_start, host = host),
+ # Ctrl+C aborts a tunnel launch and only a tunnel launch. On a raw bind it
+ # declines the prompt and the launch continues, so the banner must not
+ # promise an abort that will not happen.
+ refusal_aborts = tunnel_will_start,
# A raw bind must never block a launch that used to start. A detached pty
# (`tmux new -d`, `screen -dmS`, `docker run -dt`) passes every isatty and
# process-group test yet nobody will ever type, so an undeadlined read
diff --git a/unsloth_cli/commands/studio.py b/unsloth_cli/commands/studio.py
index d6118dfb612..6381aeca025 100644
--- a/unsloth_cli/commands/studio.py
+++ b/unsloth_cli/commands/studio.py
@@ -1194,6 +1194,18 @@ def _launch_publishes_tunnel(
return is_wildcard_host(host) and not api_only
+def _bind_is_wildcard(host: str) -> bool:
+ """Whether this bind really is every interface, rather than one address.
+
+ Only used to word the prompt. `_launch_publishes_tunnel` above has already
+ called `is_wildcard_host` on this same launch, so the getaddrinfo it does for
+ a non-literal host is not a new cost on the path.
+ """
+ from unsloth_cli._tool_policy import is_wildcard_host
+
+ return is_wildcard_host(host)
+
+
def _should_prompt_password_change(
*, cloudflare: Optional[bool], host: str, secure: bool, api_only: bool
) -> bool:
@@ -1673,7 +1685,29 @@ def _enforce_password_change_before_exposure(
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"
+ if not tunnel_will_start and os.environ.get(_UNATTENDED_PROMPT_DONE_ENV):
+ # An outer CLI already sat at this terminal for the full deadline and
+ # nobody typed. `unsloth studio run` re-execs into the studio venv and
+ # re-enters this gate, so without this the SAME unattended pty is waited
+ # on again: 30s becomes 60s before the backend gate even gets its turn,
+ # which is long enough to trip a startup watchdog. The default admin was
+ # committed by the parent before it set this, so there is nothing left to
+ # do here. Peeked, never popped: run.py pops it, and consuming it here
+ # would hand the backend a fresh 30s wait instead.
+ #
+ # Never for a tunnel. That launch fails closed, and a marker set by some
+ # earlier raw-bind attempt must not buy a public URL a free pass.
+ return
+ if tunnel_will_start:
+ exposure = "on a public Cloudflare URL"
+ elif _bind_is_wildcard(host):
+ exposure = "on every network interface"
+ else:
+ # A concrete bind such as `-H 192.168.1.50` or `-H myhost.local` listens on
+ # that address ONLY, so "every network interface" is simply untrue. The gate
+ # widened to is_external_host and routes these here too; naming what the
+ # operator actually typed is both accurate and more useful than a category.
+ exposure = f"at {host}, which other machines on the network can reach"
# 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 be
# seeded + committed below), an old studio-venv child could regenerate a fresh
@@ -1822,9 +1856,18 @@ def _enforce_password_change_before_exposure(
_pbkdf2_hex(candidate, password_salt.encode("utf-8")), password_hash
)
+ # Ctrl+C aborts a TUNNEL launch and only a tunnel launch. On a raw bind it
+ # declines the prompt and the launch continues, because that launch worked
+ # before this gate existed and must not start failing now. Saying "abort"
+ # there would leave an operator believing they had stopped a server that is
+ # in fact up on the network with the auto-generated password.
+ refusal = (
+ "Ctrl+C to abort."
+ if tunnel_will_start
+ else "Ctrl+C to skip, and Unsloth starts with the auto-generated password."
+ )
typer.echo(
- f"Unsloth Studio will be reachable {exposure}, so set a "
- "password now. Ctrl+C to abort.",
+ f"Unsloth Studio will be reachable {exposure}, so set a password now. {refusal}",
err = True,
)
try:
diff --git a/unsloth_cli/tests/test_studio_password_prompt.py b/unsloth_cli/tests/test_studio_password_prompt.py
index c942e9bb855..687d32990a9 100644
--- a/unsloth_cli/tests/test_studio_password_prompt.py
+++ b/unsloth_cli/tests/test_studio_password_prompt.py
@@ -32,6 +32,20 @@ def _studio():
_BASE = ["--model", "unsloth/Qwen3-1.7B-GGUF"]
+
+
[email protected](autouse = True)
+def _no_leaked_unattended_marker(monkeypatch):
+ """Start every test with the unattended marker unset.
+
+ The gate writes it straight into os.environ, which is exactly right in
+ production (it is inherited across the re-exec and nowhere else) and exactly
+ wrong in a test process, where it then survives into every later test and
+ silently suppresses the very prompt they are asserting on.
+ """
+ import unsloth_cli.commands.studio as studio_mod
+
+ monkeypatch.delenv(studio_mod._UNATTENDED_PROMPT_DONE_ENV, raising = False)
_NEW_PW = "brand-new-password"
@@ -2146,3 +2160,110 @@ def test_a_tunnel_ctrl_c_still_aborts(monkeypatch, tmp_path):
studio_mod._enforce_password_change_before_exposure(
cloudflare = None, host = "127.0.0.1", secure = True, api_only = False
)
+
+
+def test_a_second_cli_gate_does_not_re_wait_the_same_dead_terminal(monkeypatch, tmp_path):
+ """`unsloth studio run` re-execs and re-enters this gate on the SAME pty.
+
+ The parent waits its deadline, nobody types, and it marks the terminal as
+ already tried. Without honouring that mark the child waits the whole deadline
+ over again, so 30s becomes 60s before the backend gate has even had its turn,
+ which is long enough to trip a startup watchdog. The mark is peeked, never
+ popped: run.py is what consumes it.
+ """
+ studio_mod = _studio()
+ calls = []
+
+ def _fake_prompt(verify_current, out = None, **kw):
+ calls.append(kw)
+ raise studio_mod._password_prompt.PromptUnattended
+
+ events = _install_prompt_env(monkeypatch, tmp_path, interactive = True)
+ monkeypatch.setattr(studio_mod._password_prompt, "prompt_new_password", _fake_prompt)
+ monkeypatch.setattr(studio_mod, "_prompt_owns_the_terminal", lambda: True)
+ _seed_auth(studio_mod)
+
+ # Parent: waits, gets nothing, marks the terminal.
+ _invoke_studio_default(monkeypatch, events, ["-H", "0.0.0.0"])
+ assert len(calls) == 1
+ import os as _os
+ assert _os.environ.get(studio_mod._UNATTENDED_PROMPT_DONE_ENV) == "1"
+
+ # Child, after the re-exec: same terminal, must not sit on it again.
+ _invoke_studio_default(monkeypatch, events, ["-H", "0.0.0.0"])
+ assert len(calls) == 1, "the re-executed gate waited on the dead terminal again"
+ assert _os.environ.get(studio_mod._UNATTENDED_PROMPT_DONE_ENV) == "1", "popped, not peeked"
+
+
+def test_the_mark_never_lets_a_tunnel_skip_its_prompt(monkeypatch, tmp_path):
+ """A public URL fails closed, mark or no mark."""
+ studio_mod = _studio()
+ calls = []
+
+ def _fake_prompt(verify_current, out = None, **kw):
+ calls.append(kw)
+ return _NEW_PW
+
+ events = _install_prompt_env(monkeypatch, tmp_path, interactive = True)
+ monkeypatch.setattr(studio_mod._password_prompt, "prompt_new_password", _fake_prompt)
+ monkeypatch.setattr(studio_mod, "_prompt_owns_the_terminal", lambda: True)
+ monkeypatch.setenv(studio_mod._UNATTENDED_PROMPT_DONE_ENV, "1")
+ _seed_auth(studio_mod)
+
+ _invoke_studio_default(monkeypatch, events, ["--secure"])
+ assert len(calls) == 1, "a tunnel launch skipped its prompt because of the mark"
+
+
+def _banner(monkeypatch, tmp_path, args):
+ """Run the gate far enough to capture the banner it prints, then bail out.
+
+ Clears the unattended mark first: bailing out with an interrupt SETS it on a
+ raw bind, so a second call in the same test would skip the prompt and capture
+ no banner at all.
+ """
+ import os as _os
+
+ studio_mod = _studio()
+ _os.environ.pop(studio_mod._UNATTENDED_PROMPT_DONE_ENV, None)
+
+ def _fake_prompt(verify_current, out = None, **kw):
+ raise KeyboardInterrupt
+
+ events = _install_prompt_env(monkeypatch, tmp_path, interactive = True)
+ monkeypatch.setattr(studio_mod._password_prompt, "prompt_new_password", _fake_prompt)
+ monkeypatch.setattr(studio_mod, "_prompt_owns_the_terminal", lambda: True)
+ _seed_auth(studio_mod)
+ result = _invoke_studio_default(monkeypatch, events, args)
+ return (result.output or "") + (getattr(result, "stderr", "") or "")
+
+
+def test_the_banner_does_not_promise_an_abort_a_raw_bind_will_not_perform(
+ monkeypatch, tmp_path,
+):
+ """`Ctrl+C to abort` is true for a tunnel and false for a raw bind.
+
+ On a raw bind the interrupt declines the prompt and the launch continues, by
+ design, because that launch worked before this gate existed. An operator who
+ reads "abort", presses Ctrl+C and walks away would be leaving a server up on
+ the network with the auto-generated password.
+ """
+ raw = _banner(monkeypatch, tmp_path, ["-H", "0.0.0.0"])
+ assert "Ctrl+C to abort" not in raw
+ assert "Ctrl+C to skip" in raw
+
+ tunnel = _banner(monkeypatch, tmp_path, ["--secure"])
+ assert "Ctrl+C to abort" in tunnel
+
+
+def test_a_concrete_bind_is_not_described_as_every_interface(monkeypatch, tmp_path):
+ """`-H 192.168.1.50` listens on one address, so say so.
+
+ The gate widened to is_external_host, which routes concrete non-loopback
+ hosts down the same path as the wildcard, and they inherited its wording.
+ """
+ concrete = _banner(monkeypatch, tmp_path, ["-H", "192.168.1.50"])
+ assert "on every network interface" not in concrete
+ assert "192.168.1.50" in concrete
+
+ wildcard = _banner(monkeypatch, tmp_path, ["-H", "0.0.0.0"])
+ assert "on every network interface" in wildcard