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.

Studio: managed accounts cannot use another account's loaded model or export worker (#14432)

Daniel Han7986436a1b58
diff --git a/studio/backend/core/export/orchestrator.py b/studio/backend/core/export/orchestrator.py
index 64f903951d9..b732da99813 100644
--- a/studio/backend/core/export/orchestrator.py
+++ b/studio/backend/core/export/orchestrator.py
@@ -18,6 +18,7 @@ import atexit
import os
import structlog
from collections import deque
+from fastapi import HTTPException
from loggers import get_logger
import multiprocessing as mp
import queue
@@ -95,6 +96,9 @@ class ExportOrchestrator:
# ------------------------------------------------------------------
def _clear_account_result(self):
+ # Under _account_job_lock: the worker holds the previous account's model; one that will not stop reports busy.
+ if not self._shutdown_subprocess():
+ raise HTTPException(status_code = 409, detail = {"code": "job_busy", "message": "Busy"})
self.current_checkpoint = None
self.is_vision = self.is_peft = False
self.decision = None
diff --git a/studio/backend/routes/inference.py b/studio/backend/routes/inference.py
index 6be23286e8b..541257acafb 100644
--- a/studio/backend/routes/inference.py
+++ b/studio/backend/routes/inference.py
@@ -11635,12 +11635,23 @@ async def _maybe_auto_switch_model(
return
async def _refuse_foreign_resident() -> None:
- """Serve a named model only if the resident is the caller's own or answers to the name."""
+ """Serve a named model only if the resident is the caller's own, or answers to the name
+ and is itself a model the caller may load."""
if not named_model or not account_access.managed_account():
return
if not account_access.resident_hidden("chat", _loaded_slot_ident()):
return
if await asyncio.to_thread(_loaded_identity_satisfies, named_model):
+ # The name was authorized, not the resident: a caller's own file can carry any id.
+ resident = _loaded_slot_ident()
+ try:
+ await asyncio.to_thread(account_access.require_model_access, resident)
+ except HTTPException as refusal:
+ # A Hub resident the caller's own token can fetch is theirs to use as well.
+ if refusal.status_code != 404 or not await _caller_token_authorizes_download(
+ str(resident or ""), fastapi_request
+ ):
+ raise
return
raise HTTPException(status_code = 404, detail = "Model not found")
@@ -11747,6 +11758,7 @@ async def _maybe_auto_switch_model(
# from resident state before consulting the filesystem index: rebuilding a stale
# multi-root index here used to hold the request for seconds before streaming.
if auto_switch_on and await asyncio.to_thread(_loaded_identity_satisfies, requested_model):
+ await _refuse_foreign_resident()
warm_index_soon()
if claim_resident:
_claim_slot_for_non_preview(fastapi_request)
diff --git a/studio/backend/tests/test_account_inference_isolation.py b/studio/backend/tests/test_account_inference_isolation.py
index 34b59582618..dcca4c854db 100644
--- a/studio/backend/tests/test_account_inference_isolation.py
+++ b/studio/backend/tests/test_account_inference_isolation.py
@@ -510,6 +510,77 @@ def test_the_local_id_v1_models_publishes_is_usable_by_its_own_account(monkeypat
assert refused.value.status_code == 404
[email protected]("auto_switch", [False, True])
[email protected]("public", [False, True])
+def test_an_own_file_listed_under_a_foreign_residents_id_does_not_unlock_it(
+ monkeypatch, auto_switch, public
+):
+ from utils import openai_auto_switch_settings
+ from utils.paths.storage_roots import workspace_root
+
+ own = str(run_as(ALICE, workspace_root) / "sandbox" / "org" / "private.gguf")
+ row = SimpleNamespace(model_id = "org/private", id = own, path = own)
+ monkeypatch.setattr(inference, "_classified_catalog", lambda listed: listed)
+ monkeypatch.setattr(models, "collect_local_models", lambda *_a, **_kw: [row])
+ monkeypatch.setattr(access, "repo_is_public", lambda *a, **k: public)
+ monkeypatch.setattr(
+ openai_auto_switch_settings, "get_openai_auto_switch_enabled", lambda: auto_switch
+ )
+ monkeypatch.setattr(openai_auto_switch_settings, "idle_unload_is_configured", lambda: False)
+ monkeypatch.setattr(inference, "_loaded_slot_ident", lambda: "org/private")
+ monkeypatch.setattr(inference, "_loaded_satisfies", lambda model: True)
+ monkeypatch.setattr(inference, "_loaded_identity_satisfies", lambda model: True)
+ claimed = []
+ monkeypatch.setattr(inference, "_claim_slot_for_non_preview", claimed.append)
+ request = SimpleNamespace(
+ scope = {},
+ state = SimpleNamespace(),
+ url = SimpleNamespace(path = "/v1/chat/completions"),
+ )
+ switch = arun_as(ALICE, inference._maybe_auto_switch_model("org/private", request, "alice"))
+ if public:
+ asyncio.run(switch)
+ assert claimed
+ return
+ with pytest.raises(HTTPException) as refused:
+ asyncio.run(switch)
+ assert refused.value.status_code == 404
+ assert not claimed
+
+
+def test_a_private_hub_resident_the_callers_own_token_can_fetch_is_served(monkeypatch):
+ from utils import openai_auto_switch_settings
+ from utils.paths.storage_roots import workspace_root
+
+ own = str(run_as(ALICE, workspace_root) / "sandbox" / "org" / "private.gguf")
+ row = SimpleNamespace(model_id = "org/private", id = own, path = own)
+ monkeypatch.setattr(inference, "_classified_catalog", lambda listed: listed)
+ monkeypatch.setattr(models, "collect_local_models", lambda *_a, **_kw: [row])
+ monkeypatch.setattr(access, "repo_is_public", lambda *a, **k: False)
+ monkeypatch.setattr(openai_auto_switch_settings, "get_openai_auto_switch_enabled", lambda: True)
+ monkeypatch.setattr(openai_auto_switch_settings, "idle_unload_is_configured", lambda: False)
+ monkeypatch.setattr(inference, "_loaded_slot_ident", lambda: "org/private")
+ monkeypatch.setattr(inference, "_loaded_satisfies", lambda model: True)
+ monkeypatch.setattr(inference, "_loaded_identity_satisfies", lambda model: True)
+ authorized = []
+
+ async def _token_authorizes(named_model, request):
+ authorized.append(named_model)
+ return named_model == "org/private"
+
+ monkeypatch.setattr(inference, "_caller_token_authorizes_download", _token_authorizes)
+ claimed = []
+ monkeypatch.setattr(inference, "_claim_slot_for_non_preview", claimed.append)
+ request = SimpleNamespace(
+ scope = {},
+ state = SimpleNamespace(),
+ url = SimpleNamespace(path = "/v1/chat/completions"),
+ )
+ asyncio.run(arun_as(ALICE, inference._maybe_auto_switch_model("org/private", request, "alice")))
+ assert claimed
+ assert "org/private" in authorized
+
+
def test_private_media_index_rows_cannot_bypass_filtered_openai_catalog(monkeypatch):
picks = {
"text-to-image": [
diff --git a/studio/backend/tests/test_job_accounts.py b/studio/backend/tests/test_job_accounts.py
index 6b449c8c514..e0ecbc90eb3 100644
--- a/studio/backend/tests/test_job_accounts.py
+++ b/studio/backend/tests/test_job_accounts.py
@@ -225,6 +225,43 @@ def test_export_finished_checkpoint_and_logs_are_private(export):
assert proc.is_alive()
+def test_export_handover_never_leaves_the_previous_accounts_worker(export, monkeypatch):
+ from utils.models import checkpoints
+
+ backend, proc = export
+ assert run_as(ALICE, backend.load_checkpoint, str(run_as(ALICE, outputs_root) / "checkpoint"))[
+ 0
+ ]
+
+ def unparsable(*args):
+ raise RecursionError
+
+ # Bob's load fails after he became the owner and before it would have replaced the worker.
+ monkeypatch.setattr(checkpoints, "is_unquantized_full_finetune", unparsable)
+ with pytest.raises(RecursionError):
+ run_as(
+ BOB, backend.load_checkpoint, str(run_as(BOB, outputs_root) / "c"), load_in_4bit = None
+ )
+ assert not proc.is_alive()
+ result = run_as(BOB, backend.export_base_model, str(run_as(BOB, exports_root)))
+ assert result[0] is False and "No export subprocess running" in result[1]
+
+
+def test_export_handover_is_refused_while_the_previous_worker_survives(export, monkeypatch):
+ backend, proc = export
+ assert run_as(ALICE, backend.load_checkpoint, str(run_as(ALICE, outputs_root) / "checkpoint"))[
+ 0
+ ]
+ monkeypatch.setattr(backend, "_shutdown_subprocess", lambda **kwargs: False)
+ with pytest.raises(HTTPException) as exc:
+ run_as(BOB, backend.load_checkpoint, str(run_as(BOB, outputs_root) / "checkpoint"))
+ assert exc.value.status_code == 409
+ assert backend._result_account == ALICE and backend.current_checkpoint is not None
+ with pytest.raises(HTTPException) as exc:
+ run_as(BOB, backend.export_base_model, str(run_as(BOB, exports_root)))
+ assert exc.value.status_code == 404
+
+
def test_export_busy_status_hides_checkpoint(export, monkeypatch):
from routes import export as route