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
Tighten comments in the studio wildcard bind password prompt
danielhanchen5ca7bb35c108
diff --git a/studio/backend/auth/terminal_prompt.py b/studio/backend/auth/terminal_prompt.pyindex dff56bfd475..f9b3c247919 100644--- a/studio/backend/auth/terminal_prompt.py+++ b/studio/backend/auth/terminal_prompt.py@@ -2,8 +2,8 @@# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0"""Interactive terminal prompt that forces a bootstrap password change before-Unsloth is put where others can reach it: a public Cloudflare URL (``--secure``-/ ``--cloudflare``) or a raw non-loopback bind such as ``-H 0.0.0.0``.+Unsloth becomes reachable: a public Cloudflare URL (``--secure`` / ``--cloudflare``)+or a raw non-loopback bind such as ``-H 0.0.0.0``.Masked input echoes one ``*`` per keystroke (unlike ``getpass``). Works onWindows (``msvcrt``) and Linux/macOS (``termios``). All output goes to stderr so@@ -146,21 +146,20 @@ _getch: Callable[[], str] = _getch_windows if os.name == "nt" else _getch_posixclass PromptUnattended(Exception):- """A terminal is attached but nobody answered the prompt before the deadline.+ """A terminal is attached but nobody answered before the deadline.- A pty is not a person. ``tmux new -d``, ``screen -dmS`` and ``docker run -dt``- all allocate a real, foreground pty that no one is reading, so isatty() is- True on both streams and the read simply never returns. Callers that must- never block a launch pass a deadline and treat this as a refusal.+ A pty is not a person: ``tmux new -d`` / ``docker run -dt`` allocate a real+ foreground pty nobody reads, so isatty() is True on both streams and the read+ never returns. Callers that must not block a launch treat this as a refusal."""def _wait_for_first_key(timeout: float) -> bool:"""Whether a keystroke arrived within ``timeout`` seconds.- Must be called with the terminal already in cbreak mode: in canonical mode- the driver holds input until a newline, so the fd would not become readable- on the first character. True on any doubt, which is the blocking behaviour.+ Requires cbreak mode already set: canonical mode holds input until a newline,+ so the fd would not become readable on the first character. True on any doubt+ (the blocking behaviour)."""if os.name == "nt":import time@@ -195,8 +194,8 @@ def _read_password(Raises KeyboardInterrupt on Ctrl-C and EOFError on Ctrl-D/Ctrl-Z with anempty buffer; the terminal is restored on every exit path. With- ``first_key_timeout`` set, raises PromptUnattended when the FIRST keystroke- never arrives; once someone starts typing there is no deadline.+ ``first_key_timeout``, raises PromptUnattended when the FIRST keystroke never+ arrives; once someone starts typing there is no deadline."""if out is None:out = sys.stderr@@ -256,12 +255,11 @@ def should_prompt_password_change(still has the seeded password, and both stdin and stderr are real terminals(headless launches keep the bootstrap-timeout protection instead of hanging).- Two ways to be reachable, not one. ``tunnel_will_start`` is the public- Cloudflare URL. ``bind_is_exposed`` is a raw non-loopback bind such as- ``-H 0.0.0.0``, which is reachable by every host on the network, and by the- internet when the machine has a public address, yet starts no tunnel. That- second case previously got no prompt at all, so the seeded password stayed- live and was served in the page to anyone who loaded it.+ Two ways to be reachable: ``tunnel_will_start`` (public Cloudflare URL) and+ ``bind_is_exposed`` (a raw non-loopback bind like ``-H 0.0.0.0``, reachable by+ the whole network yet starting no tunnel). The second used to get no prompt at+ all, so the seeded password stayed live and was served to anyone who loaded+ the page."""if not (tunnel_will_start or bind_is_exposed):return False@@ -282,22 +280,20 @@ def prompt_for_password_change("""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. 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,- which is the LAN behind a NAT router and the internet on a cloud box with a- public address. Claiming the wrong one trains people to ignore the message.-- ``first_key_timeout`` bounds the wait for the FIRST keystroke and returns+ Ctrl-C / EOF returns False; ``refusal_aborts`` tells the banner what the+ caller does with that, so it never promises an abort that will not happen:+ True for a tunnel (caller aborts), False for a raw bind (launch proceeds,+ because it worked before this prompt existed).++ ``exposure`` names where this launch is reachable: a tunnel really is the+ public internet, a raw bind is every interface (LAN behind NAT, or the+ internet on a cloud box). Claiming the wrong one trains people to ignore it.++ ``first_key_timeout`` bounds the wait for the FIRST keystroke, returningFalse if it never comes. Only a caller that must not block a launch passesit: a detached pty (``tmux new -d``, ``docker run -dt``) looks exactly like- an attended terminal, so without a deadline such a launch waits forever and- never binds its socket. Unset (the tunnel) keeps blocking indefinitely.+ an attended terminal, so undeadlined it waits forever and never binds its+ socket. Unset (the tunnel) blocks indefinitely."""if out is None:out = sys.stderr@@ -312,7 +308,7 @@ def prompt_for_password_change(f"password now. {refusal}\n\n")out.flush()- # Only the first read is deadlined; once a key arrives someone is there.+ # Only the first read is deadlined; a key arriving proves someone is there.pending_timeout = first_key_timeouttry:while True:diff --git a/studio/backend/run.py b/studio/backend/run.pyindex 30d2143fc0e..6b27e517058 100644--- a/studio/backend/run.py+++ b/studio/backend/run.py@@ -2133,18 +2133,13 @@ def _stream_isatty(stream) -> bool:return False-# How long a raw-bind prompt waits for the FIRST keystroke before giving up and-# launching anyway. Only the first: once someone is typing there is no deadline.-#-# 30s, not longer. The launches that reach this with nobody watching are the ones-# that allocate a pty and then never read it -- `docker run -dt`, `tmux new -d`,-# `screen -dmS`, some CI runners -- and they want to bind promptly. A container-# that takes two minutes to answer a healthcheck can be killed and restarted by-# the orchestrator, which would turn "delayed" into a restart loop; 30s stays-# inside a default Docker HEALTHCHECK start period. Someone who is actually-# looking at the prompt starts typing well inside that, and someone who is not-# gets the refusal path, which warns and launches with the bootstrap deadline-# armed. Mirrored in the CLI.+# How long a raw-bind prompt waits for the FIRST keystroke before launching+# anyway; once someone is typing there is no deadline. 30s because the launches+# that reach here unwatched allocate a pty and never read it (`docker run -dt`,+# `tmux new -d`, CI runners) and need to bind promptly: a longer stall can trip a+# healthcheck into a restart loop, while 30s stays inside a default Docker+# HEALTHCHECK start period and is ample for anyone actually watching. Mirrored in+# the CLI._UNATTENDED_PROMPT_SECONDS = 30.0@@ -2152,14 +2147,13 @@ def _prompt_owns_the_terminal() -> bool:"""Whether this process may DRIVE the terminal, not merely see one.A backgrounded shell job (`unsloth studio -H 0.0.0.0 &`) inherits the- terminal, so isatty() is True, but the masked prompt calls termios.tcsetattr,- and POSIX sends SIGTTOU to a background process group that does; the default- action stops the process. The launch would freeze before the socket binds- instead of starting, which is exactly the "never block a launch that worked"- case this gate is careful about everywhere else. Treat it as no terminal.-- True on any doubt: no job control (Windows), no controlling terminal, or a- stream with no fileno. Nothing can stop us there, so the isatty answer stands.+ terminal so isatty() is True, but the masked prompt calls termios.tcsetattr+ and POSIX SIGTTOUs a background process group that does; the default action+ stops the process, freezing the launch before the socket binds. Treat it as+ no terminal.++ True on any doubt (no job control, no controlling terminal, no fileno):+ nothing can stop us there, so the isatty answer stands."""try:return os.tcgetpgrp(sys.stdin.fileno()) == os.getpgrp()@@ -2170,10 +2164,9 @@ def _prompt_owns_the_terminal() -> bool: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.+ A tunnel is the public internet; a wildcard bind is every interface. A+ CONCRETE bind (`-H 192.168.1.50`) is neither, since uvicorn listens on that+ one address, and the operator acts on the address they typed anyway."""if tunnel_will_start:return "on the public internet"@@ -2216,16 +2209,12 @@ def _terminal_password_gate(from auth.bootstrap_timeout import _is_exposed_bind# A raw non-loopback bind (-H 0.0.0.0) starts no tunnel, so it used to skip- # this gate entirely even though the docstring above describes exactly its- # hazard: the served HTML injects the bootstrap credential, and every host on- # the network can load it. Scoped like the bootstrap deadline: web UI only,- # never api-only (authenticates by API key, not the admin password) and never- # Colab (sandboxed, no inbound).- # secure = False deliberately. _is_exposed_bind counts --secure as exposed- # because for a tunnel launch the tunnel IS the exposure, but --secure forces- # a loopback bind, so asking it with secure = True would conflate "the tunnel- # publishes this" with "the socket itself is reachable". Here only the second- # question matters; the first is already tunnel_will_start.+ # this gate even though the served HTML injects the bootstrap credential for+ # every host on the network. Scoped like the bootstrap deadline: web UI only,+ # never api-only (API key, not the admin password) and never Colab (no inbound).+ # secure = False deliberately: _is_exposed_bind counts --secure as exposed+ # (for a tunnel the tunnel IS the exposure) but --secure forces a loopback+ # bind, and the only question here is whether the socket itself is reachable.bind_is_exposed = (_is_exposed_bind(host, False) and frontend_served and not api_only and not is_colab)@@ -2233,19 +2222,18 @@ def _terminal_password_gate(return True, False# The parent already held this terminal open and got nothing. Repeating the- # wait would double the fallback (and triple it on the `studio run` path,- # which re-enters the CLI gate after re-exec), which is exactly the startup- # stall the deadline was chosen to stay under. Consumed, not just read, so it- # cannot leak into a later launch from the same environment.+ # wait would double the fallback (triple on the `studio run` path, which+ # re-enters the CLI gate after re-exec) -- the startup stall the deadline was+ # chosen to stay under. Consumed, not peeked, so it cannot leak into a later+ # launch from the same environment.if os.environ.pop("UNSLOTH_STUDIO_UNATTENDED_PROMPT_DONE", "") and not tunnel_will_start:return True, False# A raw-bind-only launch decides promptability BEFORE opening auth storage.- # Before this gate learned about non-tunnel exposure it returned above, so a- # headless container never reached ensure_default_admin() from here. Doing so- # now would move first seeding earlier, open the SQLite file sooner and give a- # read-only or locked home a new place to fail, none of which a container- # operator asked for. Tunnel launches are unaffected: they always came here.+ # Such a launch used to return above, so a headless container never reached+ # ensure_default_admin() from here; doing so now would seed earlier, open the+ # SQLite file sooner and give a read-only or locked home a new place to fail.+ # Tunnel launches are unaffected: they always came here.if not tunnel_will_start and not (_stream_isatty(sys.stdin) and _stream_isatty(sys.stderr) and _prompt_owns_the_terminal()):@@ -2276,12 +2264,11 @@ def _terminal_password_gate(stdin_isatty = _stream_isatty(sys.stdin),stderr_isatty = _stream_isatty(sys.stderr),):- # Headless raw bind: leave it EXACTLY as it behaved before this gate- # learned about non-tunnel exposure. The refuse-and-strip handling below- # is calibrated to publishing a public URL; applying it here would break- # long-running headless containers, which are the common use of- # -H 0.0.0.0, and would delete the .bootstrap_password file such a- # deployment is often read from. The bootstrap deadline still arms.+ # Headless raw bind: leave it EXACTLY as it behaved before. The+ # refuse-and-strip handling below is calibrated to publishing a public+ # URL; here it would break long-running headless containers (the common+ # use of -H 0.0.0.0) and delete the .bootstrap_password they are read+ # from. The bootstrap deadline still arms.if not tunnel_will_start:return True, False# No terminal: only proceed if the bootstrap deadline will arm; api-only@@ -2344,39 +2331,36 @@ def _terminal_password_gate(apply_change = _apply_change,out = sys.stderr,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+ # 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- # waits forever and the socket never binds. No answer is handled below as- # a refusal: proceed on the bootstrap deadline, exactly as before. The- # tunnel keeps waiting indefinitely; it fails closed rather than proceed.+ # (`tmux new -d`, `docker run -dt`) passes every isatty and process-group+ # test yet nobody will ever type, so an undeadlined read waits forever and+ # the socket never binds; no answer is handled below as a refusal and+ # proceeds on the bootstrap deadline. The tunnel waits forever instead,+ # failing closed.first_key_timeout = None if tunnel_will_start else _UNATTENDED_PROMPT_SECONDS,)if changed:return True, Trueif tunnel_will_start:- # Refusing to secure a launch that is about to publish a public URL- # aborts it, exactly as before.+ # Refusing to secure a launch about to publish a public URL aborts it,+ # exactly as before.return False, False- # A raw bind is different: this launch worked before the prompt existed, and- # aborting it would turn Ctrl+C into "no Studio" for anyone who just wanted- # the old behaviour. `docker run -it` on a fresh volume is precisely that- # 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.+ # A raw bind is different: it worked before the prompt existed, and aborting+ # would turn Ctrl+C into "no Studio". 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 `docker run -it` on a fresh volume+ # meets this prompt and aborting would stop a container that starts today.+ # Warn and proceed at the 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.+ # Which is sometimes NO protection: UNSLOTH_STUDIO_BOOTSTRAP_TIMEOUT=0 never+ # arms the deadline, so say what will actually happen rather than promise a+ # shutdown -- that is the one sentence an operator acts on. Still proceed: the+ # operator disabled the deadline and cancelled the prompt deliberately, and+ # refusing to start would break the case above.deadline_arms = should_arm_bootstrap_timeout(host = host,secure = secure,diff --git a/studio/backend/tests/test_password_prompt.py b/studio/backend/tests/test_password_prompt.pyindex 52ca94d432a..e1249be6a1a 100644--- a/studio/backend/tests/test_password_prompt.py+++ b/studio/backend/tests/test_password_prompt.py@@ -341,12 +341,9 @@ def test_resolve_supplied_password_off_by_default(monkeypatch):# ──────────────────────────────────────────────────────────────────────-# A raw non-loopback bind is exposure too.-#-# `-H 0.0.0.0` starts no tunnel, so it used to return False here and skip the-# gate entirely, leaving the seeded admin password live and served in the page-# to every host on the network. The gate's own docstring in run.py described-# that hazard while the code returned early on `if not tunnel_will_start`.+# A raw non-loopback bind is exposure too. `-H 0.0.0.0` starts no tunnel, so it+# used to return False here and skip the gate, leaving the seeded admin password+# live and served in the page to every host on the network.# ──────────────────────────────────────────────────────────────────────@@ -367,11 +364,10 @@ def test_a_raw_exposed_bind_prompts_when_a_terminal_is_attached():def test_a_raw_exposed_bind_stays_silent_without_a_terminal():"""Headless raw binds keep today's behaviour, deliberately.- Everything downstream of a True here is calibrated to publishing a public- URL: it refuses to launch when the deadline is disabled, and it deletes- .bootstrap_password. Long-running headless containers are the common use of- -H 0.0.0.0 and are often logged into by reading exactly that file, so they- keep the bootstrap deadline as their protection instead.+ Everything downstream of a True here is calibrated to publishing a public URL:+ it refuses to launch when the deadline is disabled, and it deletes+ .bootstrap_password, which long-running headless containers (the common use of+ -H 0.0.0.0) are often logged into by reading. They keep the deadline instead."""from auth.terminal_prompt import should_prompt_password_changefor stdin_tty, stderr_tty in ((False, False), (True, False), (False, True)):@@ -433,8 +429,8 @@ def test_the_default_keeps_old_callers_tunnel_only():def test_the_prompt_banner_does_not_claim_the_internet_for_a_lan_bind(monkeypatch):"""`-H 0.0.0.0` behind a NAT router is the LAN, not the public internet.- Saying "public internet" there is false often enough to train people to- ignore the message, which is the one thing this prompt cannot afford.+ Saying "public internet" is false often enough to train people to ignore the+ message, which is the one thing this prompt cannot afford."""import io@@ -446,8 +442,7 @@ def test_the_prompt_banner_does_not_claim_the_internet_for_a_lan_bind(monkeypatcmonkeypatch.setattr(terminal_prompt, "_read_password", _no_input)out = io.StringIO()- # The read aborts immediately and returns False, which is fine: the banner- # is written before any read.+ # The read aborts immediately; fine, the banner is written before any read.terminal_prompt.prompt_for_password_change(min_length = 8,is_current_password = lambda _c: False,diff --git a/studio/backend/tests/test_password_prompt_backstop.py b/studio/backend/tests/test_password_prompt_backstop.pyindex d5edb750e4e..093145080b2 100644--- a/studio/backend/tests/test_password_prompt_backstop.py+++ b/studio/backend/tests/test_password_prompt_backstop.py@@ -428,10 +428,10 @@ _RAW_BIND_KWARGS = dict(def test_a_headless_raw_bind_is_byte_for_byte_unchanged(monkeypatch):"""The compatibility promise of this change.- Headless `-H 0.0.0.0` is the long-running container case. It must still- proceed, still keep serving the bootstrap credential, and above all must not- reach the strip-and-refuse handling that a public tunnel launch uses; that- would delete the .bootstrap_password such deployments are logged into with.+ Headless `-H 0.0.0.0` is the long-running container case: it must still+ proceed, keep serving the bootstrap credential, and above all not reach the+ strip-and-refuse handling a public tunnel launch uses, which would delete the+ .bootstrap_password such deployments are logged into with."""_patch_streams(monkeypatch, tty = False)_patch_seeded_admin(monkeypatch, requires_change = True)@@ -441,12 +441,11 @@ def test_a_headless_raw_bind_is_byte_for_byte_unchanged(monkeypatch):def test_a_headless_raw_bind_does_not_open_auth_storage(monkeypatch):""" "Unchanged" has to mean it does not touch the database either.- Before this gate learned about non-tunnel exposure, a headless raw bind- returned at `if not tunnel_will_start` without importing auth storage. If it- now calls ensure_default_admin() first, first seeding moves earlier and the- SQLite file is opened sooner, which gives a read-only or locked STUDIO_HOME a- brand new place to fail on a launch that used to work. So the promptability- decision has to happen before storage is consulted.+ A headless raw bind used to return at `if not tunnel_will_start` without+ importing auth storage. Calling ensure_default_admin() first would move+ seeding earlier and open the SQLite file sooner, giving a read-only or locked+ STUDIO_HOME a new place to fail on a launch that used to work, so+ promptability must be decided before storage is consulted."""_patch_streams(monkeypatch, tty = False)@@ -469,9 +468,8 @@ def test_refusing_the_prompt_on_a_raw_bind_still_launches(monkeypatch):`docker/studio_run.sh` execs `unsloth studio -H 0.0.0.0` and only supplies apassword when the initial-password file is non-empty, so a fresh- `docker run -it` meets this prompt. Aborting there would stop a container- that starts today. The launch proceeds at the protection level it already- had, which is the bootstrap deadline.+ `docker run -it` meets this prompt and aborting would stop a container that+ starts today. It proceeds on the bootstrap deadline it already had."""_patch_streams(monkeypatch, tty = True)_patch_seeded_admin(monkeypatch, requires_change = True)@@ -484,8 +482,7 @@ def test_refusing_the_prompt_on_a_raw_bind_still_launches(monkeypatch):lambda **_kw: False, # Ctrl+C / EOF)- # proceed = True, and the bootstrap credential keeps being injected exactly- # as it was before this prompt existed.+ # proceed = True, and the bootstrap credential is still injected as before.assert run._terminal_password_gate(tunnel_will_start = False, **_RAW_BIND_KWARGS) == (True, False)@@ -587,11 +584,10 @@ def test_a_backgrounded_raw_bind_does_not_prompt(monkeypatch):"""`unsloth studio -H 0.0.0.0 &` must still launch.A background job inherits the terminal, so isatty() is True on both streams,- but the masked prompt calls termios.tcsetattr; POSIX sends SIGTTOU to a- background process group that does, and the default action STOPS the process.- The launch would freeze before the socket binds, so it takes the headless- path it took before this gate learned about non-tunnel exposure: proceed,- protected by the bootstrap deadline, without consulting auth storage.+ but the masked prompt calls termios.tcsetattr; POSIX SIGTTOUs a background+ process group that does, and the default action STOPS the process. The launch+ would freeze before the socket binds, so it takes the old headless path:+ proceed on the bootstrap deadline, without consulting auth storage."""monkeypatch.setattr(sys, "stdin", _FdStream())monkeypatch.setattr(sys, "stderr", _FdStream())@@ -615,8 +611,8 @@ def test_a_backgrounded_tunnel_launch_still_fails_closed(monkeypatch):_patch_seeded_admin(monkeypatch, requires_change = True)monkeypatch.setattr(terminal_prompt, "prompt_for_password_change", lambda **_kw: False)- # The process group check is scoped to the raw-bind branch, so a tunnel- # launch still reaches the prompt and still aborts when it is refused.+ # The process group check is scoped to the raw-bind branch, so a tunnel still+ # reaches the prompt and still aborts when it is refused.assert run._prompt_owns_the_terminal() is Falseassert run._terminal_password_gate(tunnel_will_start = True, **_GATE_KWARGS) == (False, False)@@ -667,11 +663,10 @@ class _PtyStdin:def test_an_unattended_pty_does_not_block_a_raw_bind_forever(monkeypatch):"""`tmux new -d 'unsloth studio -H 0.0.0.0'` must still bind its socket.- A detached pty is a real, foreground terminal that nobody will ever type- into: isatty() is True on both streams and the process owns the terminal, so- every interactivity test says "prompt". The read then never returns, and- because the gate runs BEFORE uvicorn binds, the launch hangs forever instead- of starting - a launch that worked before this gate widened to raw binds.+ A detached pty is a real, foreground terminal nobody will ever type into:+ isatty() is True on both streams and the process owns the terminal, so every+ interactivity test says "prompt". The read never returns, and the gate runs+ BEFORE uvicorn binds, so the launch hangs forever instead of starting."""import ioimport pty@@ -680,7 +675,7 @@ def test_an_unattended_pty_does_not_block_a_raw_bind_forever(monkeypatch):try:monkeypatch.setattr(sys, "stdin", _PtyStdin(slave))out = io.StringIO()- # Nothing is ever written to `master`: the pty exists, the human does not.+ # Nothing is written to `master`: the pty exists, the human does not.changed = terminal_prompt.prompt_for_password_change(min_length = 8,is_current_password = lambda _c: False,@@ -751,10 +746,10 @@ def test_the_gate_deadlines_a_raw_bind_prompt_and_never_the_tunnel(monkeypatch):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.+ The refusal path proceeds on purpose (the launch worked before the prompt+ existed), but must not 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)@@ -789,9 +784,9 @@ def test_the_child_does_not_repeat_a_prompt_the_parent_already_gave_up_on(monkey"""A 30s fallback must not become 60s across the re-exec.The CLI parent holds the terminal for its deadline, gets nothing, warns and- launches. The child gate then sees the SAME unattended pty. Without a handoff- it waits the whole deadline again, and on the `studio run` path a third time,- which is exactly the startup stall the 30s value was chosen to stay under.+ launches. The child gate then sees the SAME unattended pty; without a handoff+ it waits the whole deadline again, and a third time on the `studio run` path,+ which is the startup stall the 30s value was chosen to stay under."""monkeypatch.setenv("UNSLOTH_STUDIO_UNATTENDED_PROMPT_DONE", "1")_patch_streams(monkeypatch, tty = True)@@ -804,8 +799,7 @@ def test_the_child_does_not_repeat_a_prompt_the_parent_already_gave_up_on(monkeymonkeypatch.setattr(_storage, "ensure_default_admin", _boom)assert run._terminal_password_gate(tunnel_will_start = False, **_RAW_BIND_KWARGS) == (True, False)- # Consumed, so a later launch from the same environment is not silently- # stripped of its own prompt.+ # Consumed, so a later launch from the same environment keeps its own prompt.import os as _osassert _os.environ.get("UNSLOTH_STUDIO_UNATTENDED_PROMPT_DONE") is Nonediff --git a/studio/backend/tests/test_wildcard_prompt_compatibility.py b/studio/backend/tests/test_wildcard_prompt_compatibility.pyindex 9ce0cd3cb7a..23d609177f9 100644--- a/studio/backend/tests/test_wildcard_prompt_compatibility.py+++ b/studio/backend/tests/test_wildcard_prompt_compatibility.py@@ -4,9 +4,8 @@"""Compatibility surface of the raw-bind password prompt.The prompt itself is covered by test_password_prompt.py and the gate wiring by-test_password_prompt_backstop.py. This file covers the things that only break-somewhere else: other platforms, old installs, and the claim that none of this-touches hardware.+test_password_prompt_backstop.py. This file covers what only breaks somewhere+else: other platforms, old installs, and the no-hardware-coupling claim."""from __future__ import annotations@@ -31,9 +30,9 @@ from auth import terminal_prompt # noqa: E402def test_the_windows_getch_path_decodes_a_password(monkeypatch):"""`_getch` is selected by os.name at import; exercise the Windows half.- This box is Linux, so the msvcrt branch is otherwise never executed. A stub- stands in for the module so the two-wchar arrow-key sequence and ordinary- characters both go through the real handler.+ CI is Linux, so the msvcrt branch is otherwise never executed. A stub module+ puts the two-wchar arrow-key sequence and ordinary characters through the+ real handler."""import types@@ -62,7 +61,7 @@ def test_the_windows_getch_path_decodes_a_password(monkeypatch):passassert terminal_prompt._read_password("pw: ", out = _Out()) == "pw1"- # The arrow key is swallowed, not masked, so exactly one star per character.+ # The arrow key is swallowed, not masked: one star per character.assert "".join(out).count("*") == 3@@ -77,9 +76,8 @@ class _NullCtx:def test_a_stream_with_no_fileno_is_not_interactive():"""pythonw / a Windows service has no console; isatty must not raise.- _prompt_raw_mode swallows the resulting error, and the gate's own isatty- helpers treat a broken stream as non-interactive, so such a launch takes the- headless path rather than crashing.+ The gate's isatty helpers treat a broken stream as non-interactive, so such a+ launch takes the headless path rather than crashing."""class _Broken:@@ -114,7 +112,7 @@ def test_a_split_terminal_never_prompts(stdin_tty, stderr_tty):def test_an_old_caller_that_omits_bind_is_exposed_behaves_as_before():- """Forwards compatibility: the new kwarg is optional and defaults off.+ """The new kwarg is optional and defaults off.A studio venv can hold an older backend than the CLI that launched it, so acaller predating this change must keep tunnel-only semantics.@@ -153,11 +151,11 @@ def test_the_prompt_signature_stays_keyword_compatible():def test_the_password_gate_imports_no_gpu_or_torch_module():- """The claim that this change is hardware-independent, checked not asserted.+ """The hardware-independence claim, checked not asserted.- Run in a subprocess: importing torch in THIS interpreter would poison the- rest of the session, and a sys.modules probe after the fact proves nothing- about what the import graph actually pulls in.+ In a subprocess: importing torch in THIS interpreter would poison the rest of+ the session, and a sys.modules probe after the fact proves nothing about what+ the import graph pulls in."""probe = ("import sys;"diff --git a/unsloth_cli/commands/_password_prompt.py b/unsloth_cli/commands/_password_prompt.pyindex 69dd9c7c0a5..7afcd4ccd63 100644--- a/unsloth_cli/commands/_password_prompt.py+++ b/unsloth_cli/commands/_password_prompt.py@@ -31,20 +31,19 @@ _SUBMIT_CHARS = ("\r", "\n")class PromptUnattended(Exception):"""A terminal is attached but nobody answered before the deadline.- A pty is not a person: ``tmux new -d``, ``screen -dmS`` and ``docker run -dt``- allocate a real, foreground pty nobody reads, so isatty() is True on both- streams and the read never returns. Callers that must not block a launch pass- a deadline and treat this as a refusal. Mirror of- studio/backend/auth/terminal_prompt.py -- keep the two in sync.+ A pty is not a person: ``tmux new -d`` / ``docker run -dt`` allocate a real+ foreground pty nobody reads, so isatty() is True on both streams and the read+ never returns. Callers that must not block a launch treat this as a refusal.+ Mirror of studio/backend/auth/terminal_prompt.py -- keep the two in sync."""def _wait_for_first_key(timeout: float) -> bool:"""Whether a keystroke arrived within ``timeout`` seconds.- Must be called with the terminal already in cbreak mode: in canonical mode- the driver holds input until a newline, so the fd would not become readable- on the first character. True on any doubt, which is the blocking behaviour.+ Requires cbreak mode already set: canonical mode holds input until a newline,+ so the fd would not become readable on the first character. True on any doubt+ (the blocking behaviour)."""if os.name == "nt":import time@@ -132,8 +131,8 @@ def _read_masked_posix(new_attrs = termios.tcgetattr(fd)new_attrs[3] &= ~termios.ISIGtermios.tcsetattr(fd, termios.TCSADRAIN, new_attrs)- # Deadline the FIRST keystroke only: a detached pty is a terminal that- # nobody will ever type into, and blocking there never binds the socket.+ # FIRST keystroke only: a detached pty is a terminal nobody will type+ # into, and blocking there means the socket never binds.if first_key_timeout is not None and not _wait_for_first_key(first_key_timeout):raise PromptUnattended# os.read + incremental decoder with errors="replace": text-mode read(1) can raise or yield a lone@@ -246,7 +245,7 @@ def prompt_new_password(``first_key_timeout`` bounds the wait for the FIRST keystroke and raisesPromptUnattended if it never comes; once someone types there is no deadline.- Only a caller that must not block a launch passes it -- a detached pty+ Only a caller that must not block a launch passes it: a detached pty(``tmux new -d``, ``docker run -dt``) is a terminal nobody will answer."""if out is None:diff --git a/unsloth_cli/commands/studio.py b/unsloth_cli/commands/studio.pyindex 6381aeca025..6bb6fa8f89c 100644--- a/unsloth_cli/commands/studio.py+++ b/unsloth_cli/commands/studio.py@@ -1179,11 +1179,10 @@ def _launch_publishes_tunnel((Colab launches never come through this CLI path). --secure implies thetunnel; --cloudflare only tunnels non-api-only wildcard binds.- Kept separate from _should_prompt_password_change, which is deliberately- wider. The guards that key off THIS one exist because a headless tunnel- launch strips .bootstrap_password and could lock the admin out; a raw- wildcard bind never strips, so widening them would add failure modes that- protect nothing.+ Kept separate from the deliberately wider _should_prompt_password_change: the+ guards keyed off THIS one exist because a headless tunnel launch strips+ .bootstrap_password and could lock the admin out, and a raw wildcard bind+ never strips, so widening them would add failure modes that protect nothing."""if secure:return True@@ -1197,9 +1196,9 @@ def _launch_publishes_tunnel(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.+ Only used to word the prompt. `_launch_publishes_tunnel` already called+ `is_wildcard_host` on this launch, so its getaddrinfo for a non-literal host+ is not a new cost here."""from unsloth_cli._tool_policy import is_wildcard_host@@ -1215,30 +1214,26 @@ def _should_prompt_password_change(through this CLI path). --secure implies the tunnel; --cloudflare onlytunnels non-api-only wildcard binds.- A raw non-loopback bind counts too, and only when a terminal is attached. It- is reachable by every host on the network, and by the internet on a machine- with a public address, while starting no tunnel, so it previously got no- prompt, no warning and no strip: the seeded admin password stayed live and- was served in the page to anyone who loaded it.-- is_external_host, NOT is_wildcard_host. The backend gate classifies exposure- with auth/bootstrap_timeout._is_exposed_bind, which counts anything that is- not one of the three loopback aliases; wildcard is a strict subset of that.- Using the narrower test here meant `unsloth studio -H 192.168.1.50`, an- ordinary LAN bind, skipped the parent prompt and prompted in the re-exec'd- child instead, and against an OLDER studio-venv child, which the mixed-version- path explicitly supports and which has no backend gate, it prompted nowhere at- all and served the seeded password. It is also cheaper: is_wildcard_host runs- socket.getaddrinfo for any non-literal host, while is_external_host is a- frozenset membership test.-- The interactivity condition is deliberate and is what keeps this safe to- ship. Everything downstream of here is calibrated to publishing a public- URL: it refuses to launch when the deadline is disabled and it deletes- .bootstrap_password. Applying that to headless -H 0.0.0.0 would break- long-running containers, which are the common use of the flag. Headless raw- binds therefore keep exactly today's behaviour, protected by the bootstrap- deadline; only a launch with a human present is asked to set a password.+ A raw non-loopback bind counts too, but only with a terminal attached. It is+ reachable by the whole network (and the internet on a machine with a public+ address) while starting no tunnel, so it previously got no prompt, no warning+ and no strip: the seeded admin password stayed live and was served in the page.++ is_external_host, NOT is_wildcard_host. The backend classifies exposure with+ auth/bootstrap_timeout._is_exposed_bind, which counts anything that is not one+ of the three loopback aliases; wildcard is a strict subset. The narrower test+ meant `unsloth studio -H 192.168.1.50`, an ordinary LAN bind, skipped the+ parent prompt and prompted in the re-exec'd child instead, and against an+ OLDER studio-venv child (supported by the mixed-version path, and with no+ backend gate) it prompted nowhere at all and served the seeded password. It is+ also cheaper: a frozenset lookup rather than getaddrinfo.++ The interactivity condition is what keeps this safe to ship. Everything+ downstream is calibrated to publishing a public URL: it refuses to launch when+ the deadline is disabled and it deletes .bootstrap_password, which would break+ the long-running containers that are the common use of -H 0.0.0.0. Headless+ raw binds therefore keep today's behaviour on the bootstrap deadline; only a+ launch with a human present is asked to set a password."""if secure:return True@@ -1247,8 +1242,7 @@ def _should_prompt_password_change(from unsloth_cli._tool_policy import is_external_host, is_wildcard_hostif cloudflare is True and is_wildcard_host(host):- # A tunnel launch prompts regardless of the terminal; the headless- # fallback is handled downstream.+ # A tunnel prompts regardless of the terminal; headless is handled downstream.return Truereturn is_external_host(host) and _prompt_streams_interactive() and _prompt_owns_the_terminal()@@ -1261,21 +1255,12 @@ def _prompt_streams_interactive() -> bool:return False-# How long a raw-bind prompt waits for the first keystroke before giving up and-# launching anyway. Long enough for someone watching the terminal to react, short-# enough that an unattended pty is not held hostage. Mirrors run.py.-# How long a raw-bind prompt waits for the FIRST keystroke before giving up and-# launching anyway. Only the first: once someone is typing there is no deadline.-#-# 30s, not longer. The launches that reach this with nobody watching are the ones-# that allocate a pty and then never read it -- `docker run -dt`, `tmux new -d`,-# `screen -dmS`, some CI runners -- and they want to bind promptly. A container-# that takes two minutes to answer a healthcheck can be killed and restarted by-# the orchestrator, which would turn "delayed" into a restart loop; 30s stays-# inside a default Docker HEALTHCHECK start period. Someone who is actually-# looking at the prompt starts typing well inside that, and someone who is not-# gets the refusal path, which warns and launches with the bootstrap deadline-# armed. Mirrored in the CLI.+# How long a raw-bind prompt waits for the FIRST keystroke before launching+# anyway; once someone is typing there is no deadline. 30s because the launches+# that reach here unwatched allocate a pty and never read it (`docker run -dt`,+# `tmux new -d`, CI runners) and need to bind promptly: a longer stall can trip a+# healthcheck into a restart loop, while 30s stays inside a default Docker+# HEALTHCHECK start period and is ample for anyone actually watching. Mirrors run.py._UNATTENDED_PROMPT_SECONDS = 30.0@@ -1283,17 +1268,15 @@ def _prompt_owns_the_terminal() -> bool:"""Whether this process may DRIVE the terminal, not merely see one.A backgrounded shell job (`unsloth studio -H 0.0.0.0 &`) inherits the- terminal, so isatty() is True, but read_masked calls termios.tcsetattr, and- POSIX sends SIGTTOU to a background process group that does; the default- action stops the process. The launch would freeze at the prompt instead of- starting, which is the one thing widening this gate to raw binds must not do- -- such a launch started fine before, protected by the bootstrap deadline.- Only the raw-bind branch consults this: a tunnel launch is published on the- public internet and keeps failing closed rather than quietly proceeding.-- True on any doubt: no job control (Windows), no controlling terminal, or a- stream with no fileno. Nothing can stop us there, so the isatty answer stands.- Mirror of run.py's _prompt_owns_the_terminal -- keep the two in sync.+ terminal so isatty() is True, but read_masked calls termios.tcsetattr and+ POSIX SIGTTOUs a background process group that does; the default action stops+ the process, freezing the launch instead of starting it -- the one thing+ widening this gate to raw binds must not do. Only the raw-bind branch+ consults this; a tunnel keeps failing closed rather than quietly proceeding.++ True on any doubt (no job control, no controlling terminal, no fileno):+ nothing can stop us there, so the isatty answer stands. Mirror of run.py's+ _prompt_owns_the_terminal -- keep the two in sync."""try:return os.tcgetpgrp(sys.stdin.fileno()) == os.getpgrp()@@ -1317,17 +1300,17 @@ def _bootstrap_deadline_active() -> bool:return True-# Set by the parent when it has already put the prompt in front of this terminal-# and got nothing, so the re-exec'd child does not repeat the wait.+# Set by the parent once it has put the prompt in front of this terminal and got+# nothing, so the re-exec'd child does not repeat the wait._UNATTENDED_PROMPT_DONE_ENV = "UNSLOTH_STUDIO_UNATTENDED_PROMPT_DONE"def _deadline_sentence() -> str:"""Say what will actually happen, not what usually happens.- UNSLOTH_STUDIO_BOOTSTRAP_TIMEOUT=0 disables the shutdown entirely, and this- is the sentence an operator acts on, so promising a deadline that will never- arm is worse than saying nothing.+ UNSLOTH_STUDIO_BOOTSTRAP_TIMEOUT=0 disables the shutdown entirely, and this is+ the sentence an operator acts on, so promising a deadline that will never arm+ is worse than saying nothing."""if _bootstrap_deadline_active():return (@@ -1673,15 +1656,12 @@ def _enforce_password_change_before_exposure(cloudflare = cloudflare, host = host, secure = secure, api_only = api_only):return- # Only a tunnel launch is genuinely "a public Cloudflare URL". A raw wildcard- # 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`.- # 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.+ # Only a tunnel launch is genuinely "a public Cloudflare URL"; a raw bind is+ # the LAN behind a NAT router, or the internet on a cloud box. Use 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 none and is reached+ # through the raw bind instead. Naming the wrong one in the one message the+ # operator is meant to act on trains people to ignore it.tunnel_will_start = _launch_publishes_tunnel(cloudflare = cloudflare, host = host, secure = secure, api_only = api_only)@@ -1690,23 +1670,20 @@ def _enforce_password_change_before_exposure(# 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.+ # long enough to trip a startup watchdog. The parent committed the default+ # admin before setting this, so there is nothing left to do. Peeked, never+ # popped: run.py consumes it, and popping here would hand the backend a+ # fresh 30s wait. Never for a tunnel, which fails closed -- a marker from+ # an earlier raw-bind attempt must not buy a public URL a free pass.returnif 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.+ # A concrete bind (`-H 192.168.1.50`, `-H myhost.local`) listens on that+ # address ONLY, so "every network interface" is untrue; the gate widened to+ # is_external_host and routes these here too. Name what the operator typed.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@@ -1856,11 +1833,11 @@ 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+ # 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.+ # before this gate existed. Saying "abort" there would leave an operator+ # believing they 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@@ -1874,12 +1851,11 @@ def _enforce_password_change_before_exposure(new_password = _password_prompt.prompt_new_password(_is_current_password,# 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 waits forever and no server is ever- # started. Fall back to the protection that launch already had,- # the bootstrap deadline. A tunnel keeps waiting: it publishes a- # public URL, so it fails closed rather than proceeding.+ # detached pty (`tmux new -d`, `docker run -dt`) passes every+ # isatty and process-group test yet nobody will ever type, so an+ # undeadlined read waits forever and no server starts; fall back+ # to the bootstrap deadline it already had. A tunnel keeps waiting+ # and fails closed rather than publish a public URL unprompted.first_key_timeout = None if tunnel_will_start else _UNATTENDED_PROMPT_SECONDS,)except _password_prompt.PromptUnattended:@@ -1891,12 +1867,11 @@ def _enforce_password_change_before_exposure(err = True,)# The child gate sees the SAME unattended terminal and would wait its- # own deadline over again, so a 30s fallback becomes 60s, or 90 on the- # `studio run` path that re-enters this gate after re-exec. That is- # long enough to trip a startup watchdog, which is the restart loop- # the deadline exists to avoid. Tell the child the terminal has- # already been tried. A direct `python run.py` sets nothing, so it- # keeps its own backstop.+ # own deadline again: 30s becomes 60s, or 90 on the `studio run` path+ # that re-enters this gate after re-exec, long enough to trip a startup+ # watchdog into the restart loop the deadline exists to avoid. Tell the+ # child the terminal has been tried. A direct `python run.py` sets+ # nothing, so it keeps its own backstop.os.environ[_UNATTENDED_PROMPT_DONE_ENV] = "1"returnexcept (KeyboardInterrupt, EOFError):@@ -1908,11 +1883,11 @@ def _enforce_password_change_before_exposure(err = True,)raise typer.Exit(1)- # A raw bind is not a publication. This launch worked before the- # prompt existed, so Ctrl+C returns it to what it did then rather- # than refusing to start; run.py's gate makes the same choice, and- # this mirror is the one that actually runs for `unsloth studio- # -H 0.0.0.0`, so disagreeing here would make that unreachable.+ # A raw bind is not a publication: it worked before the prompt+ # existed, so Ctrl+C returns it to that rather than refusing to start.+ # run.py's gate makes the same choice, and this mirror is what actually+ # runs for `unsloth studio -H 0.0.0.0`, so disagreeing here would make+ # run.py's warn-and-proceed unreachable.typer.echo("\nWarning: password change aborted, so Unsloth is starting with ""the auto-generated admin password on a bind that is reachable "diff --git a/unsloth_cli/tests/test_studio_password_prompt.py b/unsloth_cli/tests/test_studio_password_prompt.pyindex 687d32990a9..5159da8a0c3 100644--- a/unsloth_cli/tests/test_studio_password_prompt.py+++ b/unsloth_cli/tests/test_studio_password_prompt.py@@ -38,10 +38,9 @@ _BASE = ["--model", "unsloth/Qwen3-1.7B-GGUF"]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.+ The gate writes it straight into os.environ, right in production (inherited+ across the re-exec) but wrong in a test process, where it survives into every+ later test and silently suppresses the prompt they assert on."""import unsloth_cli.commands.studio as studio_mod@@ -78,7 +77,7 @@ _TUNNEL_MATRIX = [def test_launch_publishes_tunnel_matrix(cloudflare, host, secure, api_only, expected):"""The narrow predicate. Unchanged, and pinned so it stays that way.- The strip-and-lockout guards key off this one. A raw wildcard bind never+ The strip-and-lockout guards key off this one, and a raw wildcard bind neverstrips .bootstrap_password, so it must not be pulled in here even though itdoes now prompt."""@@ -94,12 +93,12 @@ def test_launch_publishes_tunnel_matrix(cloudflare, host, secure, api_only, expe"cloudflare,host,secure,api_only,interactive,expected",[# Every tunnel launch prompts regardless of the terminal; the headless- # fallback is handled downstream, not here.+ # fallback is downstream.*[(c, h, s, a, False, e) for c, h, s, a, e in _TUNNEL_MATRIX if e],*[(c, h, s, a, True, e) for c, h, s, a, e in _TUNNEL_MATRIX if e],# The change: a RAW non-loopback bind with a terminal attached. Reachable- # by every host on the network with the seeded password live, and it- # starts no tunnel, so before this it got no prompt at all.+ # by the whole network with the seeded password live, and it starts no+ # tunnel, so before this it got no prompt at all.(None, "0.0.0.0", False, False, True, True),(False, "0.0.0.0", False, False, True, True),(None, "::", False, False, True, True),@@ -114,9 +113,8 @@ def test_launch_publishes_tunnel_matrix(cloudflare, host, secure, api_only, expe(None, "example.com", False, False, True, True),(None, "myhost.local", False, False, True, True),(None, "[::]", False, False, True, True),- # Headless raw binds stay exactly as they were: no prompt, no strip, no- # refusal. Long-running containers are the common use of this flag and- # the bootstrap deadline is what covers them.+ # Headless raw binds stay as they were: no prompt, no strip, no refusal.+ # Long-running containers are the common use, covered by the deadline.(None, "0.0.0.0", False, False, False, False),(False, "0.0.0.0", False, False, False, False),(None, "::", False, False, False, False),@@ -268,10 +266,9 @@ def _install_run_reexec(monkeypatch, events):real_is_file = Path.is_file# The fixture describes a POSIX install ("bin/unsloth", "/fake/..." paths), so# pin BOTH platform probes, not just sys.platform: the launcher name comes from- # platform.system(), which on a Windows runner looks for unsloth.exe, finds the- # fixture's POSIX name instead and exits with "venv missing 'unsloth' entry- # point" before any of these tests reaches what it is actually asserting. The- # Windows name has its own test below.+ # platform.system(), so a Windows runner looks for unsloth.exe, misses the+ # fixture's POSIX name and exits with "venv missing 'unsloth' entry point"+ # before any of these tests asserts anything. Windows has its own test below.monkeypatch.setattr(studio_mod.platform, "system", lambda: "Linux")monkeypatch.setattr(Path,@@ -318,9 +315,9 @@ def _invoke_run(monkeypatch, events, args):def test_run_reexecs_through_the_windows_console_script(monkeypatch):# Windows ships the console script as unsloth.exe, so `studio run` looks for- # that name instead of the bare one. Runs on every platform: platform.system()- # is the only thing that decides, and the branch was previously exercised by- # nothing, which is how the POSIX-only fixture above went unnoticed.+ # that name. Runs on every platform since platform.system() is the only thing+ # that decides; the branch was previously untested, which is how the+ # POSIX-only fixture above went unnoticed.import typer as _typerstudio_mod = _studio()@@ -334,8 +331,8 @@ def test_run_reexecs_through_the_windows_console_script(monkeypatch):"is_file",lambda self: True if str(self) == str(windows_bin) else real_is_file(self),)- # The bare POSIX name is NOT a file here, so a launch that only got this far- # by ignoring platform.system() would exit instead of re-execing.+ # The bare POSIX name is NOT a file here, so a launch that ignored+ # platform.system() would exit instead of re-execing.monkeypatch.setattr(studio_mod, "_managed_cli_package_present", lambda _python: False)app = _typer.Typer()@@ -1858,12 +1855,11 @@ _EXPOSURE_HOSTS = [def test_cli_and_backend_agree_on_which_hosts_are_exposed(monkeypatch, host):"""The parent and the child must classify exposure identically.- They are separate implementations in separate packages (the CLI cannot import- the backend), and they are consulted at different moments: the parent decides- before re-exec, the child decides after. When they disagree the prompt lands- in the child instead of the parent, and against an OLDER studio-venv child,- which the mixed-version path explicitly supports and which has no gate at all,- it lands nowhere and the seeded password is served.+ Separate implementations in separate packages (the CLI cannot import the+ backend), consulted at different moments: the parent before re-exec, the child+ after. When they disagree the prompt lands in the child, and against an OLDER+ studio-venv child (supported by the mixed-version path, and with no gate) it+ lands nowhere and the seeded password is served.Measured before the fix: wildcard was False but exposed was True for192.168.1.50, 10.0.0.5, example.com, myhost.local, [::] and 0.0.0.0.0.@@ -1899,11 +1895,10 @@ def test_a_backgrounded_raw_bind_does_not_prompt(monkeypatch):"""`unsloth studio -H 0.0.0.0 &` must still launch.A background job inherits the terminal, so isatty() is True on both streams,- but the masked prompt calls termios.tcsetattr; POSIX sends SIGTTOU to a- background process group that does, and the default action STOPS the process.- The launch would freeze at the prompt before the socket binds, i.e. a launch- that worked before this gate widened to raw binds stops working. It keeps the- protection it already had, the bootstrap deadline.+ but the masked prompt calls termios.tcsetattr; POSIX SIGTTOUs a background+ process group that does, and the default action STOPS the process. The launch+ would freeze before the socket binds, so a launch that worked before this gate+ widened stops working. It keeps the bootstrap deadline it already had."""studio = _studio()monkeypatch.setattr(studio, "_prompt_streams_interactive", lambda: True)@@ -1917,8 +1912,7 @@ def test_a_backgrounded_raw_bind_does_not_prompt(monkeypatch):)is False)- # The tunnel is published on the public internet either way: it must keep- # failing closed rather than quietly proceeding.+ # A tunnel is public either way, so it keeps failing closed.assert (studio._should_prompt_password_change(cloudflare = None, host = "0.0.0.0", secure = True, api_only = False@@ -1978,11 +1972,10 @@ def test_an_unattended_pty_still_launches_a_raw_bind(monkeypatch, tmp_path):"""`tmux new -d 'unsloth studio -H 0.0.0.0'` must still start Unsloth.A detached pty (tmux/screen/`docker run -dt`) is a real, foreground terminal- that nobody will ever type into: both streams are ttys and the process owns- the terminal, so every interactivity test says "prompt" and the read then- never returns. The gate runs before any server exists, so without a deadline- the launch hangs forever instead of starting. It must fall back to the- protection it already had, the bootstrap deadline.+ nobody will ever type into: both streams are ttys and the process owns the+ terminal, so every interactivity test says "prompt" and the read never+ returns. The gate runs before any server exists, so undeadlined the launch+ hangs forever. It must fall back to the bootstrap deadline it already had."""studio_mod = _studio()events = _install_prompt_env(@@ -2095,10 +2088,10 @@ def test_the_exposure_wording_matches_what_will_actually_happen():"""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.+ `--cloudflare -H 192.168.1.50` requests a tunnel that will not start, since 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)@@ -2123,9 +2116,9 @@ def test_the_cli_deadline_sentence_tracks_the_configured_timeout(monkeypatch):def test_a_raw_bind_ctrl_c_does_not_abort_the_launch(monkeypatch, tmp_path):"""Ctrl+C on `unsloth studio -H 0.0.0.0` must leave it starting.- The CLI mirror is the gate that actually runs for that command, so if it- exits here the warn-and-proceed in run.py is unreachable and the docker- run -it case the two of them exist to protect is not protected at all.+ The CLI mirror is the gate that actually runs for that command, so exiting+ here makes run.py's warn-and-proceed unreachable and leaves the+ `docker run -it` case unprotected."""studio_mod = _studio()events = _install_prompt_env(monkeypatch, tmp_path, interactive = True)@@ -2166,10 +2159,9 @@ def test_a_second_cli_gate_does_not_re_wait_the_same_dead_terminal(monkeypatch,"""`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.+ already tried. Without honouring that the child waits the whole deadline+ again, so 30s becomes 60s before the backend gate even has its turn, long+ enough to trip a startup watchdog. Peeked, never popped: run.py consumes it."""studio_mod = _studio()calls = []@@ -2218,8 +2210,7 @@ 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.+ raw bind, so a second call in the same test would capture no banner."""import os as _os@@ -2242,10 +2233,10 @@ def test_the_banner_does_not_promise_an_abort_a_raw_bind_will_not_perform():"""`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.+ On a raw bind the interrupt declines the prompt and the launch continues by+ design, because it 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@@ -2258,8 +2249,8 @@ def test_the_banner_does_not_promise_an_abort_a_raw_bind_will_not_perform(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.+ The gate widened to is_external_host, routing concrete non-loopback hosts down+ the wildcard's path, where they inherited its wording."""concrete = _banner(monkeypatch, tmp_path, ["-H", "192.168.1.50"])assert "on every network interface" not in concrete