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: show why llama-server rejected a chat request (#15817)

Nilaye296c20e4b68
diff --git a/studio/backend/routes/inference.py b/studio/backend/routes/inference.py
index 82480c3fc30..2e049285b03 100644
--- a/studio/backend/routes/inference.py
+++ b/studio/backend/routes/inference.py
@@ -147,6 +147,7 @@ from core.inference.memory_contract import (
from core.inference.stream_errors import (
KV_STARVATION_MESSAGE,
LlamaStreamError,
+ error_message_from_chunk,
is_kv_starvation,
)
from core.inference.orchestrator import (
@@ -314,6 +315,7 @@ _LOST_CONNECTION_MSG = (
_OVERSIZE_TOKENS_RE = _re.compile(
r"request \((\d+) tokens?\) exceeds the available context size \((\d+) tokens?\)"
)
+_LLAMA_CLIENT_ERROR_RE = _re.compile(r"llama-server returned 4\d\d: (.*)", _re.DOTALL)
def _friendly_error(exc: Exception) -> str:
@@ -353,6 +355,14 @@ def _friendly_error(exc: Exception) -> str:
# After the token-count regex, before the catch-all, so stream failures keep their cause.
if isinstance(exc, LlamaStreamError):
return exc.friendly
+ client_error = _LLAMA_CLIENT_ERROR_RE.match(msg)
+ if client_error:
+ body = client_error.group(1)
+ try:
+ body = error_message_from_chunk(json.loads(body)) or body
+ except ValueError:
+ pass
+ return _friendly_upstream_error(body[:500])
return "An internal error occurred"
diff --git a/studio/backend/tests/test_stream_errors.py b/studio/backend/tests/test_stream_errors.py
index b879ff751a1..24b22b2cc88 100644
--- a/studio/backend/tests/test_stream_errors.py
+++ b/studio/backend/tests/test_stream_errors.py
@@ -353,3 +353,32 @@ class TestTheStarvationTextDoesNotReadAsAContextLimitOnTheClient:
raw = "Context size has been exceeded."
assert any(m in raw.lower() for m in self.CLIENT_CONTEXT_LIMIT_MARKERS)
assert describe_stream_error(raw) == KV_STARVATION_MESSAGE
+
+
+class TestARefusalBeforeTheReplyStartsKeepsItsCause:
+ REFUSAL = RuntimeError(
+ 'llama-server returned 400: {"error":{"code":400,"message":"Cannot have 2 or more '
+ 'assistant messages at the end of the list.","type":"invalid_request_error"}}'
+ )
+
+ @staticmethod
+ def _routes():
+ import routes.inference as routes_inference
+ return routes_inference
+
+ def test_the_server_message_reaches_the_client(self):
+ routes = self._routes()
+ expected = (
+ "llama-server error: Cannot have 2 or more assistant messages at the end of the list."
+ )
+ assert routes._friendly_error(self.REFUSAL) == expected
+ chunk = routes._openai_stream_error_chunk(self.REFUSAL)
+ assert chunk["error"]["message"] == expected
+ assert chunk["error"]["type"] == "invalid_request_error"
+
+ def test_a_server_failure_stays_generic(self):
+ routes = self._routes()
+ failure = RuntimeError(
+ 'llama-server returned 500: {"error":{"code":500,"message":"/srv/secret crashed"}}'
+ )
+ assert routes._friendly_error(failure) == "An internal error occurred"