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 the three Backend CI failures on main (#11111)

Daniel Han1e6908d666b0
diff --git a/studio/backend/core/inference/tool_confinement.py b/studio/backend/core/inference/tool_confinement.py
index db669e3738d..9945aad18b8 100644
--- a/studio/backend/core/inference/tool_confinement.py
+++ b/studio/backend/core/inference/tool_confinement.py
@@ -353,7 +353,15 @@ def _landlock_preexec(
raise OSError(ctypes.get_errno(), "landlock_create_ruleset failed")
try:
for path, access in rules:
- parent_fd = os.open(path, os.O_PATH | os.O_CLOEXEC)
+ try:
+ parent_fd = os.open(path, os.O_PATH | os.O_CLOEXEC)
+ except FileNotFoundError:
+ # The rules come from a directory walk, and a path can go between that walk and
+ # this open: a cache purge, a model delete, an account delete. Landlock denies by
+ # default, so dropping a grant only ever narrows the child, while raising here
+ # kills the whole tool call as "Exception occurred in preexec_fn", which names
+ # neither the path nor the reason.
+ continue
try:
beneath = _PathBeneathAttr(access & handled, parent_fd)
rc = libc.syscall(
diff --git a/studio/backend/tests/test_account_tool_confinement.py b/studio/backend/tests/test_account_tool_confinement.py
index 1ab1b31045e..342b1f4d515 100644
--- a/studio/backend/tests/test_account_tool_confinement.py
+++ b/studio/backend/tests/test_account_tool_confinement.py
@@ -418,6 +418,42 @@ def test_sandbox_home_under_a_granted_root_hides_other_accounts(tmp_path, monkey
shutil.rmtree(base, ignore_errors = True)
[email protected](not LANDLOCK, reason = "Landlock not available on this kernel")
+def test_a_rule_path_removed_before_the_child_opens_it_does_not_kill_the_call(tmp_path):
+ """A grant whose directory went between the walk and the child is dropped, not fatal.
+
+ `_landlock_rules` walks a granted ancestor child by child, and the child opens each path
+ afterwards. Anything that removes one in between -- a cache purge, a model delete, an
+ account delete, another test sharing the interpreter prefix -- used to raise out of
+ preexec_fn, so the tool call died as "Exception occurred in preexec_fn" and named neither
+ the path nor the reason. Landlock denies by default, so a dropped grant only narrows the
+ child.
+ """
+ gone = tmp_path / "granted-then-removed"
+ gone.mkdir()
+ rules = [
+ (str(tmp_path), tool_confinement._FS_READ_DIR),
+ (str(gone), tool_confinement._FS_READ_DIR),
+ ]
+ handled = tool_confinement._handled_mask(tool_confinement.landlock_abi())
+ gone.rmdir()
+
+ # Forked, because _landlock_preexec restricts the process it runs in and pytest is not a
+ # process to restrict.
+ pid = os.fork()
+ if pid == 0:
+ try:
+ tool_confinement._landlock_preexec(handled, rules)
+ except BaseException:
+ os._exit(1)
+ os._exit(0)
+ _, status = os.waitpid(pid, 0)
+ assert os.WIFEXITED(status) and os.WEXITSTATUS(status) == 0, (
+ "a rule path that disappeared before the child opened it took the whole launch down; "
+ "landlock denies by default, so the grant should be dropped instead"
+ )
+
+
@pytest.mark.skipif(not LANDLOCK, reason = "Landlock not available on this kernel")
def test_projects_home_under_a_granted_root_hides_other_accounts(tmp_path, monkeypatch):
from utils.paths.storage_roots import project_workspaces_root
diff --git a/studio/backend/tests/test_mcp_stdio_sessions.py b/studio/backend/tests/test_mcp_stdio_sessions.py
index 8a96a46206d..c984fc40544 100644
--- a/studio/backend/tests/test_mcp_stdio_sessions.py
+++ b/studio/backend/tests/test_mcp_stdio_sessions.py
@@ -663,10 +663,25 @@ def test_config_check_blocks_stale_publish(fake_clients):
def test_close_generation_keys_hold_no_secrets(fake_clients):
secret_url = "npx server --token sk-url-secret"
- close_mcp_sessions(secret_url, {"API_KEY": "sk-env-secret"})
+ secret_env = {"API_KEY": "sk-env-secret"}
+ # A close records a generation only when it closed something, so each half needs its own live
+ # session. Reading whatever the maps already held made the non-vacuity check depend on earlier
+ # tests in this file: these maps are module-level and never pruned, so under `--dist load`,
+ # which spreads one file across workers, this test could run on a worker that left them empty.
+ before = set(mcp_client._mcp_cfg_close_gen) | set(mcp_client._mcp_url_close_gen)
+
+ call_tool_sync(secret_url, secret_env, "t", {}, scope = "chat")
+ close_mcp_sessions(secret_url, secret_env)
+ call_tool_sync(secret_url, secret_env, "t", {}, scope = "chat")
close_mcp_sessions(secret_url)
+
gen_keys = list(mcp_client._mcp_cfg_close_gen) + list(mcp_client._mcp_url_close_gen)
- assert gen_keys
+ recorded = set(gen_keys) - before
+ assert recorded, (
+ "closing a live session recorded no close generation, so the secret check below would "
+ f"pass over an empty map: cfg={mcp_client._mcp_cfg_close_gen}, "
+ f"url={mcp_client._mcp_url_close_gen}"
+ )
# These maps are never pruned: neither command/URL nor env may persist.
assert all("sk-url-secret" not in repr(k) and "sk-env-secret" not in repr(k) for k in gen_keys)
diff --git a/studio/backend/tests/test_scoped_download_job.py b/studio/backend/tests/test_scoped_download_job.py
index 06db072d2da..4b3ba2d3359 100644
--- a/studio/backend/tests/test_scoped_download_job.py
+++ b/studio/backend/tests/test_scoped_download_job.py
@@ -42,6 +42,29 @@ from hub.utils.paths import is_valid_gguf_variant
FILES = ["model_index.json", "vae/diffusion_pytorch_model.safetensors"]
+REPO = "black-forest-labs/FLUX.1-dev"
+
+
[email protected](autouse = True)
+def _repo_with_no_running_job():
+ """No job of this repo is left running around a test in this file.
+
+ The download registry is a process global and nothing resets it between tests, while a
+ running scoped job deliberately blocks a full snapshot of the same repo. Any test that
+ leaves one running therefore fails a later one here with "no full-snapshot row", and under
+ `--dist load`, which spreads a file across workers, which tests share a process changes
+ from run to run. Retiring the repo's jobs on both sides keeps that out of the assertions.
+ """
+
+ def _retire():
+ for ref in download_lifecycle.active_download_refs(dl._registry, REPO, with_variant = True):
+ dl._registry.set_job(dl._download_job_key(REPO, ref.variant), "complete")
+
+ _retire()
+ yield
+ _retire()
+
+
def _request(**over) -> DownloadModelRequest:
body = {
"repo_id": "black-forest-labs/FLUX.1-dev",
diff --git a/tests/studio/playwright_image_download_cancel_retry.py b/tests/studio/playwright_image_download_cancel_retry.py
index 2a68981bd0f..47cb20b4ea2 100644
--- a/tests/studio/playwright_image_download_cancel_retry.py
+++ b/tests/studio/playwright_image_download_cancel_retry.py
@@ -22,9 +22,11 @@ from pathlib import Path
from urllib.parse import parse_qs, urlparse
from playwright.sync_api import Route, expect, sync_playwright
+from playwright.sync_api import TimeoutError as PWTimeoutError
from playwright_image_model_footprint import (
BASE_URL,
+ KLEIN_ROW,
CHECKPOINT_BYTES,
COMPANION_BYTES,
FILENAME,
@@ -107,7 +109,37 @@ def _open_quant(page, *, navigate: bool) -> None:
requestAnimationFrame(frame);
});
}""")
- trigger.click()
+ menu = page.locator(".unsloth-model-selector-menu")
+
+ # The picker dismisses on scroll, and in the download-only pass it is opened with the Advanced
+ # panel expanded and two fields just filled, so a late re-render can close it in the frame
+ # after it opened. Waiting on the row alone then burns the whole timeout against a menu that
+ # is no longer there and reports only "Locator.click: Timeout 30000ms exceeded". Reopen while
+ # that is what happened, and say which of the two it was if neither settles.
+ def _open() -> bool:
+ return bool(menu.count()) and menu.first.is_visible()
+
+ last = ""
+ for attempt in range(5):
+ # Clicking the trigger toggles, so an already-open picker must not be clicked shut.
+ if not _open():
+ trigger.click()
+ try:
+ menu.wait_for(state = "visible", timeout = 5_000)
+ klein_row(page).wait_for(state = "visible", timeout = 15_000)
+ break
+ except PWTimeoutError as error:
+ last = str(error).splitlines()[0]
+ if _open():
+ # Open, but without the row: reopening cannot help, so stop and report it.
+ raise AssertionError(
+ f"the picker is open and {KLEIN_ROW.pattern} is not in it after {attempt + 1} "
+ f"attempts: {last}"
+ ) from None
+ else:
+ raise AssertionError(
+ f"the picker did not stay open for {KLEIN_ROW.pattern} across 5 attempts: {last}"
+ )
klein_row(page).click()
gguf = page.get_by_text("GGUF", exact = True)
if gguf.count() == 1: