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
fix(studio): WSL2 Windows localhost hint in startup banner (#11187) (#11361)
Sourav Rajvicd4d5c197f7f
diff --git a/studio/backend/run.py b/studio/backend/run.pyindex f9b8b1b66da..0d25bd0ddf5 100644--- a/studio/backend/run.py+++ b/studio/backend/run.py@@ -348,11 +348,16 @@ def _print_localhost_ipv6_mismatch_warning(local_url: str, port: int) -> None:)-def _verify_global_reachability(display_host: str, port: int) -> None:+def _verify_global_reachability(+ display_host: str,+ port: int,+ wsl_nat: bool = False,+) -> None:"""Probe check-host.net to confirm display_host:port is reachable from the public internet. Synchronous sooutput lands between the banner URLs and the stop hint. Bounded at ~15s; failures swallowed (verifierfailing is not Unsloth failing). Only meaningful for a wildcard bind, and skipped entirely by- UNSLOTH_STUDIO_DISABLE_PUBLIC_CHECK."""+ UNSLOTH_STUDIO_DISABLE_PUBLIC_CHECK. ``wsl_nat``: the private address is WSL's NAT side, not a LAN+ one, and the WSL note already printed says so."""global _public_reachable# Reset to "unknown" each run; set True/False only when the probe decides._public_reachable = None@@ -381,6 +386,8 @@ def _verify_global_reachability(display_host: str, port: int) -> None:addr = ipaddress.ip_address(display_host)if addr.is_loopback or addr.is_private or addr.is_link_local:_public_reachable = False+ if wsl_nat:+ returnprint(f"{dim} Note: {display_host} is a private/LAN address -- "f"reachable on this network only, not from the public internet."@@ -536,6 +543,32 @@ def _network_share_host_for_bind(host: str) -> str:return host+def _is_wsl_nat() -> bool:+ from lan_access import _wsl_networking_mode++ # "unknown" = WSL too old for wslinfo, which is NAT; "none" has no network at all.+ if _wsl_networking_mode() not in ("nat", "unknown"):+ return False+ # Imported only on WSL: every wildcard bind reaches here. A container on Docker Desktop's WSL2+ # kernel also reads "unknown", but its host port is whatever -p published.+ from utils.paths.file_manager import _in_container++ return not _in_container()+++def _print_wsl_windows_hint(port: int) -> None:+ """WSL2 NAT has no LAN URL to print, but Windows reaches a wildcard bind through localhost+ forwarding (#11187). Printed where the reachability note goes, which it stands in for."""+ dim = "\033[38;5;245m" if _stdout_color_ok() else ""+ reset = "\033[0m" if dim else ""+ print(+ f"{dim} WSL2: open http://localhost:{port} in a Windows browser. Other devices on your "+ f"network can't reach WSL's NAT address; set networkingMode=mirrored in "+ f"%UserProfile%\\.wslconfig for LAN access.{reset}",+ flush = True,+ )++def _loopback_bind_host_for(host: str) -> str:return wildcard_loopback_host(host) or "127.0.0.1"@@ -628,7 +661,10 @@ def _emit_startup_output(if localhost_mismatch_url:_print_localhost_ipv6_mismatch_warning(localhost_mismatch_url, port)elif wildcard_bind:- _verify_global_reachability(display_host, port)+ wsl_nat = _is_wsl_nat()+ if wsl_nat:+ _print_wsl_windows_hint(port)+ _verify_global_reachability(display_host, port, wsl_nat = wsl_nat)_print_cloudflare_line(loopback_host = _loopback_bind_host_for(host))_emit_tool_policy_notice(lan_addresses[0] if lan_addresses else host, False, enable_tools)print_studio_stop_hint()diff --git a/studio/backend/tests/test_startup_banner_loopback.py b/studio/backend/tests/test_startup_banner_loopback.pyindex 9a541562d7f..1f19ee88ccc 100644--- a/studio/backend/tests/test_startup_banner_loopback.py+++ b/studio/backend/tests/test_startup_banner_loopback.py@@ -43,6 +43,89 @@ def test_wildcard_aliases_show_reachable_urls(capsys, host, loopback_url):assert "http://192.168.1.24:8891" in out+WSL_HINT = "WSL2: open http://localhost:"++[email protected]("mode,wsl", [("nat", True), (None, False)])+def test_wsl_hint_replaces_the_private_address_note(capsys, monkeypatch, mode, wsl):+ # Under WSL NAT the private address is WSL's own, so "reachable on this network" would be wrong.+ import lan_access+ import run+ from utils.paths import file_manager++ monkeypatch.setattr(lan_access, "_wsl_networking_mode", lambda: mode)+ monkeypatch.setattr(file_manager, "_in_container", lambda: False)+ monkeypatch.setattr(run, "_network_share_host_for_bind", lambda h: h)+ monkeypatch.setattr(run, "_print_cloudflare_line", lambda *a, **k: None)+ monkeypatch.setattr(run, "_localhost_ipv6_mismatch_url", lambda *a, **k: None)+ run._emit_startup_output("0.0.0.0", 8888, "172.25.35.232")+ out = capsys.readouterr().out+ assert (WSL_HINT + "8888" in out) is wsl+ assert ("networkingMode=mirrored" in out) is wsl+ assert ("172.25.35.232 is a private/LAN address" in out) is not wsl+ assert run._public_reachable is False+ if wsl:+ assert out.index("/api/health") < out.index(WSL_HINT)+++ "host,mode,expected",+ [+ ("0.0.0.0", "nat", True),+ ("::", "nat", True),+ ("0.0.0.0", "unknown", True),+ ("0.0.0.0", "none", False),+ ("0.0.0.0", "mirrored", False),+ ("0.0.0.0", None, False),+ ("127.0.0.1", "nat", False),+ ],+)+def test_startup_output_wsl_hint_gating(capsys, monkeypatch, host, mode, expected):+ import lan_access+ import run+ from utils.paths import file_manager++ monkeypatch.setattr(lan_access, "_wsl_networking_mode", lambda: mode)+ monkeypatch.setattr(file_manager, "_in_container", lambda: False)+ monkeypatch.setattr(run, "_network_share_host_for_bind", lambda h: h)+ monkeypatch.setattr(run, "_verify_global_reachability", lambda *a, **k: None)+ monkeypatch.setattr(run, "_print_cloudflare_line", lambda *a, **k: None)+ monkeypatch.setattr(run, "_localhost_ipv6_mismatch_url", lambda *a, **k: None)+ run._emit_startup_output(host, 8888, host)+ assert (WSL_HINT in capsys.readouterr().out) is expected+++def test_startup_output_wsl_hint_skipped_in_container(capsys, monkeypatch):+ import lan_access+ import run+ from utils.paths import file_manager++ monkeypatch.setattr(lan_access, "_wsl_networking_mode", lambda: "unknown")+ monkeypatch.setattr(file_manager, "_in_container", lambda: True)+ monkeypatch.setattr(run, "_network_share_host_for_bind", lambda h: h)+ monkeypatch.setattr(run, "_verify_global_reachability", lambda *a, **k: None)+ monkeypatch.setattr(run, "_print_cloudflare_line", lambda *a, **k: None)+ monkeypatch.setattr(run, "_localhost_ipv6_mismatch_url", lambda *a, **k: None)+ run._emit_startup_output("0.0.0.0", 8000, "0.0.0.0")+ assert WSL_HINT not in capsys.readouterr().out+++def test_wsl_hint_check_skips_container_import_off_wsl(capsys, monkeypatch):+ # Every wildcard bind runs the WSL check, so off WSL it must not need the container probe's module+ # (a stubbed utils.paths in tests/studio/install has none).+ import lan_access+ import run++ monkeypatch.setattr(lan_access, "_wsl_networking_mode", lambda: None)+ monkeypatch.setitem(sys.modules, "utils.paths.file_manager", None)+ monkeypatch.setattr(run, "_network_share_host_for_bind", lambda h: h)+ monkeypatch.setattr(run, "_verify_global_reachability", lambda *a, **k: None)+ monkeypatch.setattr(run, "_print_cloudflare_line", lambda *a, **k: None)+ monkeypatch.setattr(run, "_localhost_ipv6_mismatch_url", lambda *a, **k: None)+ run._emit_startup_output("0.0.0.0", 8000, "0.0.0.0")+ assert WSL_HINT not in capsys.readouterr().out++def test_banner_prints_on_strict_cp1252_stdout(monkeypatch):buf = io.BytesIO()stdout = io.TextIOWrapper(buf, encoding = "cp1252", errors = "strict")diff --git a/tests/studio/install/test_selection_logic.py b/tests/studio/install/test_selection_logic.pyindex 30e09461044..a0a83abdf4d 100644--- a/tests/studio/install/test_selection_logic.py+++ b/tests/studio/install/test_selection_logic.py@@ -454,7 +454,7 @@ class TestStudioLocalhostIpv6Warning:monkeypatch.setattr(run_module,"_verify_global_reachability",- lambda display_host, port: calls["reachability"].append((display_host, port)),+ lambda display_host, port, **_: calls["reachability"].append((display_host, port)),)return calls