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.

Skip llama-server discovery when there is no launch revision, and scope the VRAM finalizer assertion (#9325)

oobaboogae1746a0f0d6e
diff --git a/studio/backend/core/inference/llama_cpp.py b/studio/backend/core/inference/llama_cpp.py
index 692219068c5..a83fcbc3218 100644
--- a/studio/backend/core/inference/llama_cpp.py
+++ b/studio/backend/core/inference/llama_cpp.py
@@ -4979,10 +4979,13 @@ class LlamaCppBackend:
def _binary_changed_since_revision(self, revision: tuple) -> bool:
"""Whether the current selection differs from a captured binary."""
+ # No captured revision is no baseline, and discovery cannot recover one.
+ if not revision:
+ return False
current = self._binary_revision(
self._exec_path_for_launch(self._find_llama_server_binary())
)
- if not current or not revision:
+ if not current:
return False
return current != revision
diff --git a/studio/backend/tests/test_llama_cpp_darwin_loader_env.py b/studio/backend/tests/test_llama_cpp_darwin_loader_env.py
index 735ca97f453..49058133823 100644
--- a/studio/backend/tests/test_llama_cpp_darwin_loader_env.py
+++ b/studio/backend/tests/test_llama_cpp_darwin_loader_env.py
@@ -344,6 +344,17 @@ class TestBinaryRevisionPathSpace:
monkeypatch.setattr(sys, "platform", "darwin")
return wrapper
+ def test_a_missing_baseline_does_not_rediscover_the_binary(self, monkeypatch):
+ backend = LlamaCppBackend.__new__(LlamaCppBackend)
+ backend._launch_binary_revision = ()
+
+ # *args/**kwargs, or a caller passing include_denied fails on the signature.
+ def _unexpected_discovery(*args, **kwargs): # pragma: no cover - must never run
+ raise AssertionError("binary discovery ran without a revision to compare")
+
+ monkeypatch.setattr(backend, "_find_llama_server_binary", _unexpected_discovery)
+ assert backend._binary_changed_since_launch() is False
+
def test_an_unchanged_managed_install_does_not_look_updated(self, monkeypatch, tmp_path):
wrapper = self._managed_wrapper(monkeypatch, tmp_path)
monkeypatch.setattr(
diff --git a/studio/backend/tests/test_vram_budget_settings.py b/studio/backend/tests/test_vram_budget_settings.py
index e8ddaca31b8..37f16cb13b0 100644
--- a/studio/backend/tests/test_vram_budget_settings.py
+++ b/studio/backend/tests/test_vram_budget_settings.py
@@ -459,24 +459,37 @@ class TestPendingOwnership:
# back and the route reads it before is_active. The release belongs to the
# lock, not the call: overlapping /load calls hand the lock over before the
# first returns, so clearing on the way out would discard the queued marker.
+ import ast
import inspect
+ import textwrap
import core.inference.llama_cpp as lc
- code = [
- line
- for line in inspect.getsource(lc.LlamaCppBackend._serial_load_scope).splitlines()
- if not line.strip().startswith("#")
- ]
- compact = "".join("".join(code).split())
- assert "withself._serial_load_lock:try:yieldfinally:" in compact
- # In the finally, not necessarily last in it. The scope releases more than
- # one pending marker now -- #9292 added _binary_revision_pending -- and
- # pinning this to the END of the source made adding a sibling clear read as
- # "the pending value is no longer released with the load lock", which is a
- # different and much more alarming claim than the one that was true.
- released = compact.split("finally:", 1)[1]
- assert "self._vram_fraction_pending=None" in released
+ # The finalizer as a scope, not as text after "finally:": a substring also passes
+ # on a clear moved below the `with`, which an exception through the yield skips.
+ # Position in the finalbody is free, as are siblings (#9292's _binary_revision_pending).
+ scope = ast.parse(
+ textwrap.dedent(inspect.getsource(lc.LlamaCppBackend._serial_load_scope))
+ ).body[0]
+ # Defaulted, so a rewritten scope fails on what it lost, not on a StopIteration.
+ held = next((n for n in scope.body if isinstance(n, (ast.With, ast.AsyncWith))), None)
+ assert held is not None, "the scope no longer takes the load lock in a with"
+ assert ast.unparse(held.items[0].context_expr) == "self._serial_load_lock"
+ guarded = next((n for n in held.body if isinstance(n, ast.Try)), None)
+ assert guarded is not None, "the yield is no longer wrapped in try/finally"
+ assert any(
+ isinstance(node, ast.Expr) and isinstance(node.value, ast.Yield)
+ for node in guarded.body
+ )
+ cleared = {
+ ast.unparse(target)
+ for node in guarded.finalbody
+ if isinstance(node, ast.Assign)
+ and isinstance(node.value, ast.Constant)
+ and node.value.value is None
+ for target in node.targets
+ }
+ assert "self._vram_fraction_pending" in cleared
# And the load has to go through it, or the scope guards nothing.
load = "".join(inspect.getsource(lc.LlamaCppBackend.load_model).split())
assert "withself._serial_load_scope():" in load
diff --git a/studio/frontend/src/features/settings/settings-dialog.tsx b/studio/frontend/src/features/settings/settings-dialog.tsx
index a3aa61d874c..bf2da8901c5 100644
--- a/studio/frontend/src/features/settings/settings-dialog.tsx
+++ b/studio/frontend/src/features/settings/settings-dialog.tsx
@@ -55,7 +55,7 @@ import {
type SettingsTab,
useSettingsDialogStore,
} from "./stores/settings-dialog-store";
-// Statically imported, all twelve panels ran before first paint even though the dialog
+// Statically imported, every panel ran before first paint even though the dialog
// starts closed. Load each on first view instead; this map also drives the prefetch.
const TAB_LOADERS = {
general: () => import("./tabs/general-tab").then((m) => ({ default: m.GeneralTab })),
diff --git a/studio/frontend/tests/settings-tab-panel-loading.test.ts b/studio/frontend/tests/settings-tab-panel-loading.test.ts
index e6151391a9d..3889e5318c3 100644
--- a/studio/frontend/tests/settings-tab-panel-loading.test.ts
+++ b/studio/frontend/tests/settings-tab-panel-loading.test.ts
@@ -2,7 +2,7 @@
// Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
/**
- * The dialog is closed for the whole launch, yet its twelve tab panels were static imports
+ * The dialog is closed for the whole launch, yet its tab panels were static imports
* and so ran before first paint. One static `./tabs/...` edge from anywhere reachable at
* startup puts them all back, so these assert the import graph, not rendered output.
*/