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: only exempt output metadata on the turn that can carry it

danielhanchen193361ec9f00
diff --git a/studio/backend/routes/inference.py b/studio/backend/routes/inference.py
index 70705df2d52..aecc1b0918d 100644
--- a/studio/backend/routes/inference.py
+++ b/studio/backend/routes/inference.py
@@ -27811,15 +27811,22 @@ def _reject_unserviceable_responses_attachment(part, *, role = "user") -> None:
)
-# The only part types a flatten may discard without losing something the caller sent.
-# ``input_text`` / ``output_text`` survive the flatten as text; ``refusal`` and
-# ``summary_text`` are the model's own output metadata, which clients round-trip and the
-# prompt does not need. OpenAI's part enumeration is input_text, input_image, output_text,
-# refusal, input_file, computer_screenshot, summary_text -- so an allowlist, not an
-# ``input_`` prefix test, which would miss ``computer_screenshot``.
-_RESPONSES_FLATTENABLE_PART_TYPES = frozenset(
- {"input_text", "output_text", "refusal", "summary_text"}
-)
+# 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.
+_RESPONSES_TEXT_PART_TYPES = frozenset({"input_text", "output_text"})
+_RESPONSES_ASSISTANT_METADATA_PART_TYPES = frozenset({"refusal", "summary_text"})
+
+
+def _responses_part_survives_flatten(part_type, role) -> bool:
+ if part_type in _RESPONSES_TEXT_PART_TYPES:
+ return True
+ return role == "assistant" and part_type in _RESPONSES_ASSISTANT_METADATA_PART_TYPES
def _reject_unserviceable_responses_attachments(item) -> None:
@@ -27835,7 +27842,7 @@ def _reject_unserviceable_responses_attachments(item) -> None:
for part in item.content or []:
_reject_unserviceable_responses_attachment(part, role = item.role)
part_type = getattr(part, "type", None)
- if item.role != "user" and part_type not in _RESPONSES_FLATTENABLE_PART_TYPES:
+ if item.role != "user" and not _responses_part_survives_flatten(part_type, item.role):
_raise_unsupported_openai_parameter(
"input",
f"Responses message content parts of type '{part_type}' are not supported on "
diff --git a/studio/backend/tests/test_responses_tool_passthrough.py b/studio/backend/tests/test_responses_tool_passthrough.py
index b4c0869de7c..64dc0d00da4 100644
--- a/studio/backend/tests/test_responses_tool_passthrough.py
+++ b/studio/backend/tests/test_responses_tool_passthrough.py
@@ -1080,7 +1080,10 @@ class TestResponsesMessagePartMatrix:
{"role": "user", "content": "go on"},
],
)
- if part["type"] in ("input_text", "output_text", "refusal", "summary_text"):
+ survives = part["type"] in ("input_text", "output_text") or (
+ role == "assistant" and part["type"] in ("refusal", "summary_text")
+ )
+ if survives:
assert _normalise_responses_input(payload)
return
if part["type"] == "input_file":
@@ -1195,6 +1198,29 @@ class TestResponsesMessagePartMatrix:
_normalise_responses_input(payload)
assert "require a text field" in str(exc.value.detail)
+ @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.
+ payload = ResponsesRequest(
+ input = [
+ {
+ "role": role,
+ "content": [
+ {"type": "input_text", "text": "keep"},
+ {"type": part_type, "text": "x", "refusal": "x"},
+ ],
+ },
+ {"role": "user", "content": "go on"},
+ ],
+ )
+ with pytest.raises(HTTPException) as exc:
+ _normalise_responses_input(payload)
+ assert exc.value.status_code == 400
+ assert part_type in str(exc.value.detail)
+
@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.