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
unsloth start vscode: print the group instead of writing a dead file inside a plain container (#14237)
Daniel Hand6a7ae8bd617
diff --git a/unsloth_cli/commands/start.py b/unsloth_cli/commands/start.pyindex ae20bfd39db..3df0db45c43 100644--- a/unsloth_cli/commands/start.py+++ b/unsloth_cli/commands/start.py@@ -6557,11 +6557,33 @@ def _vscode_capabilities(base: str, key: str, entry: dict) -> tuple:)-def _vscode_over_ssh(path: Path) -> bool:- if sys.platform in ("win32", "darwin") or path.parent.is_dir():+def _container_engine() -> Optional[str]:+ # `docker run unsloth/unsloth` sets none of the env vars below, only these markers.+ if os.path.exists("/.dockerenv"):+ return "docker"+ if os.path.exists("/run/.containerenv"):+ return "podman"+ return None+++_VSCODE_REMOTE_ENV = ("SSH_CONNECTION", "SSH_CLIENT", "SSH_TTY", "REMOTE_CONTAINERS", "CODESPACES")+++def _vscode_over_ssh(path: Path, unconfirmed: bool = False) -> bool:+ if sys.platform in ("win32", "darwin"):return False- remote = ("SSH_CONNECTION", "SSH_CLIENT", "SSH_TTY", "REMOTE_CONTAINERS", "CODESPACES")- return any(os.environ.get(name) for name in remote)+ if path.parent.is_dir():+ # In a container, a dir holding only what an earlier release of this command wrote there+ # (state without "written") is not VS Code's.+ return (+ unconfirmed+ and _container_engine() is not None+ and path.is_file()+ and all(p.name.lstrip(".").startswith(path.name) for p in path.parent.iterdir())+ )+ return (+ any(os.environ.get(name) for name in _VSCODE_REMOTE_ENV) or _container_engine() is not None+ )def _add_vscode_provider(@@ -6579,7 +6601,7 @@ def _add_vscode_provider(state_path, state, text, key, key_id = _open_app_config(target, base, explicit_key, _vscode_groups)- remote = _vscode_over_ssh(target.path)+ remote = _vscode_over_ssh(target.path, bool(state) and not state.get("written"))new_text = _vscode_models_text(None if remote else text,target.path,@@ -6598,6 +6620,7 @@ def _add_vscode_provider("key": key,"key_id": key_id,"models": [entry["id"]],+ "written": not remote,}if remote:# Keep the key in state so a re-run reuses it; a file here would never be read.@@ -6611,12 +6634,20 @@ def _add_vscode_provider(if remote:url = urlparse(base)port = url.port or (443 if url.scheme == "https" else 80)- reach = (- f"forward port {port} to the same port on your machine (for example: "- f"ssh -L {port}:127.0.0.1:{port} <this host>)"- if is_loopback_url(base)- else f"make sure your machine can reach {base}"- )+ managed = any(os.environ.get(name) for name in _VSCODE_REMOTE_ENV)+ engine = _container_engine()+ if not is_loopback_url(base):+ reach = f"make sure your machine can reach {base}"+ elif engine and not managed:+ reach = (+ f"publish port {port} to the same port on your machine (for example: "+ f"{engine} run -p {port}:{port} ...)"+ )+ else:+ reach = (+ f"forward port {port} to the same port on your machine (for example: "+ f"ssh -L {port}:127.0.0.1:{port} <this host>)"+ )typer.echo("This is a remote session (SSH or a container) with no VS Code user dir here, so ""nothing was written. VS Code does not list these models in remote windows yet "diff --git a/unsloth_cli/tests/test_start_app.py b/unsloth_cli/tests/test_start_app.pyindex df6c6741766..ef4f41a7e34 100644--- a/unsloth_cli/tests/test_start_app.py+++ b/unsloth_cli/tests/test_start_app.py@@ -863,6 +863,84 @@ def test_vscode_in_a_dev_container_prints_the_group(studio, monkeypatch, name):assert not (studio["home"] / ".config" / "Code").exists()+ "marker, engine", [("/.dockerenv", "docker"), ("/run/.containerenv", "podman")]+)+def test_vscode_in_a_plain_container_prints_the_group(studio, monkeypatch, marker, engine):+ monkeypatch.delenv("XDG_CONFIG_HOME", raising = False)+ monkeypatch.setattr(start.sys, "platform", "linux")+ for var in ("SSH_CONNECTION", "SSH_CLIENT", "SSH_TTY", "REMOTE_CONTAINERS", "CODESPACES"):+ monkeypatch.delenv(var, raising = False)+ real_exists = os.path.exists+ monkeypatch.setattr(+ start.os.path,+ "exists",+ lambda p: p == marker+ or (p not in ("/.dockerenv", "/run/.containerenv") and real_exists(p)),+ )+ user_dir = studio["home"] / ".config" / "Code" / "User"++ result = CliRunner().invoke(start.start_app, ["vscode"])++ assert result.exit_code == 0, result.output+ assert "nothing was written" in result.output+ assert f"{engine} run -p 8888:8888" in result.output and "ssh -L" not in result.output+ assert not user_dir.exists()++ # A dead file an earlier release wrote here is left alone and the group is still printed.+ user_dir.mkdir(parents = True)+ (user_dir / "chatLanguageModels.json").write_text("[]\n")+ (user_dir / "chatLanguageModels.json.unsloth-backup").write_text("[]\n")+ result = CliRunner().invoke(start.start_app, ["vscode"])+ assert result.exit_code == 0, result.output+ assert "nothing was written" in result.output+ assert (user_dir / "chatLanguageModels.json").read_text() == "[]\n"++ # VS Code itself running in the container keeps the write.+ (user_dir / "globalStorage").mkdir()+ assert CliRunner().invoke(start.start_app, ["vscode"]).exit_code == 0+ assert "Unsloth" in (user_dir / "chatLanguageModels.json").read_text()+++def test_vscode_in_a_container_writes_a_user_dir_it_never_targeted(studio, monkeypatch):+ # A bind-mounted or fresh VS Code user dir holding only this file is VS Code's, not residue.+ config = _vscode_config(studio, monkeypatch)+ config.write_text("[]\n")+ monkeypatch.setattr(start, "_container_engine", lambda: "docker")+ for var in start._VSCODE_REMOTE_ENV:+ monkeypatch.delenv(var, raising = False)++ result = CliRunner().invoke(start.start_app, ["vscode"])++ assert result.exit_code == 0, result.output+ assert "nothing was written" not in result.output+ assert [g["name"] for g in json.loads(config.read_text())] == ["Unsloth"]++ # Its own earlier write there does not make the dir look stale.+ monkeypatch.setitem(MODEL, "id", "unsloth/Qwen3.5-4B-GGUF")+ result = CliRunner().invoke(start.start_app, ["vscode"])+ assert result.exit_code == 0, result.output+ assert "nothing was written" not in result.output+ assert [m["id"] for m in json.loads(config.read_text())[0]["models"]] == [MODEL["id"]]++[email protected]("name", ["REMOTE_CONTAINERS", "CODESPACES"])+def test_vscode_in_a_docker_backed_dev_container_keeps_the_forwarding_hint(+ studio, monkeypatch, name+):+ monkeypatch.delenv("XDG_CONFIG_HOME", raising = False)+ monkeypatch.setattr(start.sys, "platform", "linux")+ for var in start._VSCODE_REMOTE_ENV:+ monkeypatch.delenv(var, raising = False)+ monkeypatch.setenv(name, "true")+ monkeypatch.setattr(start, "_container_engine", lambda: "docker")++ result = CliRunner().invoke(start.start_app, ["vscode"])++ assert result.exit_code == 0, result.output+ assert "ssh -L 8888:127.0.0.1:8888" in result.output and "docker run" not in result.output++@pytest.mark.skipif(os.name == "nt", reason = "WSL paths are POSIX paths")def test_vscode_under_wsl_says_to_use_a_local_window(studio, monkeypatch, tmp_path):monkeypatch.setattr(start.sys, "platform", "linux")