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: final comment pass on the responses attachment refusal

danielhanchenc4c3bf55c7ba
diff --git a/studio/backend/routes/inference.py b/studio/backend/routes/inference.py
index aecc1b0918d..542ef7367d3 100644
--- a/studio/backend/routes/inference.py
+++ b/studio/backend/routes/inference.py
@@ -27758,21 +27758,18 @@ def _responses_reasoning_output_item(
def _reject_unserviceable_responses_attachment(part, *, role = "user") -> None:
"""Refuse an attachment the local adapter cannot serve, instead of dropping it.
- 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.
+ Same rules and wording as ``_responses_tool_output_content``; two vocabularies for one
+ question is the bug. A part only reaches here by failing its typed variant, so an
+ ``input_image`` here lacks ``image_url``, or carries an undocumented ``detail``, or both.
+ One with ``image_url`` and ``file_id`` both never arrives: ``file_id`` means instead of
+ a URL, so it validates and is served from the URL, here and on the tool-result path.
"""
part_type = getattr(part, "type", None)
if part_type in ("input_text", "output_text") and not isinstance(
part, (ResponsesInputTextPart, ResponsesOutputTextPart)
):
- # A text part that lost its `text` field is a ResponsesUnknownContentPart wearing a
- # known type name, so it passes a name-only allowlist and is then dropped by both the
- # flatten and the parts loop. Say what is wrong with it, the way the tool-result path
- # does, rather than "parts of type 'input_text' are not supported", which is untrue.
+ # Wearing a known type name, so a name-only allowlist waves it through and the
+ # flatten drops it. "type 'input_text' is not supported" would also be untrue.
_raise_unsupported_openai_parameter(
"input",
f"Responses {part_type} message parts require a text field.",
@@ -27811,14 +27808,11 @@ def _reject_unserviceable_responses_attachment(part, *, role = "user") -> None:
)
-# The only part types a flatten may discard without losing something the caller sent, per
-# role. Text survives the flatten as text anywhere. ``refusal`` and ``summary_text`` are the
-# model's own output metadata that clients round-trip, so they are free to drop on a replay
-# turn -- but only there: on system or developer they are caller content like any other, and
-# a metadata-only turn would vanish whole.
-# An allowlist, not an ``input_`` prefix test: OpenAI's enumeration is input_text,
-# input_image, output_text, refusal, input_file, computer_screenshot, summary_text, so a
-# prefix test would wave ``computer_screenshot`` through.
+# What a flatten may discard without losing caller content. Metadata is the model's own
+# output, free to drop on a replay turn and only there; on system or developer it is content
+# someone wrote. An allowlist, not an ``input_`` prefix test, which misses
+# ``computer_screenshot`` (OpenAI's set: input_text, input_image, output_text, refusal,
+# input_file, computer_screenshot, summary_text).
_RESPONSES_TEXT_PART_TYPES = frozenset({"input_text", "output_text"})
_RESPONSES_ASSISTANT_METADATA_PART_TYPES = frozenset({"refusal", "summary_text"})
@@ -27832,10 +27826,10 @@ def _responses_part_survives_flatten(part_type, role) -> bool:
def _reject_unserviceable_responses_attachments(item) -> None:
"""Run the attachment refusal over one input message's content parts.
- Role matters: only a user turn keeps its parts. Every other role is flattened by
- ``_responses_message_text``, which keeps text and silently dropped everything else,
- because Chat Completions wants a plain string on system and assistant and strict
- templates reject an array there. Nothing can be forwarded there, only refused.
+ Only a user turn keeps its parts. ``_responses_message_text`` flattens the rest to text
+ and silently dropped everything else, and nothing can be forwarded there instead:
+ Chat Completions wants a plain string on system and assistant, and the strict templates
+ this normaliser exists for reject an array.
"""
if isinstance(item.content, str):
return
diff --git a/studio/backend/tests/test_responses_tool_passthrough.py b/studio/backend/tests/test_responses_tool_passthrough.py
index b9544a7d5d2..3e6ab5c57f1 100644
--- a/studio/backend/tests/test_responses_tool_passthrough.py
+++ b/studio/backend/tests/test_responses_tool_passthrough.py
@@ -858,8 +858,7 @@ class TestNormaliseResponsesInputWithTools:
assert "file_id" in str(exc.value.detail)
def test_unmodelled_message_part_is_named_not_dropped(self):
- # Matches _reject_unsupported_content_parts on /chat/completions; a part dropped
- # here is one the caller sent and the model never saw.
+ # Matches _reject_unsupported_content_parts on /chat/completions.
payload = ResponsesRequest(
input = [
{
@@ -895,8 +894,7 @@ class TestNormaliseResponsesInputWithTools:
assert "require an image_url string" in str(exc.value.detail)
def test_image_message_part_with_unknown_detail_rejected_clearly(self):
- # 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.
+ # Fails the Literal, degrades to the catch-all, and loses a servable url with it.
payload = ResponsesRequest(
input = [
{
@@ -940,8 +938,7 @@ class TestNormaliseResponsesInputWithTools:
@pytest.mark.parametrize("role", ["system", "developer", "assistant"])
def test_attachment_refused_on_the_roles_that_exit_early(self, role):
- # Both branches return via `continue`, so a refusal in the user parts loop
- # never sees their attachments.
+ # Both return via `continue`, so a refusal in the user parts loop never sees them.
text_part = (
{"type": "output_text", "text": "hi"}
if role == "assistant"
@@ -1010,8 +1007,7 @@ class TestNormaliseResponsesInputWithTools:
assert error["type"] == "invalid_request_error"
-# 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.
+# Every part shape and the answer it is owed; the failures live in the combinations.
_IMG = "https://example.com/a.png"
_RESPONSES_PART_MATRIX = [
# (part, refused, needle in the message)
@@ -1097,9 +1093,8 @@ class TestResponsesMessagePartMatrix:
@pytest.mark.parametrize("role", ["system", "developer", "assistant"])
def test_a_servable_image_is_refused_on_a_role_that_flattens(self, role):
- # The role branches flatten content through _responses_message_text, which keeps only
- # text, so an image that passed every shape check still vanished. Forwarding it is not
- # an option: Chat Completions wants a plain string on system and assistant.
+ # Passed every shape check and vanished in the flatten anyway. Nowhere to forward
+ # it to: Chat Completions wants a plain string on system and assistant.
text_part = (
{"type": "output_text", "text": "hi"}
if role == "assistant"
@@ -1134,8 +1129,7 @@ class TestResponsesMessagePartMatrix:
ids = ["input_audio", "computer_screenshot", "future"],
)
def test_a_non_text_part_is_refused_on_a_role_that_flattens(self, role, part):
- # The flatten keeps text and drops the rest, so anything else on these roles is
- # caller content that vanishes. A user turn already refused these by name.
+ # Anything the flatten does not keep is caller content that vanishes.
text_part = (
{"type": "output_text", "text": "hi"}
if role == "assistant"
@@ -1165,9 +1159,7 @@ class TestResponsesMessagePartMatrix:
ids = ["no_text", "null_text", "int_text", "output_no_text"],
)
def test_a_text_part_without_text_is_named_for_what_is_wrong(self, role, part):
- # It fails its typed variant and becomes a ResponsesUnknownContentPart wearing a known
- # type name, so a name-only allowlist waves it through and both the flatten and the
- # parts loop then drop it. "type 'input_text' is not supported" would also be untrue.
+ # A known type name on an untyped part: waved through, then dropped by the flatten.
payload = ResponsesRequest(
input = [
{"role": role, "content": [part]},
@@ -1181,8 +1173,7 @@ class TestResponsesMessagePartMatrix:
assert part["type"] in str(exc.value.detail)
def test_a_malformed_text_part_does_not_hide_behind_a_good_one(self):
- # The turn still had servable text, so before this the request succeeded and only the
- # broken part went missing.
+ # Servable text beside it, so the request succeeded and only the broken part went.
payload = ResponsesRequest(
input = [
{
@@ -1199,9 +1190,7 @@ class TestResponsesMessagePartMatrix:
@pytest.mark.parametrize("part_type", ["refusal", "summary_text"])
@pytest.mark.parametrize("role", ["system", "developer"])
def test_output_metadata_is_caller_content_on_a_non_assistant_turn(self, role, part_type):
- # refusal and summary_text are only the model's own output on a replay turn. On system
- # or developer they are content the caller wrote, and the flatten dropped them: with
- # text beside them the turn still answered, and alone the turn vanished whole.
+ # Only the model's own output on a replay turn; elsewhere someone wrote it.
payload = ResponsesRequest(
input = [
{
@@ -1221,9 +1210,7 @@ class TestResponsesMessagePartMatrix:
@pytest.mark.parametrize("part_type", ["refusal", "summary_text"])
def test_assistant_output_metadata_survives_the_flatten(self, part_type):
- # refusal and summary_text are the model's own output, which clients round-trip.
- # They carry nothing the prompt needs, so the flatten may drop them in silence and
- # a replay turn must not start failing.
+ # Clients round-trip these, and the prompt needs nothing from them.
payload = ResponsesRequest(
input = [
{