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: tighten the comments on the responses attachment refusal

danielhanchena785ad3ee6ce
diff --git a/studio/backend/routes/inference.py b/studio/backend/routes/inference.py
index b2f547dff88..f12e616cc27 100644
--- a/studio/backend/routes/inference.py
+++ b/studio/backend/routes/inference.py
@@ -27758,19 +27758,12 @@ def _responses_reasoning_output_item(
def _reject_unserviceable_responses_attachment(part) -> None:
"""Refuse an attachment the local adapter cannot serve, instead of dropping it.
- ``_responses_tool_output_content`` already answers these exact shapes with a typed 400
- when they arrive as a tool result; the same four rules and the same wording apply to a
- message content part, so one server does not explain the gap in one place and hide it in
- another.
-
- A part reaches here only after failing its typed variant, so an ``input_image`` that got
- this far is missing its ``image_url``, or carries a ``detail`` outside the documented set,
- or both. An image carrying ``image_url`` *and* ``file_id`` validates normally and is
- served from the URL -- ``file_id`` means "instead of a URL" here, exactly as it does on
- the tool-result path.
-
- Called for every role, before the system/developer hoist and the assistant flatten, since
- an attachment vanishes just as quietly from those turns as it does from a user turn.
+ Same four rules and same wording as ``_responses_tool_output_content``, which already
+ answers these shapes as a tool result; two vocabularies for one question is the bug.
+ A part reaches here only after failing its typed variant, so an ``input_image`` here has
+ no ``image_url``, or a ``detail`` outside the documented set, or both. One with both
+ ``image_url`` and ``file_id`` never arrives: ``file_id`` means instead of a URL, not
+ as well as, so it validates and is served from the URL on this path and on that one.
"""
part_type = getattr(part, "type", None)
if part_type == "input_file":
@@ -27802,10 +27795,7 @@ def _reject_unserviceable_responses_attachment(part) -> None:
def _reject_unserviceable_responses_attachments(item) -> None:
- """Run the attachment refusal over one input message's content parts.
-
- Only list content carries parts; a plain string cannot hide an attachment.
- """
+ """Run the attachment refusal over one input message's content parts."""
if isinstance(item.content, str):
return
for part in item.content or []:
@@ -27815,11 +27805,9 @@ def _reject_unserviceable_responses_attachments(item) -> None:
def _reject_unknown_responses_message_part(part) -> None:
"""Refuse a content part no local route can serve, naming the type.
- Mirrors ``_reject_unsupported_content_parts`` on the Chat Completions side: a part left
- standing is dropped in silence and the model answers a prompt the caller did not send.
- Applied to user turns only, so an assistant replay turn keeps the lenient text flatten
- it has always had -- clients round-trip prior assistant output verbatim and must not be
- made to fail on a part that carries no attachment.
+ Mirrors ``_reject_unsupported_content_parts`` on the Chat Completions side. User turns
+ only: clients round-trip prior assistant output verbatim, so hoisting this one too would
+ fail a replay turn over a part that carries no attachment.
"""
_raise_unsupported_openai_parameter(
"input",
@@ -27950,9 +27938,8 @@ def _normalise_responses_input(payload: ResponsesRequest) -> list[ChatMessage]:
# don't 422.
continue
- # ResponsesInputMessage. Refuse an attachment this adapter cannot serve before the
- # role branches below, each of which returns via `continue` and would otherwise carry
- # a system, developer or assistant turn's attachment away in silence.
+ # ResponsesInputMessage. Before the role branches: each returns via `continue`, so a
+ # refusal placed after them loses a system, developer or assistant attachment.
_reject_unserviceable_responses_attachments(item)
# Hoist system/developer to the top, merge.
@@ -27976,9 +27963,8 @@ def _normalise_responses_input(payload: ResponsesRequest) -> list[ChatMessage]:
messages.append(ChatMessage(role = "assistant", content = text))
continue
- # User (and any other remaining roles). Attachments are already refused above; a part
- # still standing here is one no local route can serve, so name it rather than answer
- # a prompt the caller did not send.
+ # User (and any other remaining roles). Attachments were refused above, so a part
+ # still standing is one no local route can serve.
parts: list = []
for part in item.content:
if isinstance(part, (ResponsesInputTextPart, ResponsesOutputTextPart)):
diff --git a/studio/backend/tests/test_responses_message_attachments.py b/studio/backend/tests/test_responses_message_attachments.py
index 78e96df3bc4..2f4733adcf0 100644
--- a/studio/backend/tests/test_responses_message_attachments.py
+++ b/studio/backend/tests/test_responses_message_attachments.py
@@ -107,8 +107,7 @@ def test_the_route_refuses_an_attachment_on_a_non_user_turn(role):
@pytest.mark.parametrize("case", _REFUSED_PARTS, ids = _part_id)
def test_the_refusal_lands_before_the_model_switch(case, monkeypatch):
- """The route documents this invariant for its other refusals: an invalid request must
- never evict the resident model on its way to a 400."""
+ """The route holds this for its other refusals: a 400 must not evict the model."""
import routes.inference as inference_route
switched = []
@@ -140,9 +139,8 @@ def test_the_refusal_lands_before_the_model_switch(case, monkeypatch):
def test_a_servable_turn_is_not_refused(part):
"""The refusal must not reach past the shapes it owns.
- There is no model here, so a servable turn stops at the load check further down the
- handler. Reaching that check is the assertion: it can only be reached by a request
- normalisation accepted.
+ No model here, so a servable turn stops at the load check below; reaching it is the
+ assertion, since only an accepted normalisation gets that far.
"""
with _route_client() as client:
response = client.post("/v1/responses", json = _body(part))
diff --git a/studio/backend/tests/test_responses_tool_passthrough.py b/studio/backend/tests/test_responses_tool_passthrough.py
index 809e2e54df9..f0b956ada7a 100644
--- a/studio/backend/tests/test_responses_tool_passthrough.py
+++ b/studio/backend/tests/test_responses_tool_passthrough.py
@@ -858,9 +858,8 @@ class TestNormaliseResponsesInputWithTools:
assert "file_id" in str(exc.value.detail)
def test_unmodelled_message_part_is_named_not_dropped(self):
- # /chat/completions refuses an unmodelled part by name in
- # _reject_unsupported_content_parts. A part this endpoint drops instead is a part
- # the caller sent and the model never saw, so the two routes answer alike.
+ # Matches _reject_unsupported_content_parts on /chat/completions; a part dropped
+ # here is one the caller sent and the model never saw.
payload = ResponsesRequest(
input = [
{
@@ -878,8 +877,7 @@ class TestNormaliseResponsesInputWithTools:
assert "input_something_new" in str(exc.value.detail)
def test_image_message_part_without_any_source_rejected_clearly(self):
- # No image_url and no file_id: nothing to serve, and the tool-result path already
- # says so in these words.
+ # Nothing to serve, and the tool-result path already says so in these words.
payload = ResponsesRequest(
input = [
{
@@ -897,9 +895,8 @@ class TestNormaliseResponsesInputWithTools:
assert "require an image_url string" in str(exc.value.detail)
def test_image_message_part_with_unknown_detail_rejected_clearly(self):
- # detail is a Literal, so an out-of-set value fails ResponsesInputImagePart and the
- # whole image degrades to the catch-all. Dropping it loses an image the adapter
- # could have served from the url that is sitting right there.
+ # An out-of-set detail fails the Literal, so the whole part degrades to the
+ # catch-all and dropping it loses a url the adapter could have served.
payload = ResponsesRequest(
input = [
{
@@ -921,8 +918,7 @@ class TestNormaliseResponsesInputWithTools:
assert "auto, low, high, or original" in str(exc.value.detail)
def test_image_message_part_with_url_and_file_id_is_served_from_the_url(self):
- # file_id means "instead of a url" on both paths. With a url present there is
- # something to serve, so serve it rather than refuse the turn.
+ # file_id means instead of a url, not as well as: with a url, serve it.
payload = ResponsesRequest(
input = [
{
@@ -944,8 +940,8 @@ class TestNormaliseResponsesInputWithTools:
@pytest.mark.parametrize("role", ["system", "developer", "assistant"])
def test_attachment_refused_on_the_roles_that_exit_early(self, role):
- # system/developer hoist and assistant flatten each return via `continue`, so a
- # refusal placed in the user parts loop never sees their attachments.
+ # Both branches return via `continue`, so a refusal in the user parts loop
+ # never sees their attachments.
text_part = (
{"type": "output_text", "text": "hi"}
if role == "assistant"
@@ -966,9 +962,8 @@ class TestNormaliseResponsesInputWithTools:
assert "input_file" in str(exc.value.detail)
def test_assistant_replay_keeps_its_lenient_text_flatten(self):
- # Clients round-trip prior assistant output verbatim. A part that carries no
- # attachment must not fail a turn that used to work -- only attachments are refused
- # on a replay turn.
+ # Clients round-trip prior assistant output verbatim, so only attachments are
+ # refused on a replay turn.
payload = ResponsesRequest(
input = [
{
@@ -988,7 +983,6 @@ class TestNormaliseResponsesInputWithTools:
]
def test_string_content_never_hides_an_attachment(self):
- # A plain string cannot carry a part, so the refusal must not touch it.
payload = ResponsesRequest(
input = [
{"role": "system", "content": "be brief"},
@@ -1004,8 +998,7 @@ class TestNormaliseResponsesInputWithTools:
]
def test_refusal_body_is_the_openai_unsupported_parameter_shape(self):
- # Clients branch on error.code / error.param, so the refusal has to be typed the
- # way every other refusal on this route is typed.
+ # Clients branch on error.code / error.param.
payload = ResponsesRequest(
input = [
{"role": "user", "content": [{"type": "input_file", "filename": "r.pdf"}]}
@@ -1019,10 +1012,8 @@ class TestNormaliseResponsesInputWithTools:
assert error["type"] == "invalid_request_error"
-# Every message-part shape this route can be handed, and the one answer it owes each of
-# them. Kept as a table because the interesting failures are the combinations: a shape that
-# is refused on a user turn but dropped on a system turn, or an image refused for its
-# file_id when the url beside it was servable all along.
+# Every part shape and the one answer it is owed. A table because the failures are the
+# combinations: refused on a user turn but dropped on a system turn, and the like.
_IMG = "https://example.com/a.png"
_RESPONSES_PART_MATRIX = [
# (part, refused, needle in the message)
@@ -1080,9 +1071,8 @@ class TestResponsesMessagePartMatrix:
@pytest.mark.parametrize("case", _RESPONSES_PART_MATRIX, ids=_matrix_id)
@pytest.mark.parametrize("role", ["system", "developer", "assistant"])
def test_attachments_refused_on_every_role(self, case, role):
- # Only attachments are hoisted above the early exits. An unmodelled *text* part on
- # a replay turn keeps the lenient flatten, so it is expected to pass here even
- # though the same part is refused on a user turn.
+ # Only attachments are hoisted, so an unmodelled text part passes here while the
+ # same part is refused on a user turn.
part, refused, needle = case
attachment = part["type"] in ("input_file", "input_image")
payload = ResponsesRequest(
@@ -1114,8 +1104,7 @@ class TestResponsesMessagePartMatrix:
]
def test_top_level_item_types_are_untouched_by_the_refusal(self):
- # The refusal walks message items only. Reasoning items and tool items still take
- # the paths they always took.
+ # The refusal walks message items only.
payload = ResponsesRequest(
input = [
{"type": "reasoning", "summary": [], "id": "rs_1"},