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 keep the configured Decision checkpoint; signed-out Hub relay hides upstream errors (#14462)

Daniel Han782fa2ac8523
diff --git a/studio/backend/hub/endpoint_proxy.py b/studio/backend/hub/endpoint_proxy.py
index 1ebd6d5317d..e9edaf46ab8 100644
--- a/studio/backend/hub/endpoint_proxy.py
+++ b/studio/backend/hub/endpoint_proxy.py
@@ -182,7 +182,11 @@ def build_router(prefix: str, upstream: Callable[[], str], *, anonymous_pages: b
body = answer.aiter_bytes()
if anonymous:
kind = answer.headers.get("content-type", "").split(";")[0].strip().lower()
- if answer.is_success and (not kind.startswith("image/") or kind == "image/svg+xml"):
+ # An error page or x-error-* header can name the host this relay keeps private.
+ if not answer.is_success:
+ await answer.aclose()
+ return _refuse(answer.status_code, "The Hub endpoint returned an error.")
+ if not kind.startswith("image/") or kind == "image/svg+xml":
await answer.aclose()
return _refuse(401, "Sign in again to browse the Hub.")
if int(answer.headers.get("content-length") or 0) > ANONYMOUS_ASSET_LIMIT:
diff --git a/studio/backend/routes/systemone.py b/studio/backend/routes/systemone.py
index 35a18bc7988..8c34502ebf8 100644
--- a/studio/backend/routes/systemone.py
+++ b/studio/backend/routes/systemone.py
@@ -30,7 +30,7 @@ from core.systemone import catalog, laya_runtime
from routes.provider_credentials import provider_config_guard, resolve_provider_api_key_or_400
from storage import providers_db
from utils import systemone_settings
-from utils.account_context import OWNER, arun_as, run_as
+from utils.account_context import OWNER, arun_as, is_owner_context, run_as
MAX_QUESTIONS = 64
MAX_CHOICES = 255
@@ -155,14 +155,21 @@ async def system_one(
# Same rule as the OpenAI routes: a keyless caller never downloads or swaps in another model.
# Checked before the unknown-model answer, so it cannot tell which owner fine-tunes exist.
- if checkpoint != await asyncio.to_thread(
- catalog.default_checkpoint
- ) and await asyncio.to_thread(request_admitted_without_credential, request):
- raise _error(
- 403,
- "permission_error",
- "Keyless requests can only use the configured Decision API model; send an API key to pick another.",
- )
+ if checkpoint != await asyncio.to_thread(catalog.default_checkpoint):
+ if await asyncio.to_thread(request_admitted_without_credential, request):
+ raise _error(
+ 403,
+ "permission_error",
+ "Keyless requests can only use the configured Decision API model; send an API key to pick another.",
+ )
+ # Another checkpoint downloads into the shared cache and evicts the owner's resident model,
+ # which the owner-only settings, unload and resolve routes already keep from other accounts.
+ if not is_owner_context():
+ raise _error(
+ 403,
+ "permission_error",
+ "Only the Studio owner can pick a Decision API model other than the configured one.",
+ )
if checkpoint is None:
raise _error(400, "api_usage_error", f"Unknown model: {payload.model}")
result = await _decide(
diff --git a/studio/backend/tests/multi_account/test_decision_api_fine_tunes.py b/studio/backend/tests/multi_account/test_decision_api_fine_tunes.py
index 587a238d60b..35629b9213a 100644
--- a/studio/backend/tests/multi_account/test_decision_api_fine_tunes.py
+++ b/studio/backend/tests/multi_account/test_decision_api_fine_tunes.py
@@ -88,3 +88,39 @@ def test_a_managed_account_sees_only_the_configured_fine_tune(client):
assert view(owner) == (served, [private, served], private)
assert view(bob) == (served, [served], None)
+
+
+def test_a_managed_account_cannot_swap_in_another_catalog_checkpoint(client, monkeypatch):
+ loads = []
+ monkeypatch.setattr(
+ laya_runtime,
+ "_load_checkpoint",
+ lambda checkpoint: (loads.append(checkpoint.name), (SimpleNamespace(), "cpu"))[1],
+ )
+ owner, alice = _login(client, "unsloth"), _login(client, "alice")
+ saved = client.put(
+ "/api/settings/systemone",
+ json = {"enabled": True, "model": "laya-multilingual"},
+ headers = owner,
+ )
+ assert saved.status_code == 200, saved.text
+
+ def decide(model, headers):
+ return client.post(
+ "/v1/systemone",
+ json = {"model": model, "state": "x", "questions": QUESTIONS},
+ headers = headers,
+ )
+
+ assert decide("laya-multilingual", owner).status_code == 200
+ # The configured model, by name or alias, still answers a managed account.
+ assert decide("laya-multilingual", alice).status_code == 200
+ assert decide("default", alice).status_code == 200
+ swap = decide("laya-english", alice)
+ assert swap.status_code == 403, swap.text
+ assert swap.json()["detail"]["error_type"] == "permission_error"
+ assert laya_runtime._loaded.name == "laya-multilingual"
+ assert "laya-english" not in loads
+ # The owner still picks any catalog entry.
+ assert decide("laya-english", owner).status_code == 200
+ assert laya_runtime._loaded.name == "laya-english"
diff --git a/studio/backend/tests/test_hub_endpoint_proxy.py b/studio/backend/tests/test_hub_endpoint_proxy.py
index 6c879466419..315ef28a1d5 100644
--- a/studio/backend/tests/test_hub_endpoint_proxy.py
+++ b/studio/backend/tests/test_hub_endpoint_proxy.py
@@ -30,6 +30,16 @@ def _mirror(request: httpx.Request) -> httpx.Response:
if request.url.host == "down.test":
raise httpx.ConnectError("refused", request = request)
headers = {"Set-Cookie": "s=1", "Link": f'<{MIRROR}/api/models?cursor=2>; rel="next"'}
+ if "missing" in request.url.path:
+ return httpx.Response(
+ 404,
+ content = b"<h1>Not found on hub.internal.corp:8443</h1>",
+ headers = {
+ "Content-Type": "text/html",
+ "X-Error-Code": "EntryNotFound",
+ "X-Error-Message": "hub.internal.corp:8443 has no such file",
+ },
+ )
kinds = {".png": "image/png", ".svg": "image/svg+xml", ".html": "text/html"}
for suffix, kind in kinds.items():
if request.url.path.endswith(suffix):
@@ -177,3 +187,18 @@ def test_a_signed_out_relay_refuses_large_files(proxy, monkeypatch):
monkeypatch.setattr(hub_settings, "_saved_only_endpoints", frozenset({MIRROR}), raising = False)
monkeypatch.setattr(endpoint_proxy, "ANONYMOUS_ASSET_LIMIT", 1)
assert client.get(f"{HUB}/org/m/resolve/main/big.png").status_code == 413
+
+
[email protected]("path", ["/org/m/resolve/main/missing.png", "/org/missing/raw/main/a.png"])
+def test_a_signed_out_relay_never_streams_an_upstream_error(proxy, monkeypatch, path):
+ import utils.hub_settings as hub_settings
+
+ client, seen, state = proxy
+ state["session"] = False
+ monkeypatch.setattr(endpoint_proxy, "client_ip", lambda _request: "203.0.113.9")
+ monkeypatch.setattr(hub_settings, "_saved_only_endpoints", frozenset({MIRROR}), raising = False)
+ page = client.get(f"{HUB}{path}", follow_redirects = False)
+ assert len(seen) == 1 and page.status_code == 404
+ assert b"internal" not in page.content
+ assert "x-error-code" not in page.headers
+ assert "internal" not in page.headers.get("x-error-message", "")