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
Studio: name the Git Bash MXC incompatibility and stop re-probing it (#12021)
Daniel Han22b80c27ecb6
diff --git a/studio/backend/core/inference/mxc_probe.py b/studio/backend/core/inference/mxc_probe.pyindex 9c91000bfda..f8cd2728f6a 100644--- a/studio/backend/core/inference/mxc_probe.py+++ b/studio/backend/core/inference/mxc_probe.py@@ -22,6 +22,12 @@ _cache: dict[tuple, tuple[float, bool, str]] = {}_inflight: dict[tuple, threading.Event] = {}POSITIVE_TTL = 300.0NEGATIVE_TTL = 30.0+# Re-probing a shell that cannot start costs ~15s of DACL-tier launches; the key changes with the runtime or the shell.+INCOMPATIBLE_TTL = 6 * 3600.0+MSYS_NAMESPACE_REASON = (+ "Git Bash (MSYS2) cannot start in the MXC container, which denies the global named-object "+ "directory it creates (microsoft/mxc#1061)."+)_host_prep_cache: dict[str, tuple[float, str | None]] = {}@@ -113,6 +119,36 @@ def _terminal_probe(selected_executable: str, workdir: Path, canary: Path, outsiraise ValueError(f"the selected Windows Terminal shell is not qualified for MXC: {name}")+def _is_msys_namespace_failure(selected_executable: str, execution_kind: str, output) -> bool:+ """msys-2.0.dll dies in DLL init when AppContainer denies its absolute \\BaseNamedObjects path."""+ name = Path(selected_executable).name.casefold()+ if execution_kind != "terminal" or name not in {"bash", "bash.exe"}:+ return False+ text = output or ""+ return (+ "NtCreateDirectoryObject" in text+ and "\\BaseNamedObjects\\" in text+ and "0xc0000022" in text.casefold()+ )+++def _executable_signature(selected_executable: str) -> tuple:+ """An in-place update (a Git for Windows upgrade) keeps the path, so a verdict also keys on the files."""+ paths = [selected_executable]+ if Path(selected_executable).name.casefold() in {"bash", "bash.exe"}:+ bin_dir = Path(selected_executable).parent+ paths += [bin_dir / "msys-2.0.dll", bin_dir.parent / "usr" / "bin" / "msys-2.0.dll"]+ signature = []+ for path in paths:+ try:+ stat = os.stat(path)+ except OSError:+ signature.append(None)+ else:+ signature.append((stat.st_mtime_ns, stat.st_size))+ return tuple(signature)++def _probe(selected_executable: str,execution_kind: str,@@ -230,6 +266,10 @@ def _probe(or result.get("exitCode") != 0or result.get("cleanup") != "complete"):+ if result.get("cleanup") == "complete" and _is_msys_namespace_failure(+ selected_executable, execution_kind, output+ ):+ return False, MSYS_NAMESPACE_REASONreturn False, "the live MXC probe did not complete cleanly"if execution_kind == "terminal":captured = workdir / "outside-read.txt"@@ -286,6 +326,7 @@ def probe(mxc_runtime.PROFILE_ID,execution_kind,os.path.abspath(selected_executable),+ _executable_signature(selected_executable),mxc_policy.dacl_fallback_enabled(),)while True:@@ -307,6 +348,8 @@ def probe(with _lock:if cancel_event is None or not cancel_event.is_set():ttl = POSITIVE_TTL if result[0] else NEGATIVE_TTL+ if result[1] == MSYS_NAMESPACE_REASON:+ ttl = INCOMPATIBLE_TTL_cache[key] = (time.monotonic() + ttl, *result)return resultfinally:diff --git a/studio/backend/core/inference/sandbox_windows_mxc.py b/studio/backend/core/inference/sandbox_windows_mxc.pyindex f0fda64aa03..e5c8936690e 100644--- a/studio/backend/core/inference/sandbox_windows_mxc.py+++ b/studio/backend/core/inference/sandbox_windows_mxc.py@@ -82,6 +82,13 @@ def capability_snapshot()if dacl:limitations += ("mxc_tier3_dacl_host_permission_changes",)+ shell_incompatible = reason == mxc_probe.MSYS_NAMESPACE_REASON+ if shell_incompatible:+ remediation = (+ "Set tool isolation to auto to run Terminal commands with software safeguards, or use "+ "the Python tool, which is sandboxed separately."+ )+ elif dacl:remediation = ("Install the pinned Microsoft WXC runtime and prepare this host once as an ""administrator; the null device step repeats after every reboot."@@ -94,7 +101,11 @@ def capability_snapshot("on exit, and needs a one-time administrator host preparation plus one per reboot.")# Only in DACL mode: a bare --probe allows the fallback, so it warns on hosts Studio never uses it on.- host_prep = mxc_probe.host_prep_remediation() if dacl and not available else None+ host_prep = (+ mxc_probe.host_prep_remediation()+ if dacl and not available and not shell_incompatible+ else None+ )if host_prep:remediation = f"{remediation} {host_prep}"return SandboxCapability(diff --git a/studio/backend/tests/test_mxc_git_bash_namespace.py b/studio/backend/tests/test_mxc_git_bash_namespace.pynew file mode 100644index 00000000000..6f11420cba6--- /dev/null+++ b/studio/backend/tests/test_mxc_git_bash_namespace.py@@ -0,0 +1,216 @@+# SPDX-License-Identifier: AGPL-3.0-only++from __future__ import annotations++from types import SimpleNamespace++import pytest++from core.inference import mxc_probe, os_sandbox, sandbox_windows_mxc++# What Git for Windows' bash prints under an AppContainer before it reads its command (microsoft/mxc#1061).+MSYS_STARTUP_FAILURE = (+ " 0 [main] bash (8852) C:\\Program Files\\Git\\bin\\..\\usr\\bin\\bash.exe: *** fatal error - "+ "NtCreateDirectoryObject(\\BaseNamedObjects\\msys-2.0S5-1888ae32e00d56aa): 0xC0000022\n"+)+DLL_INIT_FAILED = 3221225794 # 0xC0000142++[email protected](autouse = True)+def _fresh_probe_cache():+ mxc_probe.invalidate_cache()+ yield+ mxc_probe.invalidate_cache()+++def _run_probe(+ monkeypatch,+ tmp_path,+ executable,+ kind,+ output,+ exit_code,+ cleanup = "complete",+):+ class Finished:+ returncode = exit_code++ def poll(self):+ return exit_code++ def communicate(self, timeout = None):+ return output, None++ monkeypatch.setattr(mxc_probe.sys, "platform", "win32")+ monkeypatch.setattr(+ mxc_probe.sys, "getwindowsversion", lambda: SimpleNamespace(build = 26100), raising = False+ )+ monkeypatch.setattr(mxc_probe.mxc_runtime, "wxc_path", lambda: tmp_path / "wxc-exec.exe")+ monkeypatch.setattr(mxc_probe.mxc_policy, "build_launch_request", lambda _plan: {})+ monkeypatch.setattr(mxc_probe.mxc_adapter, "spawn", lambda *_a, **_k: Finished())+ monkeypatch.setattr(mxc_probe.mxc_adapter, "abort", lambda _proc: None)+ monkeypatch.setattr(mxc_probe.mxc_adapter, "release_runtime", lambda _proc: None)+ monkeypatch.setattr(+ mxc_probe.mxc_adapter,+ "completion_result",+ lambda _proc: {"exitCode": exit_code, "cleanup": cleanup},+ )+ monkeypatch.setattr(mxc_probe.subprocess, "CREATE_NO_WINDOW", 0, raising = False)+ return mxc_probe._probe(str(tmp_path / executable), kind)+++def test_git_bash_namespace_failure_is_named(monkeypatch, tmp_path):+ available, reason = _run_probe(+ monkeypatch, tmp_path, "bash.exe", "terminal", MSYS_STARTUP_FAILURE, DLL_INIT_FAILED+ )+ assert available is False+ assert reason == mxc_probe.MSYS_NAMESPACE_REASON+++ "executable, kind, output, cleanup",+ [+ # Another bash failure is not this one.+ ("bash.exe", "terminal", "bash: some other startup error\n", "complete"),+ # Uncertain cleanup outranks any diagnosis of the shell.+ ("bash.exe", "terminal", MSYS_STARTUP_FAILURE, "uncertain"),+ # The signature only means something from the shell it describes.+ ("cmd.exe", "terminal", MSYS_STARTUP_FAILURE, "complete"),+ ("pwsh.exe", "terminal", MSYS_STARTUP_FAILURE, "complete"),+ ("python.exe", "python", MSYS_STARTUP_FAILURE, "complete"),+ ],+)+def test_other_failures_keep_the_generic_reason(+ monkeypatch, tmp_path, executable, kind, output, cleanup+):+ available, reason = _run_probe(+ monkeypatch, tmp_path, executable, kind, output, DLL_INIT_FAILED, cleanup+ )+ assert available is False+ assert reason == "the live MXC probe did not complete cleanly"+++def _count_live_probes(monkeypatch, reason):+ clock = [1000.0]+ calls = []+ monkeypatch.setattr(mxc_probe.time, "monotonic", lambda: clock[0])+ monkeypatch.setattr(mxc_probe.mxc_runtime, "installation_identity", lambda: "runtime-a")++ def live_probe(+ executable,+ execution_kind,+ cancel_event = None,+ ):+ calls.append(executable)+ return False, reason++ monkeypatch.setattr(mxc_probe, "_probe", live_probe)+ return clock, calls+++def test_an_incompatible_shell_is_not_probed_again_each_negative_ttl(monkeypatch, tmp_path):+ clock, calls = _count_live_probes(monkeypatch, mxc_probe.MSYS_NAMESPACE_REASON)+ bash = str(tmp_path / "bash.exe")+ for _ in range(5):+ assert mxc_probe.probe(bash, execution_kind = "terminal") == (+ False,+ mxc_probe.MSYS_NAMESPACE_REASON,+ )+ clock[0] += mxc_probe.NEGATIVE_TTL + 1+ assert len(calls) == 1+ clock[0] += mxc_probe.INCOMPATIBLE_TTL+ mxc_probe.probe(bash, execution_kind = "terminal")+ assert len(calls) == 2+++def test_a_generic_failure_still_expires_at_the_negative_ttl(monkeypatch, tmp_path):+ clock, calls = _count_live_probes(monkeypatch, "the live MXC probe did not complete cleanly")+ bash = str(tmp_path / "bash.exe")+ mxc_probe.probe(bash, execution_kind = "terminal")+ clock[0] += mxc_probe.NEGATIVE_TTL + 1+ mxc_probe.probe(bash, execution_kind = "terminal")+ assert len(calls) == 2+++def test_a_new_runtime_or_opt_in_probes_the_shell_again(monkeypatch, tmp_path):+ _clock, calls = _count_live_probes(monkeypatch, mxc_probe.MSYS_NAMESPACE_REASON)+ bash = str(tmp_path / "bash.exe")+ monkeypatch.delenv("UNSLOTH_MXC_ALLOW_DACL_FALLBACK", raising = False)+ mxc_probe.probe(bash, execution_kind = "terminal")+ monkeypatch.setenv("UNSLOTH_MXC_ALLOW_DACL_FALLBACK", "1")+ mxc_probe.probe(bash, execution_kind = "terminal")+ monkeypatch.setattr(mxc_probe.mxc_runtime, "installation_identity", lambda: "runtime-b")+ mxc_probe.probe(bash, execution_kind = "terminal")+ assert len(calls) == 3+++def _incompatible_snapshot(monkeypatch):+ monkeypatch.setattr(sandbox_windows_mxc.sys, "platform", "win32")+ monkeypatch.setenv("UNSLOTH_MXC_ALLOW_DACL_FALLBACK", "1")+ monkeypatch.setattr(+ sandbox_windows_mxc.mxc_probe,+ "probe",+ lambda *_a, **_k: (False, mxc_probe.MSYS_NAMESPACE_REASON),+ )+ monkeypatch.setattr(sandbox_windows_mxc.mxc_runtime, "installation_identity", lambda: "runner")+ monkeypatch.setattr(+ mxc_probe.mxc_runtime,+ "probe_host_prep_steps",+ lambda **_kwargs: pytest.fail("host preparation was probed for a shell it cannot help"),+ )+++def test_the_remediation_names_the_shell_not_setup(monkeypatch, tmp_path):+ _incompatible_snapshot(monkeypatch)+ capability = sandbox_windows_mxc.capability_snapshot(+ execution_kind = "terminal", selected_executable = str(tmp_path / "bash.exe")+ )+ assert capability.available is False+ assert capability.reason == mxc_probe.MSYS_NAMESPACE_REASON+ assert "Install the pinned" not in capability.remediation+ assert "prepare" not in capability.remediation+ assert "Python tool" in capability.remediation+++def _terminal_plan(tmp_path, mode):+ return os_sandbox.ToolLaunchPlan(+ argv = (str(tmp_path / "bash.exe"), "-c", "echo hi"),+ workdir = str(tmp_path),+ env = {"PATH": "trusted"},+ requested_mode = mode,+ timeout_seconds = 10,+ execution_kind = "terminal",+ )+++def test_auto_runs_the_terminal_with_software_safeguards(monkeypatch, tmp_path):+ _incompatible_snapshot(monkeypatch)+ prepared = os_sandbox.prepare_tool_launch(_terminal_plan(tmp_path, "auto"))+ assert prepared.backend == "software-safeguards"+ assert prepared.execution_record.effective_mode == "software_safeguards"+ assert prepared.argv[0] == str(tmp_path / "bash.exe")+++def test_required_refuses_with_the_real_cause(monkeypatch, tmp_path):+ _incompatible_snapshot(monkeypatch)+ with pytest.raises(os_sandbox.SandboxUnavailableError) as raised:+ os_sandbox.prepare_tool_launch(_terminal_plan(tmp_path, "required"))+ assert "Git Bash" in str(raised.value)+ assert "Install the pinned" not in raised.value.remediation+++def test_an_in_place_git_update_probes_the_shell_again(monkeypatch, tmp_path):+ _clock, calls = _count_live_probes(monkeypatch, mxc_probe.MSYS_NAMESPACE_REASON)+ bin_dir = tmp_path / "Git" / "usr" / "bin"+ bin_dir.mkdir(parents = True)+ bash = bin_dir / "bash.exe"+ bash.write_bytes(b"bash")+ runtime = bin_dir / "msys-2.0.dll"+ runtime.write_bytes(b"msys-old")+ mxc_probe.probe(str(bash), execution_kind = "terminal")+ mxc_probe.probe(str(bash), execution_kind = "terminal")+ assert len(calls) == 1+ # Same path, new runtime: an upgrade that may have fixed the namespace call.+ runtime.write_bytes(b"msys-new-and-longer")+ mxc_probe.probe(str(bash), execution_kind = "terminal")+ assert len(calls) == 2diff --git a/studio/backend/tests/test_mxc_native_windows.py b/studio/backend/tests/test_mxc_native_windows.pyindex a2c5b7d5b4f..9574a17a482 100644--- a/studio/backend/tests/test_mxc_native_windows.py+++ b/studio/backend/tests/test_mxc_native_windows.py@@ -555,3 +555,28 @@ def test_native_mxc_session_packages_import_inside_the_container():)assert "SIX 1.16.0" in imported, importedassert os_sandbox.SESSION_PACKAGES_RELPATH in imported, imported+++def test_native_git_bash_is_named_and_not_reprobed(monkeypatch):+ """Git Bash cannot start in the container (microsoft/mxc#1061); say so, and answer from cache after that."""+ _require_native_mxc()+ bash = tools._windows_bash()+ if not bash:+ pytest.skip("no trusted Git Bash on this host")+ first = sandbox_windows_mxc.capability_snapshot(+ force = True, execution_kind = "terminal", selected_executable = bash+ )+ if first.available:+ pytest.skip("this MXC tier starts Git Bash, so there is no incompatibility to report")+ assert first.reason == mxc_probe.MSYS_NAMESPACE_REASON, first.reason+ assert "Install the pinned" not in first.remediation+ probed = []+ monkeypatch.setattr(+ mxc_probe, "_probe", lambda *args, **_kwargs: probed.append(args) or (True, "")+ )+ again = sandbox_windows_mxc.capability_snapshot(+ execution_kind = "terminal", selected_executable = bash+ )+ assert probed == [], "the incompatible shell was probed again"+ assert again.reason == mxc_probe.MSYS_NAMESPACE_REASON