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.

Fix Windows MXC runtime grants for uv-managed Python (#12756)

Lee Jackson003448a3e243
diff --git a/studio/backend/core/inference/mxc_policy.py b/studio/backend/core/inference/mxc_policy.py
index d6c4ffe5a0d..cd4f685664a 100644
--- a/studio/backend/core/inference/mxc_policy.py
+++ b/studio/backend/core/inference/mxc_policy.py
@@ -213,7 +213,12 @@ def _trusted_terminal_path_dirs(plan) -> list[str]:
def _runtime_read_roots(executable: str, extra: list[str] = ()) -> list[str]:
# Preserve the lexical executable for launch. Grants may use canonical roots,
# but never broaden to the user profile or a drive root.
- roots = [os.path.dirname(os.path.abspath(executable)), sys.prefix, sys.base_prefix, *extra]
+ # uv's managed Python base_prefix can be a version-independent junction.
+ # Resolve this interpreter-owned root before validation so the grant names
+ # the concrete runtime, not a redirect uv can retarget on upgrade. Keep
+ # strict reparse rejection for executables, workdirs and other grant inputs.
+ base_prefix = os.path.realpath(sys.base_prefix)
+ roots = [os.path.dirname(os.path.abspath(executable)), sys.prefix, base_prefix, *extra]
roots.extend(site.getsitepackages())
roots.append(str(Path(__file__).with_name("sandbox_site")))
system_root = os.environ.get("SystemRoot") or os.environ.get("WINDIR")
diff --git a/studio/backend/tests/test_mxc_windows_backend.py b/studio/backend/tests/test_mxc_windows_backend.py
index 3ec130c316e..0dbcfedb9bd 100644
--- a/studio/backend/tests/test_mxc_windows_backend.py
+++ b/studio/backend/tests/test_mxc_windows_backend.py
@@ -947,3 +947,37 @@ def test_editable_package_sources_are_granted_read_only(monkeypatch, tmp_path):
assert str(package) in readonly
assert str(module) not in readonly
assert str(tmp_path / "checkout") not in readonly
+
+
+def test_uv_base_prefix_junction_grants_concrete_runtime(monkeypatch, tmp_path):
+ from core.inference import mxc_policy
+
+ prefix = tmp_path / "venv"
+ prefix.mkdir()
+ base = tmp_path / "cpython-3.13.14"
+ base.mkdir()
+ alias = tmp_path / "cpython-3.13"
+ if os.name == "nt":
+ import subprocess
+ subprocess.run(
+ ["cmd.exe", "/d", "/c", "mklink", "/J", str(alias), str(base)],
+ check = True,
+ capture_output = True,
+ )
+ else:
+ alias.symlink_to(base, target_is_directory = True)
+ monkeypatch.setattr(mxc_policy.sys, "prefix", str(prefix))
+ monkeypatch.setattr(mxc_policy.sys, "base_prefix", str(alias))
+ monkeypatch.setattr(mxc_policy.site, "getsitepackages", lambda: [])
+ monkeypatch.delenv("SystemRoot", raising = False)
+ monkeypatch.delenv("WINDIR", raising = False)
+ roots = mxc_policy._runtime_read_roots(str(prefix / "python.exe"))
+ assert str(base.resolve()) in roots
+ assert str(alias) not in roots
+ assert str(tmp_path) not in roots
+ # The exception belongs only to Python's own base prefix. Arbitrary grants
+ # and workdirs must still reject the same redirect.
+ with pytest.raises(mxc_policy.MxcPolicyError, match = "reparse point"):
+ mxc_policy._runtime_read_roots(str(prefix / "python.exe"), [str(alias)])
+ with pytest.raises(mxc_policy.MxcPolicyError, match = "reparse point"):
+ mxc_policy._safe_canonical_path(str(alias), directory = True)