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.

Keep managed vLLM and SGLang environments usable across Docker updates (#15024)

Nilay263af9cda39b
diff --git a/studio/backend/core/inference/engine_install.py b/studio/backend/core/inference/engine_install.py
index 6bb6239d9c7..e3ee472f78c 100644
--- a/studio/backend/core/inference/engine_install.py
+++ b/studio/backend/core/inference/engine_install.py
@@ -1145,6 +1145,13 @@ def install_environment() -> dict[str, str]:
}
from utils.paths.storage_roots import cache_root
+ # Docker replaces the app tree (and /root) on update while engine venvs persist on the
+ # home volume, so their uv-managed interpreters must live beside them.
+ app = os.environ.get("UNSLOTH_STUDIO_APP")
+ python_home = env.get("UV_PYTHON_INSTALL_DIR")
+ if app and (not python_home or Path(python_home).resolve().is_relative_to(Path(app).resolve())):
+ env["UV_PYTHON_INSTALL_DIR"] = str(engine_root() / "python")
+
recorded_cache = None
try:
raw = (cache_root() / "uv-cache-dir").read_bytes().decode("utf-8-sig")
diff --git a/studio/backend/tests/test_managed_engines.py b/studio/backend/tests/test_managed_engines.py
index 080a9ebb434..6f6bb570d65 100644
--- a/studio/backend/tests/test_managed_engines.py
+++ b/studio/backend/tests/test_managed_engines.py
@@ -646,6 +646,49 @@ def test_installer_reuses_recorded_cache(monkeypatch, tmp_path):
assert install.install_environment()["UV_CACHE_DIR"] == str(tmp_path / "explicit")
[email protected]("image_python", [False, True])
+def test_docker_engine_python_survives_image_replacement(isolated, monkeypatch, image_python):
+ import shutil
+
+ app = isolated / "app"
+ app.mkdir()
+ monkeypatch.setenv("UNSLOTH_STUDIO_APP", str(app))
+ monkeypatch.delenv("UV_PYTHON_INSTALL_DIR", raising = False)
+ if image_python:
+ (app / "python").mkdir()
+ linked_python = isolated / "linked-python"
+ linked_python.symlink_to(app / "python", target_is_directory = True)
+ monkeypatch.setenv("UV_PYTHON_INSTALL_DIR", str(linked_python))
+
+ # Model uv's interpreter symlink with a small file, then discard the app layer.
+ python_home = Path(install.install_environment()["UV_PYTHON_INSTALL_DIR"])
+ python_home.mkdir(parents = True, exist_ok = True)
+ interpreter = python_home / "python3.13"
+ interpreter.touch()
+ for engine in ("vllm", "sglang"):
+ marker = active(isolated, engine)
+ python = marker.parent / "env-prior" / "bin" / "python"
+ python.unlink()
+ python.symlink_to(interpreter)
+ shutil.rmtree(app)
+ app.mkdir()
+ for engine in ("vllm", "sglang"):
+ assert install.installed(engine) is not None
+
+
+def test_docker_engine_python_respects_external_store(isolated, monkeypatch):
+ monkeypatch.setenv("UNSLOTH_STUDIO_APP", str(isolated / "app"))
+ external = str(isolated / "persistent-python")
+ monkeypatch.setenv("UV_PYTHON_INSTALL_DIR", external)
+ assert install.install_environment()["UV_PYTHON_INSTALL_DIR"] == external
+
+
+def test_native_engine_python_keeps_uv_default(isolated, monkeypatch):
+ monkeypatch.delenv("UNSLOTH_STUDIO_APP", raising = False)
+ monkeypatch.delenv("UV_PYTHON_INSTALL_DIR", raising = False)
+ assert "UV_PYTHON_INSTALL_DIR" not in install.install_environment()
+
+
@pytest.mark.parametrize("engine", ["vllm", "sglang"])
def test_argv_owns_network_and_memory_settings(engine):
argv = launch_arguments(engine, "/env/bin/python", "org/model", 45678, "private", 4096)