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 the browser matrix TMPDIR out of the checkout (#11605)

Daniel Han9829e51a0dfc
diff --git a/.github/workflows/studio-composer-compatibility.yml b/.github/workflows/studio-composer-compatibility.yml
index bfbbeba5256..153a7a5de4a 100644
--- a/.github/workflows/studio-composer-compatibility.yml
+++ b/.github/workflows/studio-composer-compatibility.yml
@@ -78,10 +78,13 @@ jobs:
run: npm ci --ignore-scripts --no-fund --no-audit
- name: Create isolated test environment
run: |
- mkdir -p temp/queue-validation/tmp
- echo "TMPDIR=$GITHUB_WORKSPACE/temp/queue-validation/tmp" >> "$GITHUB_ENV"
- echo "TMP=$GITHUB_WORKSPACE/temp/queue-validation/tmp" >> "$GITHUB_ENV"
- echo "TEMP=$GITHUB_WORKSPACE/temp/queue-validation/tmp" >> "$GITHUB_ENV"
+ # Branded Chrome and Edge put a unix socket in TMPDIR and abort when its path passes
+ # 107 bytes. Under the checkout that path grows with the repository name, so a fork
+ # with a longer name failed every chrome and msedge leg; RUNNER_TEMP is short everywhere.
+ mkdir -p "$RUNNER_TEMP/qv"
+ echo "TMPDIR=$RUNNER_TEMP/qv" >> "$GITHUB_ENV"
+ echo "TMP=$RUNNER_TEMP/qv" >> "$GITHUB_ENV"
+ echo "TEMP=$RUNNER_TEMP/qv" >> "$GITHUB_ENV"
python -m venv temp/queue-validation/venv
python - <<'PY'
import os
diff --git a/.github/workflows/workflow-trigger-lint.yml b/.github/workflows/workflow-trigger-lint.yml
index 59d550184c9..81658a9391c 100644
--- a/.github/workflows/workflow-trigger-lint.yml
+++ b/.github/workflows/workflow-trigger-lint.yml
@@ -144,6 +144,7 @@ jobs:
tests/studio/test_pip_cache_naming.py \
tests/studio/test_compile_caches_are_per_worker.py \
tests/studio/test_browser_simulations_retry_once.py \
+ tests/studio/test_composer_browser_tmpdir_is_short.py \
tests/studio/test_composer_rtl_bidi_attribute.py \
tests/studio/test_frontend_dep_removal.py \
tests/studio/test_frontend_dist_cache.py \
diff --git a/tests/studio/run_composer_compatibility.py b/tests/studio/run_composer_compatibility.py
index 04563058dac..d95c04bb0e6 100644
--- a/tests/studio/run_composer_compatibility.py
+++ b/tests/studio/run_composer_compatibility.py
@@ -7,8 +7,10 @@ import argparse
import json
import os
import platform
+import shutil
import subprocess
import sys
+import tempfile
from pathlib import Path
from _playwright_robust import stop_process
@@ -24,8 +26,46 @@ def main():
output = (root / args.output).resolve()
output.relative_to(root)
output.mkdir(parents = True, exist_ok = True)
- temp = root / "temp/queue-validation/tmp"
- temp.mkdir(parents = True, exist_ok = True)
+ temp = browser_tmpdir()
+ try:
+ return _run(args, root, output, temp)
+ finally:
+ shutil.rmtree(temp, ignore_errors = True)
+
+
+# Branded Chrome and Edge put `$TMPDIR/<vendor dir>/SingletonSocket` at launch and abort
+# when that does not fit sockaddr_un.sun_path, less its terminating NUL: 108 bytes on Linux, 104 on
+# macOS and the BSDs.
+# Edge names its directory `com.microsoft.Edge.XXXXXX`, one byte longer than Chrome's, and the
+# runner launches both, so the longest one is what has to fit.
+BROWSER_SOCKETS = (
+ "/com.google.Chrome.XXXXXX/SingletonSocket",
+ "/com.microsoft.Edge.XXXXXX/SingletonSocket",
+)
+LONGEST_SOCKET = max(BROWSER_SOCKETS, key = len)
+
+
+def sun_path_max() -> int:
+ return 107 if sys.platform.startswith("linux") else 103
+
+
+def browser_tmpdir() -> Path:
+ """A fresh TMPDIR short enough for Chrome's socket, never under the checkout.
+
+ The system temp dir is used when it fits. An inherited TMPDIR that is too long, or that sits
+ inside the checkout, falls back to /tmp, the one short path every POSIX host has."""
+ root = Path(__file__).resolve().parents[2]
+ made = Path(tempfile.mkdtemp(prefix = "uqv-"))
+ if os.name == "nt" or (
+ len(os.fsencode(made)) + len(LONGEST_SOCKET) <= sun_path_max()
+ and root not in made.resolve().parents
+ ):
+ return made
+ made.rmdir()
+ return Path(tempfile.mkdtemp(prefix = "uqv-", dir = "/tmp"))
+
+
+def _run(args, root: Path, output: Path, temp: Path) -> int:
env = {**os.environ, "TMPDIR": str(temp), "TMP": str(temp), "TEMP": str(temp)}
verdicts = []
for browser in args.browsers:
diff --git a/tests/studio/test_composer_browser_tmpdir_is_short.py b/tests/studio/test_composer_browser_tmpdir_is_short.py
new file mode 100644
index 00000000000..013842cdb0a
--- /dev/null
+++ b/tests/studio/test_composer_browser_tmpdir_is_short.py
@@ -0,0 +1,175 @@
+# SPDX-License-Identifier: AGPL-3.0-only
+# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
+
+"""The browser matrix keeps TMPDIR short, whatever the checkout is called.
+
+Branded Chrome and Edge create `$TMPDIR/com.google.Chrome.XXXXXX/SingletonSocket` at launch
+and abort with "Socket path too long" when that passes the 107 usable bytes of a unix socket
+path. With TMPDIR under the checkout the length tracked the repository name:
+`/home/runner/work/unsloth/unsloth/...` came to 100 bytes, and a fork named
+`unsloth-staging-2` to 120, which failed every chrome and msedge leg before a page loaded.
+Chromium, firefox and webkit create no such socket, so the break showed up as two browsers
+out of five.
+"""
+
+from __future__ import annotations
+
+import os
+import re
+import shutil
+import sys
+import tempfile
+from pathlib import Path
+
+import pytest
+
+ROOT = Path(__file__).resolve().parents[2]
+WORKFLOW = ROOT / ".github" / "workflows" / "studio-composer-compatibility.yml"
+# sockaddr_un.sun_path less its terminating NUL, per hosted runner: 108 bytes on Linux, 104 on macOS.
+SUN_PATH_MAX = {"linux": 107, "macos": 103, "windows": 107}
+# What Chrome appends to TMPDIR, at its length.
+# What Chrome and Edge append to TMPDIR. Edge's is the longer one, so it is the one that must fit.
+CHROME_SOCKET = "/com.google.Chrome.XXXXXX/SingletonSocket"
+EDGE_SOCKET = "/com.microsoft.Edge.XXXXXX/SingletonSocket"
+
+
+def _workflow_tmpdirs() -> dict[str, str]:
+ text = WORKFLOW.read_text(encoding = "utf-8")
+ found = dict(re.findall(r'echo "(TMPDIR|TMP|TEMP)=([^"]+)" >> "\$GITHUB_ENV"', text))
+ assert set(found) == {
+ "TMPDIR",
+ "TMP",
+ "TEMP",
+ }, f"the workflow stopped exporting a temp dir: {found}"
+ return found
+
+
+def test_the_workflow_temp_dir_does_not_grow_with_the_checkout():
+ for name, value in _workflow_tmpdirs().items():
+ assert "GITHUB_WORKSPACE" not in value and "github.workspace" not in value, (
+ f"{name}={value} sits under the checkout, so Chrome's socket path grows with the "
+ "repository name"
+ )
+ assert value.startswith("$RUNNER_TEMP/"), f"{name}={value}"
+
+
+def test_the_workflow_socket_path_fits_on_the_hosted_runners():
+ # RUNNER_TEMP on the hosted images: Linux, macOS and Windows (Git Bash spelling).
+ for host, runner_temp in (
+ ("linux", "/home/runner/work/_temp"),
+ ("macos", "/Users/runner/work/_temp"),
+ ("windows", "D:/a/_temp"),
+ ):
+ for name, value in _workflow_tmpdirs().items():
+ path = value.replace("$RUNNER_TEMP", runner_temp) + EDGE_SOCKET
+ assert len(path) <= SUN_PATH_MAX[host], f"{name} on {host}: {path} is {len(path)} bytes"
+
+
+def _runner(monkeypatch):
+ monkeypatch.syspath_prepend(str(ROOT / "tests" / "studio"))
+ sys.modules.pop("run_composer_compatibility", None)
+ import run_composer_compatibility as runner
+
+ return runner
+
+
+def _fits(path: Path, limit: int) -> bool:
+ return len(os.fsencode(path)) + len(EDGE_SOCKET) <= limit
+
+
[email protected](os.name == "nt", reason = "Chrome's singleton is a named pipe on Windows")
+def test_the_local_runner_uses_a_short_inherited_temp_dir(monkeypatch):
+ runner = _runner(monkeypatch)
+ short = Path(tempfile.mkdtemp(prefix = "s", dir = "/tmp"))
+ try:
+ monkeypatch.setattr(runner.tempfile, "tempdir", str(short))
+ first = runner.browser_tmpdir()
+ second = runner.browser_tmpdir()
+ assert first.parent == short and second.parent == short, "a short TMPDIR was not honoured"
+ assert first != second, "two runs must not share a temp dir"
+ assert _fits(first, runner.sun_path_max())
+ finally:
+ shutil.rmtree(short, ignore_errors = True)
+
+
[email protected](os.name == "nt", reason = "Chrome's singleton is a named pipe on Windows")
+def test_the_local_runner_falls_back_when_the_inherited_temp_dir_is_too_long(tmp_path, monkeypatch):
+ runner = _runner(monkeypatch)
+ deep = tmp_path / ("d" * 80)
+ deep.mkdir()
+ monkeypatch.setattr(runner.tempfile, "tempdir", str(deep))
+ made = runner.browser_tmpdir()
+ try:
+ assert _fits(made, runner.sun_path_max()), f"{made} leaves Chrome's socket path too long"
+ assert made.parent == Path("/tmp")
+ assert not any(deep.iterdir()), "the rejected temp dir was left behind"
+ finally:
+ shutil.rmtree(made, ignore_errors = True)
+
+
[email protected](os.name == "nt", reason = "Chrome's singleton is a named pipe on Windows")
+def test_the_local_runner_never_uses_a_temp_dir_inside_the_checkout(monkeypatch):
+ runner = _runner(monkeypatch)
+ inside = Path(tempfile.mkdtemp(prefix = ".t", dir = ROOT))
+ try:
+ monkeypatch.setattr(runner.tempfile, "tempdir", str(inside))
+ made = runner.browser_tmpdir()
+ try:
+ assert ROOT not in made.resolve().parents, f"{made} is under the checkout"
+ finally:
+ shutil.rmtree(made, ignore_errors = True)
+ finally:
+ shutil.rmtree(inside, ignore_errors = True)
+
+
[email protected](os.name == "nt", reason = "Chrome's singleton is a named pipe on Windows")
+def test_the_local_runner_applies_the_macos_limit_on_macos(monkeypatch):
+ """A path of 104 to 107 bytes fits Linux's sun_path and not macOS's, so it must fall back there."""
+ runner = _runner(monkeypatch)
+ # mkdtemp adds "/uqv-" plus 8 characters: pick the parent so the socket path lands on 105.
+ parent_len = 105 - len(EDGE_SOCKET) - len("/uqv-") - 8
+ base = Path(tempfile.mkdtemp(prefix = "m", dir = "/tmp"))
+ try:
+ parent = Path(str(base) + "/" + "p" * (parent_len - len(str(base)) - 1))
+ parent.mkdir()
+ assert len(str(parent)) == parent_len
+ monkeypatch.setattr(runner.tempfile, "tempdir", str(parent))
+ monkeypatch.setattr(runner.sys, "platform", "linux")
+ on_linux = runner.browser_tmpdir()
+ assert on_linux.parent == parent, "105 bytes fits Linux and should have been kept"
+ monkeypatch.setattr(runner.sys, "platform", "darwin")
+ on_macos = runner.browser_tmpdir()
+ try:
+ assert on_macos.parent == Path(
+ "/tmp"
+ ), "105 bytes is over macOS's limit and must fall back"
+ assert _fits(on_macos, 103)
+ finally:
+ shutil.rmtree(on_macos, ignore_errors = True)
+ finally:
+ shutil.rmtree(base, ignore_errors = True)
+
+
[email protected](os.name == "nt", reason = "Chrome's singleton is a named pipe on Windows")
+def test_the_local_runner_sizes_the_path_for_edge_not_just_chrome(monkeypatch):
+ """A temp dir that puts Chrome's socket at exactly 107 bytes puts Edge's at 108, which Edge
+ rejects. The runner launches both, so it must fall back."""
+ runner = _runner(monkeypatch)
+ assert runner.LONGEST_SOCKET == EDGE_SOCKET
+ assert len(EDGE_SOCKET) == len(CHROME_SOCKET) + 1
+ parent_len = 107 - len(CHROME_SOCKET) - len("/uqv-") - 8
+ base = Path(tempfile.mkdtemp(prefix = "e", dir = "/tmp"))
+ try:
+ parent = Path(str(base) + "/" + "p" * (parent_len - len(str(base)) - 1))
+ parent.mkdir()
+ assert len(str(parent)) == parent_len
+ monkeypatch.setattr(runner.tempfile, "tempdir", str(parent))
+ monkeypatch.setattr(runner.sys, "platform", "linux")
+ made = runner.browser_tmpdir()
+ try:
+ assert made.parent == Path("/tmp"), "a path that only fits Chrome was kept for Edge"
+ assert _fits(made, 107)
+ finally:
+ shutil.rmtree(made, ignore_errors = True)
+ finally:
+ shutil.rmtree(base, ignore_errors = True)