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 passthrough: read the backend's identity through getattr in the cut scope (#13769)

Daniel Han5e927b0fa337
diff --git a/studio/backend/routes/inference.py b/studio/backend/routes/inference.py
index cc132c68009..7eda56981e8 100644
--- a/studio/backend/routes/inference.py
+++ b/studio/backend/routes/inference.py
@@ -1257,10 +1257,11 @@ def _passthrough_cut_scope(llama_backend, body: dict) -> tuple:
tools = sorted(
str(((tool or {}).get("function") or {}).get("name")) for tool in body.get("tools") or []
)
+ # getattr, as the rest of this module reads the backend: not every backend object carries both.
return (
"passthrough",
- llama_backend.model_identifier,
- llama_backend.context_length,
+ getattr(llama_backend, "model_identifier", None),
+ getattr(llama_backend, "context_length", None),
tuple(tools),
)
@@ -45490,7 +45491,7 @@ async def _openai_passthrough_stream_admitted(
_replay_passthrough_cut,
body,
_truncate_policy,
- llama_backend.context_length,
+ getattr(llama_backend, "context_length", None),
_cut_scope,
)
_context_was_truncated = _truncated_messages > 0
@@ -46417,7 +46418,11 @@ async def _openai_passthrough_non_streaming_upstream(
# Off the event loop: the history can hold megabytes of images.
_cut_scope = _passthrough_cut_scope(llama_backend, body)
_truncated_messages = await asyncio.to_thread(
- _replay_passthrough_cut, body, _truncate_policy, llama_backend.context_length, _cut_scope
+ _replay_passthrough_cut,
+ body,
+ _truncate_policy,
+ getattr(llama_backend, "context_length", None),
+ _cut_scope,
)
_context_was_truncated = _truncated_messages > 0
# One respawn per request, as on the streaming twin.
diff --git a/studio/backend/tests/test_prefix_boundary.py b/studio/backend/tests/test_prefix_boundary.py
index 017efaf0e3f..d710cb2a397 100644
--- a/studio/backend/tests/test_prefix_boundary.py
+++ b/studio/backend/tests/test_prefix_boundary.py
@@ -242,3 +242,14 @@ def test_an_image_does_not_count_as_prompt_text_in_the_overflow_check():
}
assert routes._replay_passthrough_cut({"messages": later}, "truncate_oldest", 4096, SCOPE) == 0
+
+
+def test_the_cut_scope_reads_a_backend_without_identity_attributes():
+ # The passthrough handlers are driven with backend objects that carry neither attribute; the rest of
+ # routes/inference.py reads both through getattr, and a bare attribute read here failed every one.
+ class Bare:
+ pass
+
+ scope = routes._passthrough_cut_scope(Bare(), {"tools": []})
+ assert scope == ("passthrough", None, None, ())
+ assert routes._replay_passthrough_cut({"messages": []}, "truncate_oldest", None, scope) == 0