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: point unsloth start at the right model when several are loaded (#13480)
Nilayb87ab5ec4658
diff --git a/unsloth_cli/commands/start.py b/unsloth_cli/commands/start.pyindex cd0b03bf42f..b80bda0458b 100644--- a/unsloth_cli/commands/start.py+++ b/unsloth_cli/commands/start.py@@ -904,6 +904,16 @@ def _display_model_spec(model: str, variant: Optional[str]) -> str:return f"{repo}:{selected_variant}" if selected_variant else model+def _model_status(+ base: str,+ key: str,+ model_id: Optional[str] = None,+) -> dict:+ # Studio serving several models answers for the one serving model_id; an older one ignores it.+ query = f"?{urlencode({'model': model_id})}" if model_id else ""+ return _http_json("GET", f"{base}/api/inference/status{query}", key)++def _subagent_model_id(base: str,key: str,@@ -917,7 +927,7 @@ def _subagent_model_id(variant = requested_variant or inline_variantif not variant:try:- status = _http_json("GET", f"{base}/api/inference/status", key)+ status = _model_status(base, key, model_id)except Exception:status = {}typer.echo(@@ -2025,10 +2035,14 @@ def _model_id_matches(return str(actual).casefold() == str(requested).casefold()-def _inference_status(base: str, key: str) -> dict:+def _inference_status(+ base: str,+ key: str,+ model_id: Optional[str] = None,+) -> dict:"""Runtime state of the resident model. {} means "cannot prove anything" (older server), never "nothing is set"."""try:- return _http_json("GET", f"{base}/api/inference/status", key)+ return _model_status(base, key, model_id)except Exception:return {}@@ -2223,23 +2237,21 @@ def _resolve_model(requested, attach_public_id = _resident_load_target(models, status_snapshot, allow_casefold)inferred_differs = _load_settings_differ(status_snapshot, load, overrides)# preload_check deliberately survives: it is the only gate before the load evicts the shared model (_require_gguf_for_codex runs after _connect returns). An older server answers this listing from the full catalog, which also carries cached-but-unloaded entries (loaded == False); matching one would skip /api/inference/load and leave the agent pointed at a model that is not resident, so only attach to an entry that is actually loaded.- match = (- None- if requested and load_has_overrides- else next(- (- m- for m in models- if _model_id_matches(m.get("id"), requested, allow_casefold = allow_casefold)- and m.get("loaded") is not False- ),- None,- )+ loaded_match = next(+ (+ m+ for m in models+ if _model_id_matches(m.get("id"), requested, allow_casefold = allow_casefold)+ and m.get("loaded") is not False+ ),+ None,)+ match = None if requested and load_has_overrides else loaded_matchif requested and match is None:load_requested = True# Only here is an evicting load certain: the gate must not reject a request the resident model already satisfies (a path-loaded GGUF shown as a bare basename can collide with a non-GGUF unsloth/<name>).- active = next((m for m in models if m.get("loaded") is not False), None)+ # A load of a model already served replaces it in its own slot, which may not be the primary.+ active = loaded_match or next((m for m in models if m.get("loaded") is not False), None)# On the inferred path the target came from status, so catalog order can name a different entry (a speech sidecar listed first). Using it would make the survivor probe below report the wrong model as still serving.if attach_public_id is not None:active = next(@@ -2272,7 +2284,7 @@ def _resolve_model(# The loaded listing shows only the basename, so confirm a path request against the identifier the server loaded, else /new/foo.gguf reads as resident because /old/foo.gguf is.if resident_serves_request and _is_model_path(requested):try:- status = _http_json("GET", f"{base}/api/inference/status", key)+ status = _model_status(base, key, requested)except Exception:status = {}loaded_paths = {@@ -2287,7 +2299,7 @@ def _resolve_model()if resident_serves_request and load.gguf_variant:try:- status = _http_json("GET", f"{base}/api/inference/status", key)+ status = _model_status(base, key, requested)except Exception:status = {}resident_variant = status.get("gguf_variant") if status.get("is_gguf") else None@@ -2327,7 +2339,7 @@ def _resolve_model(elif active_id and load.gguf_variant:# Same repo id but an explicit quant still replaces the resident weights; the loaded listing does not carry a variant for every resident model, so ask the status endpoint.try:- status = _http_json("GET", f"{base}/api/inference/status", key)+ status = _model_status(base, key, active_id)except Exception:status = {}resident = status.get("gguf_variant") if status.get("is_gguf") else None@@ -2338,6 +2350,19 @@ def _resolve_model()typer.echo("This unloads the current model for every attached session.")announced_switch = True+ elif loaded_match is not None and _load_settings_differ(status, load, overrides):+ typer.echo(f"Applying new load settings to {active_id}.")+ typer.echo("This unloads the current model for every attached session.")+ announced_switch = True+ elif active_id and loaded_match is not None:+ try:+ status = _model_status(base, key, active_id)+ except Exception:+ status = {}+ if _load_settings_differ(status, load, overrides):+ typer.echo(f"Applying new load settings to {active_id}.")+ typer.echo("This unloads the current model for every attached session.")+ announced_switch = Trueelif not active_id and _inference_status(base, key).get("yours") is False:typer.echo("Switching the Unsloth server from another account's model to "@@ -2371,6 +2396,14 @@ def _resolve_model(resident_variant = status_snapshot.get("gguf_variant")if resident_variant and not str(requested).lower().endswith(".gguf"):payload["gguf_variant"] = resident_variant+ elif loaded_match is not None and not str(requested).lower().endswith(".gguf"):+ # Same for a named model already served, read from the slot serving it.+ try:+ status = _model_status(base, key, loaded_match["id"])+ except Exception:+ status = {}+ if status.get("is_gguf") and status.get("gguf_variant"):+ payload["gguf_variant"] = status["gguf_variant"]if "max_seq_length" in overrides:payload["max_seq_length"] = load.max_seq_lengthif "load_in_4bit" in overrides:@@ -3008,7 +3041,7 @@ def _attach_gguf_check(def _require_gguf_for_agent(agent: _GgufAgent, base: str, key: str, model_id: str) -> None:# Only a definite "no" rejects: the callers wrap this in `except BaseException: _shutdown_auto_served()`, so guessing kills a server that may have just loaded a GGUF.try:- status = _http_json("GET", f"{base}/api/inference/status", key)+ status = _model_status(base, key, model_id)except urllib.error.HTTPError:# Not evidence: get_status 500s from its own probes with a GGUF resident.return@@ -4612,7 +4645,7 @@ def _connect(# That server was started FROM these knobs, so inferring a target here would reload what was just loaded.infer_resident = server is None,)- status = _inference_status(base, key) if model else {}+ status = _inference_status(base, key, entry["id"]) if model else {}# A GGUF can be active while the resolved entry is another resident model.if status.get("memory_warning") and any(_model_id_matches(@@ -7469,7 +7502,7 @@ def vibe(if "temperature" not in request_body:# Vibe always sends a temperature, which the server honours over the model's# recommended one, so pass the recommendation along explicitly.- status = _inference_status(base, key)+ status = _inference_status(base, key, entry["id"])recommended = (status.get("inference") or {}).get("temperature")if recommended is not None and any(_model_id_matches(entry["id"], status_id, allow_casefold = is_loopback_url(base))diff --git a/unsloth_cli/tests/test_start.py b/unsloth_cli/tests/test_start.pyindex e0591ff00ce..033cffcfcb8 100644--- a/unsloth_cli/tests/test_start.py+++ b/unsloth_cli/tests/test_start.py@@ -1345,6 +1345,22 @@ def test_subagent_model_id_uses_loaded_variant(monkeypatch):assert start._subagent_model_id(BASE, "key", MODEL, None, None) == MODEL["id"] + ":Q5_K_M"+def _kept_model_status(url):+ # Primary Qwen3-4B at Q4_K_M, Qwen3-1.7B kept alongside at Q8_0.+ if "model=unsloth%2FQwen3-1.7B-GGUF" in url:+ return {"is_gguf": True, "active_model": "unsloth/Qwen3-1.7B-GGUF", "gguf_variant": "Q8_0"}+ return {"is_gguf": True, "active_model": "unsloth/Qwen3-4B-GGUF", "gguf_variant": "Q4_K_M"}+++def test_subagent_model_id_pins_the_kept_model_quant(monkeypatch):+ monkeypatch.setattr(start, "_http_json", lambda method, url, key, **_: _kept_model_status(url))++ entry = {"id": "unsloth/Qwen3-1.7B-GGUF"}+ assert start._subagent_model_id(BASE, "key", entry, entry["id"], None) == (+ "unsloth/Qwen3-1.7B-GGUF:Q8_0"+ )++def test_subagent_model_id_warns_when_status_unavailable(monkeypatch, capsys):def raise_error(*args, **kwargs):raise OSError("connection refused")@@ -1576,7 +1592,7 @@ def fake_studio(tmp_path, monkeypatch):calls.append((method, url, payload))if url.endswith("/api/inference/loaded-models"):return {"object": "list", "data": state["models"]}- if url.endswith("/api/inference/status"):+ if url.split("?")[0].endswith("/api/inference/status"):return {"is_gguf": True, "model_identifier": state["models"][0]["id"]}if url.endswith("/api/auth/api-keys"):if method == "GET":@@ -1666,7 +1682,7 @@ def test_connect_prints_the_running_models_load_warning(fake_studio, monkeypatchtimeout = 30,error = None,):- if url.endswith("/api/inference/status"):+ if url.split("?")[0].endswith("/api/inference/status"):return {"is_gguf": True, "model_identifier": MODEL["id"], "memory_warning": notice}return http_json(method, url, token, payload, timeout, error)@@ -1689,7 +1705,7 @@ def test_connect_skips_the_load_warning_of_another_active_model(fake_studio, montimeout = 30,error = None,):- if url.endswith("/api/inference/status"):+ if url.split("?")[0].endswith("/api/inference/status"):return {"is_gguf": True,"active_model": "unsloth/Other-GGUF",@@ -1705,6 +1721,24 @@ def test_connect_skips_the_load_warning_of_another_active_model(fake_studio, monassert "Warning: Not enough disk space" not in result.output+def test_connect_prints_the_load_warning_of_a_kept_model(fake_studio, monkeypatch):+ notice = "Not enough disk space to download BF16, so Q4_1 was loaded instead."+ http_json = start._http_json++ def kept_model_warns(method, url, token, *args, **kwargs):+ if url.split("?")[0].endswith("/api/inference/status"):+ if "model=" in url:+ return {"is_gguf": True, "active_model": MODEL["id"], "memory_warning": notice}+ return {"is_gguf": True, "active_model": "unsloth/Other-GGUF"}+ return http_json(method, url, token, *args, **kwargs)++ monkeypatch.setattr(start, "_http_json", kept_model_warns)+ result = CliRunner().invoke(start.start_app, ["claude", "--no-launch", "--model", MODEL["id"]])++ assert result.exit_code == 0, result.output+ assert f"Warning: {notice}" in result.stderr++def test_connect_claude_session_settings_follow_forwarded_settings(fake_studio):forwarded = json.dumps({"env": {"CLAUDE_CODE_USE_FOUNDRY": "1"}})result = CliRunner().invoke(@@ -1818,6 +1852,42 @@ def test_connect_claude_as_subagent_preserves_cloud_parent(fake_studio, tmp_pathassert "Ask Claude to spawn an Unsloth or local agent." in result.output[email protected]("suffix", ["", ":Q8_0"])+def test_connect_claude_as_subagent_attaches_to_a_kept_model(+ fake_studio, tmp_path, monkeypatch, suffix+):+ fake = start._http_json+ models = [+ {"id": "unsloth/Qwen3-4B-GGUF", "context_length": 32768},+ {"id": "unsloth/Qwen3-1.7B-GGUF", "context_length": 32768},+ ]++ def http_json(method, url, token, *args, **kwargs):+ if url.endswith("/api/inference/loaded-models"):+ return {"object": "list", "data": models}+ if "/api/inference/status" in url:+ return _kept_model_status(url)+ return fake(method, url, token, *args, **kwargs)++ monkeypatch.setattr(start, "_http_json", http_json)+ result = CliRunner().invoke(+ start.start_app,+ ["claude", "--as-subagent", "--no-launch", "--model", "unsloth/Qwen3-1.7B-GGUF" + suffix],+ )++ assert result.exit_code == 0, result.output+ assert "Switching" not in result.output+ assert "unloads" not in result.output+ loads = [payload for _, url, payload in fake_studio if url.endswith("/api/inference/load")]+ assert loads == (+ [{"model_path": "unsloth/Qwen3-1.7B-GGUF", "gguf_variant": "Q8_0"}] if suffix else []+ )+ assert "model unsloth/Qwen3-1.7B-GGUF:Q8_0" in result.output+ plugin = tmp_path / "agents" / "claude-subagent" / "unsloth-local-agent"+ mcp = json.loads((plugin / ".mcp.json").read_text())["mcpServers"]["unsloth"]+ assert mcp["env"]["UNSLOTH_CLAUDE_SUBAGENT_MODEL"] == "unsloth/Qwen3-1.7B-GGUF:Q8_0"++def test_claude_auto_route_tells_the_parent_to_delegate_routine_work(fake_studio, tmp_path):result = CliRunner().invoke(start.start_app,@@ -3327,7 +3397,7 @@ def _fake_path_resident(if state["after"] == "unreachable":raise TimeoutError("timed out")return {"data": [{"id": state["listed"], "loaded": state["after"] != "gone"}]}- if url.endswith("/api/inference/status"):+ if url.split("?")[0].endswith("/api/inference/status"):return {"is_gguf": True, "active_model": listed_id, "model_identifier": "ref:0123"}if url.endswith("/api/inference/load"):if load_error is not None:@@ -4406,7 +4476,7 @@ def test_connect_gguf_only_agents_reject_non_gguf_model(fake_studio, monkeypatchtimeout = 30,error = None,):- if url.endswith("/api/inference/status"):+ if url.split("?")[0].endswith("/api/inference/status"):return {"is_gguf": False, "model_identifier": "unsloth/Qwen3-0.6B"}return inner(method, url, token, payload, timeout, error)@@ -5152,7 +5222,7 @@ def test_resolve_model_warns_on_same_repo_quant_switch(monkeypatch, capsys):timeout = 30,error = None,):- assert url.endswith("/api/inference/status"), url+ assert url.split("?")[0].endswith("/api/inference/status"), urlreturn {"is_gguf": True, "gguf_variant": "Q4_K_M"}monkeypatch.setattr(start, "_loaded_models", lambda base, key: models)@@ -5197,6 +5267,204 @@ def test_resolve_model_same_quant_prints_no_switch_warning(monkeypatch, capsys):assert "Reusing loaded model: owner/model-GGUF:Q8_0" in out+def test_resolve_model_kept_model_at_its_quant_lets_the_server_dedupe(monkeypatch, capsys):+ models = [+ {"id": "unsloth/Qwen3-4B-GGUF", "loaded": True},+ {"id": "unsloth/Qwen3-1.7B-GGUF", "loaded": True},+ ]+ payloads = []++ def load(base, key, model, load, payload):+ payloads.append(payload)+ return {"status": "already_loaded", "model": model}++ monkeypatch.setattr(start, "_loaded_models", lambda base, key: models)+ monkeypatch.setattr(start, "_http_json", lambda method, url, key, **_: _kept_model_status(url))+ monkeypatch.setattr(start, "_load_model_with_progress", load)++ start._resolve_model(+ BASE, "key", "unsloth/Qwen3-1.7B-GGUF", start.LoadOptions(gguf_variant = "Q8_0")+ )++ # The server alone knows whether a retry or a changed server setting needs a relaunch.+ assert payloads == [{"model_path": "unsloth/Qwen3-1.7B-GGUF", "gguf_variant": "Q8_0"}]+ out = capsys.readouterr().out+ assert "Switching" not in out+ assert "unloads" not in out+ assert "Reusing loaded model: unsloth/Qwen3-1.7B-GGUF:Q8_0" in out+++def test_resolve_model_loads_a_kept_model_at_another_quant(monkeypatch, capsys):+ models = [+ {"id": "unsloth/Qwen3-4B-GGUF", "loaded": True},+ {"id": "unsloth/Qwen3-1.7B-GGUF", "loaded": True},+ ]+ payloads, gated = [], []++ def load(base, key, model, load, payload):+ payloads.append(payload)+ return {"status": "loaded", "model": model}++ monkeypatch.setattr(start, "_loaded_models", lambda base, key: models)+ monkeypatch.setattr(start, "_http_json", lambda method, url, key, **_: _kept_model_status(url))+ monkeypatch.setattr(start, "_load_model_with_progress", load)++ start._resolve_model(+ BASE,+ "key",+ "unsloth/Qwen3-1.7B-GGUF",+ start.LoadOptions(gguf_variant = "Q4_K_M"),+ preload_check = lambda *args: gated.append(args),+ )++ assert payloads == [{"model_path": "unsloth/Qwen3-1.7B-GGUF", "gguf_variant": "Q4_K_M"}]+ assert gated, "the kept model is at Q8_0, so the Q4_K_M load must pass the preload gate"+ out = capsys.readouterr().out+ assert (+ "Switching the Unsloth server from unsloth/Qwen3-1.7B-GGUF:Q8_0 to "+ "unsloth/Qwen3-1.7B-GGUF:Q4_K_M." in out+ )+ assert "Qwen3-4B" not in out+++def test_resolve_model_reloading_a_kept_model_does_not_announce_the_primary(monkeypatch, capsys):+ models = [+ {"id": "unsloth/Qwen3-4B-GGUF", "loaded": True},+ {"id": "unsloth/Qwen3-1.7B-GGUF", "loaded": True},+ ]+ payloads = []++ def load(base, key, model, load, payload):+ payloads.append(payload)+ return {"status": "loaded", "model": model}++ monkeypatch.setattr(start, "_loaded_models", lambda base, key: models)+ monkeypatch.setattr(start, "_http_json", lambda method, url, key, **_: _kept_model_status(url))+ monkeypatch.setattr(start, "_load_model_with_progress", load)++ start._resolve_model(+ BASE, "key", "unsloth/Qwen3-1.7B-GGUF", start.LoadOptions(max_seq_length = 16384)+ )++ out = capsys.readouterr().out+ assert "Switching" not in out+ assert "Qwen3-4B" not in out+ assert "Applying new load settings to unsloth/Qwen3-1.7B-GGUF." in out+ assert payloads == [+ {"model_path": "unsloth/Qwen3-1.7B-GGUF", "gguf_variant": "Q8_0", "max_seq_length": 16384}+ ]+++def test_resolve_model_kept_model_quant_and_context_warns_of_the_reload(monkeypatch, capsys):+ models = [+ {"id": "unsloth/Qwen3-4B-GGUF", "loaded": True},+ {"id": "unsloth/Qwen3-1.7B-GGUF", "loaded": True},+ ]+ payloads = []++ def load(base, key, model, load, payload):+ payloads.append(payload)+ return {"status": "loaded", "model": model}++ monkeypatch.setattr(start, "_loaded_models", lambda base, key: models)+ monkeypatch.setattr(start, "_http_json", lambda method, url, key, **_: _kept_model_status(url))+ monkeypatch.setattr(start, "_load_model_with_progress", load)++ start._resolve_model(+ BASE,+ "key",+ "unsloth/Qwen3-1.7B-GGUF",+ start.LoadOptions(gguf_variant = "Q8_0", max_seq_length = 16384),+ )++ out = capsys.readouterr().out+ assert "Switching" not in out+ assert "Applying new load settings to unsloth/Qwen3-1.7B-GGUF." in out+ assert payloads == [+ {"model_path": "unsloth/Qwen3-1.7B-GGUF", "gguf_variant": "Q8_0", "max_seq_length": 16384}+ ]+++ "pending",+ [+ {"spec_probe_retry_pending": True},+ {"audio_probe_pending": True},+ {"spec_fallback_reason": "drafter_not_found"},+ ],+)+def test_resolve_model_kept_model_with_a_pending_retry_still_loads(monkeypatch, pending):+ models = [+ {"id": "unsloth/Qwen3-4B-GGUF", "loaded": True},+ {"id": "unsloth/Qwen3-1.7B-GGUF", "loaded": True},+ ]+ payloads = []++ def status(url):+ return {**_kept_model_status(url), **pending}++ def load(base, key, model, load, payload):+ payloads.append(payload)+ return {"status": "loaded", "model": model}++ monkeypatch.setattr(start, "_loaded_models", lambda base, key: models)+ monkeypatch.setattr(start, "_http_json", lambda method, url, key, **_: status(url))+ monkeypatch.setattr(start, "_load_model_with_progress", load)++ start._resolve_model(+ BASE, "key", "unsloth/Qwen3-1.7B-GGUF", start.LoadOptions(gguf_variant = "Q8_0")+ )++ assert payloads == [{"model_path": "unsloth/Qwen3-1.7B-GGUF", "gguf_variant": "Q8_0"}]+++def test_resolve_model_kept_model_at_the_same_settings_does_not_warn(monkeypatch, capsys):+ models = [+ {"id": "unsloth/Qwen3-4B-GGUF", "loaded": True},+ {"id": "unsloth/Qwen3-1.7B-GGUF", "loaded": True},+ ]++ def status(url):+ return {**_kept_model_status(url), "requested_context_length": 16384}++ monkeypatch.setattr(start, "_loaded_models", lambda base, key: models)+ monkeypatch.setattr(start, "_http_json", lambda method, url, key, **_: status(url))+ monkeypatch.setattr(+ start,+ "_load_model_with_progress",+ lambda *a, **k: {"status": "already_loaded", "model": "unsloth/Qwen3-1.7B-GGUF"},+ )++ start._resolve_model(+ BASE, "key", "unsloth/Qwen3-1.7B-GGUF", start.LoadOptions(max_seq_length = 16384)+ )++ out = capsys.readouterr().out+ assert "unloads" not in out+ assert "Reusing loaded model: unsloth/Qwen3-1.7B-GGUF" in out+++def test_resolve_model_reload_option_keeps_the_running_quant(monkeypatch):+ models = [{"id": "owner/model-GGUF", "loaded": True}]+ payloads = []++ def load(base, key, model, load, payload):+ payloads.append(payload)+ return {"status": "loaded", "model": model}++ monkeypatch.setattr(start, "_loaded_models", lambda base, key: models)+ monkeypatch.setattr(+ start, "_http_json", lambda *a, **k: {"is_gguf": True, "gguf_variant": "Q8_0"}+ )+ monkeypatch.setattr(start, "_load_model_with_progress", load)++ start._resolve_model(BASE, "key", "owner/model-GGUF", start.LoadOptions(max_seq_length = 8192))++ assert payloads == [+ {"model_path": "owner/model-GGUF", "gguf_variant": "Q8_0", "max_seq_length": 8192}+ ]++def test_resolve_model_refused_load_reports_survivor(monkeypatch, capsys):models = [{"id": "owner/model-GGUF", "loaded": True}]@@ -5208,7 +5476,7 @@ def test_resolve_model_refused_load_reports_survivor(monkeypatch, capsys):timeout = 30,error = None,):- if url.endswith("/api/inference/status"):+ if url.split("?")[0].endswith("/api/inference/status"):return {"is_gguf": True, "gguf_variant": "Q4_K_M"}assert url.endswith("/api/inference/loaded-models"), urlreturn {"data": models}@@ -5248,7 +5516,7 @@ def _other_account_studio():if url.endswith("/api/inference/loaded-models"):return {"object": "list", "data": state["models"]}- assert url.endswith("/api/inference/status"), url+ assert url.split("?")[0].endswith("/api/inference/status"), urlif state["models"]:return {"is_gguf": True, "active_model": "owner/model-GGUF", "gguf_variant": "Q4_K_M"}return {"loaded": [], "loading": [], "yours": False}@@ -5347,7 +5615,7 @@ def test_resolve_model_failed_load_stays_quiet_when_model_gone(monkeypatch, capstimeout = 30,error = None,):- if url.endswith("/api/inference/status"):+ if url.split("?")[0].endswith("/api/inference/status"):return {"is_gguf": True, "gguf_variant": "Q4_K_M"}assert url.endswith("/api/inference/loaded-models"), urlreturn {"data": []}@@ -5582,7 +5850,7 @@ def test_codex_preflight_failure_tears_down_auto_served(fake_studio, monkeypatchtimeout = 30,error = None,):- if url.endswith("/api/inference/status"):+ if url.split("?")[0].endswith("/api/inference/status"):return {"is_gguf": False, "model_identifier": "transformers-model"}return inner(method, url, token, payload, timeout, error)@@ -5888,7 +6156,7 @@ def test_connect_openclaw_no_launch(fake_studio, tmp_path, monkeypatch):_assert_env_cwd(result.output, "OPENCLAW_WORKSPACE_DIR")assert _launch_command(result.output) == ["openclaw", "tui", "--local"]# OpenAI /v1/chat/completions works on either backend — no GGUF gate.- assert not any(c[1].endswith("/api/inference/status") for c in fake_studio)+ assert not any(c[1].split("?")[0].endswith("/api/inference/status") for c in fake_studio)@pytest.mark.skipif(os.name == "nt", reason = "WSL scenario")@@ -6355,7 +6623,7 @@ def test_connect_opencode_no_launch(fake_studio, tmp_path):# --no-launch prints an append-safe base command (no --model before a subcommand a# driver may append); the model is forced by the inline pin above.assert _launch_command(result.output) == ["opencode"]- assert not any(c[1].endswith("/api/inference/status") for c in fake_studio)+ assert not any(c[1].split("?")[0].endswith("/api/inference/status") for c in fake_studio)def test_connect_opencode_v2_no_launch_uses_private_server(fake_studio, monkeypatch):@@ -6655,7 +6923,7 @@ def test_connect_hermes_no_launch(fake_studio, tmp_path):assert config["model"]["provider"] == "custom:unsloth"assert config["providers"]["unsloth"]["base_url"] == f"{BASE}/v1"assert config["model"]["default"] == MODEL["id"]- assert not any(c[1].endswith("/api/inference/status") for c in fake_studio)+ assert not any(c[1].split("?")[0].endswith("/api/inference/status") for c in fake_studio)# ── Pi (OpenAI-compatible /v1, key in config, ~/.pi relocated via HOME) ──@@ -6719,7 +6987,7 @@ def test_connect_pi_no_launch(fake_studio, tmp_path, monkeypatch):assert config["providers"]["unsloth"]["models"] == [{"id": MODEL["id"], "contextWindow": MODEL["context_length"], "maxTokens": 32000}]- assert not any(c[1].endswith("/api/inference/status") for c in fake_studio)+ assert not any(c[1].split("?")[0].endswith("/api/inference/status") for c in fake_studio)assert (home / ".pi" / "agent" / "extensions" / "mine.ts").is_file()settings = json.loads((home / ".pi" / "agent" / "settings.json").read_text())assert settings == {"packages": ["npm:pi-mine"]}@@ -7511,6 +7779,22 @@ def test_vibe_sends_recommended_temperature(fake_studio, monkeypatch, argv, statassert json.loads(captured["env"]["VIBE_MODELS"])[0].get("temperature") == expected+def test_vibe_sends_the_kept_models_recommended_temperature(fake_studio, monkeypatch):+ def status(+ base,+ key,+ model_id = None,+ ):+ if model_id == MODEL["id"]:+ return {"active_model": MODEL["id"], "inference": {"temperature": 0.6}}+ return {"active_model": "unsloth/Other-GGUF", "inference": {"temperature": 1.0}}++ monkeypatch.setattr(start, "_inference_status", status)+ monkeypatch.setattr(start.shutil, "which", lambda _: "/usr/local/bin/vibe")+ captured = _capture_launch(monkeypatch, ["vibe"])+ assert json.loads(captured["env"]["VIBE_MODELS"])[0].get("temperature") == 0.6++def test_vibe_install_hint_per_os(monkeypatch):monkeypatch.setattr(start.os, "name", "nt")assert start._vibe_install_hint() == start._VIBE_WINDOWS_INSTALL_HINT@@ -9848,7 +10132,7 @@ def test_codex_preload_gate_checks_direct_path_identity(fake_studio, monkeypatch):if url.endswith("/api/inference/loaded-models"):return {"data": [{"id": "foo-Q4_K_M", "loaded": True}]}- if url.endswith("/api/inference/status"):+ if url.split("?")[0].endswith("/api/inference/status"):return {"is_gguf": True,"gguf_variant": "Q4_K_M",@@ -9908,7 +10192,7 @@ def test_codex_preload_gate_runs_for_a_mistyped_resident_variant(fake_studio, motimeout = 30,error = None,):- if url.endswith("/api/inference/status"):+ if url.split("?")[0].endswith("/api/inference/status"):return {"is_gguf": True, "gguf_variant": "Q4_K_M"}if "/api/models/gguf-variants" in url:probed.append(url)@@ -9936,7 +10220,7 @@ def test_codex_preload_gate_defers_to_the_resident_model(fake_studio, monkeypatctimeout = 30,error = None,):- if url.endswith("/api/inference/status"):+ if url.split("?")[0].endswith("/api/inference/status"):return {"is_gguf": True, "gguf_variant": "Q4_K_M"}if "/api/models/gguf-variants" in url:pytest.fail("the resident model already serves this request")@@ -9963,7 +10247,7 @@ def test_codex_preload_gate_still_runs_for_a_different_variant(fake_studio, monktimeout = 30,error = None,):- if url.endswith("/api/inference/status"):+ if url.split("?")[0].endswith("/api/inference/status"):return {"is_gguf": True, "gguf_variant": "Q4_K_M"}if "/api/models/gguf-variants" in url:probed.append(url)@@ -10360,6 +10644,33 @@ def test_require_gguf_for_agent_reads_the_servers_status(monkeypatch, capsys):)+def test_require_gguf_for_agent_reads_the_requested_models_slot(monkeypatch, capsys):+ def http_json(method, url, key, **_):+ if "model=unsloth%2FQwen3-1.7B-GGUF" in url:+ return {"is_gguf": True, "active_model": "unsloth/Qwen3-1.7B-GGUF"}+ return {"is_gguf": False, "active_model": "unsloth/Qwen3-0.6B"}++ monkeypatch.setattr(start, "_http_json", http_json)+ start._require_gguf_for_agent(+ start._CLAUDE_GGUF_AGENT, BASE, "sk-test", "unsloth/Qwen3-1.7B-GGUF"+ )++ monkeypatch.setattr(+ start,+ "_http_json",+ lambda method, url, key, **_: (+ {"is_gguf": False, "active_model": "unsloth/Qwen3-0.6B"}+ if "model=unsloth%2FQwen3-0.6B" in url+ else {"is_gguf": True, "active_model": "unsloth/Qwen3-4B-GGUF"}+ ),+ )+ with pytest.raises(typer.Exit):+ start._require_gguf_for_agent(+ start._CLAUDE_GGUF_AGENT, BASE, "sk-test", "unsloth/Qwen3-0.6B"+ )+ assert "Claude Code needs a GGUF model" in capsys.readouterr().err++def test_claude_preflight_rejects_non_gguf_repo(monkeypatch, capsys):_fake_hub_listing(monkeypatch, {"mlx-community/Qwen3-0.6B-4bit": []})with pytest.raises(typer.Exit):@@ -10491,7 +10802,7 @@ def test_claude_post_connect_failure_tears_down_auto_served(fake_studio, monkeyptimeout = 30,error = None,):- if url.endswith("/api/inference/status"):+ if url.split("?")[0].endswith("/api/inference/status"):return {"is_gguf": False, "model_identifier": "transformers-model"}return inner(method, url, token, payload, timeout, error)@@ -10517,7 +10828,7 @@ def test_claude_post_connect_failure_spares_an_attached_server(fake_studio, monktimeout = 30,error = None,):- if url.endswith("/api/inference/status"):+ if url.split("?")[0].endswith("/api/inference/status"):return {"is_gguf": False, "model_identifier": "transformers-model"}return inner(method, url, token, payload, timeout, error)@@ -10698,7 +11009,7 @@ def test_an_unreadable_status_leaves_the_auto_served_server_alone(fake_studio, mtimeout = 30,error = None,):- if url.endswith("/api/inference/status"):+ if url.split("?")[0].endswith("/api/inference/status"):raise urllib.error.HTTPError(url, 500, "Failed to get status", None, None)return inner(method, url, token, payload, timeout, error)@@ -10723,7 +11034,7 @@ def test_a_status_body_without_is_gguf_still_launches(fake_studio, monkeypatch,timeout = 30,error = None,):- if url.endswith("/api/inference/status"):+ if url.split("?")[0].endswith("/api/inference/status"):return {"model_identifier": MODEL["id"]}return inner(method, url, token, payload, timeout, error)diff --git a/unsloth_cli/tests/test_start_app.py b/unsloth_cli/tests/test_start_app.pyindex 85382d06155..df6c6741766 100644--- a/unsloth_cli/tests/test_start_app.py+++ b/unsloth_cli/tests/test_start_app.py@@ -58,7 +58,7 @@ def studio(tmp_path, monkeypatch):if token not in server["keys"] and token != "jwt":raise start.urllib.error.HTTPError(url, 401, "Unauthorized", {}, None)return {"object": "list", "data": [MODEL]}- if url.endswith("/api/inference/status"):+ if url.split("?")[0].endswith("/api/inference/status"):return {"is_gguf": True, "model_identifier": MODEL["id"]}if url.endswith("/api/auth/api-keys") and method == "GET":return {"api_keys": [{"key_prefix": CLI_KEY[11:19]}]}