From 8895a98fba851d02691ea48bbe002f7e6e92c499 Mon Sep 17 00:00:00 2001 From: Therapy <5164179+yuk7392@users.noreply.github.com> Date: Sun, 1 Nov 2026 14:06:15 +0900 Subject: [PATCH 1/5] [Bugfix][Frontend] Convert Responses content parts to chat parts Role-bearing Responses input items reached the renderers unconverted. The HF path parses both formats, but the Mistral renderer forwards the original messages to mistral-common, which rejects input_text and input_image. Convert input_text, output_text and input_image to chat parts when building the chat messages. Other parts and input_image parts without a URL stay as they are, so unsupported input keeps failing as before. Signed-off-by: Therapy <5164179+yuk7392@users.noreply.github.com> Co-authored-by: Claude --- .../openai/responses/test_responses_utils.py | 136 ++++++++++++++++++ .../scale_out/render/test_render.py | 77 ++++++++++ vllm/entrypoints/openai/responses/utils.py | 22 ++- 3 files changed, 234 insertions(+), 1 deletion(-) diff --git a/tests/entrypoints/openai/responses/test_responses_utils.py b/tests/entrypoints/openai/responses/test_responses_utils.py index 12e6c96ecb0a..ffeba066a1d0 100644 --- a/tests/entrypoints/openai/responses/test_responses_utils.py +++ b/tests/entrypoints/openai/responses/test_responses_utils.py @@ -4,6 +4,7 @@ from unittest.mock import patch import pytest +from mistral_common.protocol.instruct.request import ChatCompletionRequest from openai.types.responses import CustomTool, FunctionTool, ResponseCustomToolCall from openai.types.responses.response_function_tool_call import ResponseFunctionToolCall from openai.types.responses.response_function_tool_call_output_item import ( @@ -927,6 +928,141 @@ def test_merge_chain_breaks(self, items, num_expected_messages): assert len(messages) == num_expected_messages +class TestConstructInputMessagesContentParts: + """Renderers such as Mistral's forward messages to strict chat-only validators, + so Responses content parts must already be chat parts.""" + + IMAGE_URL = "https://example.com/cat.png" + + @staticmethod + def _convert(content): + messages = construct_input_messages( + request_input=[{"role": "user", "content": content}] + ) + assert len(messages) == 1 + assert messages[0]["role"] == "user" + return messages[0]["content"] + + @pytest.mark.parametrize("part_type", ["input_text", "output_text"]) + def test_text_parts_become_chat_text(self, part_type): + assert self._convert([{"type": part_type, "text": "hello"}]) == [ + {"type": "text", "text": "hello"} + ] + + @pytest.mark.parametrize("detail", ["auto", "low", "high"]) + def test_input_image_becomes_chat_image_url_with_detail(self, detail): + part = {"type": "input_image", "image_url": self.IMAGE_URL, "detail": detail} + assert self._convert([part]) == [ + { + "type": "image_url", + "image_url": {"url": self.IMAGE_URL, "detail": detail}, + } + ] + + def test_input_image_drops_detail_chat_parts_cannot_carry(self): + part = { + "type": "input_image", + "image_url": self.IMAGE_URL, + "detail": "original", + } + assert self._convert([part]) == [ + {"type": "image_url", "image_url": {"url": self.IMAGE_URL}} + ] + + def test_converted_parts_pass_mistral_common_validation(self): + content = self._convert( + [ + {"type": "input_text", "text": "Describe this."}, + {"type": "input_image", "image_url": self.IMAGE_URL, "detail": "low"}, + ] + ) + + request = ChatCompletionRequest.from_openai( + messages=[{"role": "user", "content": content}] + ) + + text_chunk, image_chunk = request.messages[0].content + assert text_chunk.text == "Describe this." + assert image_chunk.image_url.url == self.IMAGE_URL + assert image_chunk.image_url.detail == "low" + + def test_extra_part_fields_survive_conversion(self): + cache_control = {"type": "ephemeral"} + converted = self._convert( + [ + {"type": "input_text", "text": "hi", "cache_control": cache_control}, + { + "type": "input_image", + "image_url": self.IMAGE_URL, + "detail": "auto", + "file_id": None, + "uuid": "cat", + }, + ] + ) + assert converted == [ + {"type": "text", "text": "hi", "cache_control": cache_control}, + { + "type": "image_url", + "image_url": {"url": self.IMAGE_URL, "detail": "auto"}, + "uuid": "cat", + }, + ] + + @pytest.mark.parametrize( + "part", + [ + pytest.param( + {"type": "input_image", "detail": "auto", "file_id": "file_1"}, + id="file_id_only_image", + ), + pytest.param( + {"type": "input_image", "detail": "auto", "image_url": None}, + id="null_image_url", + ), + pytest.param({"type": "input_file", "file_id": "file_1"}, id="input_file"), + pytest.param({"type": "text", "text": "hello"}, id="chat_text"), + pytest.param( + {"type": "image_url", "image_url": {"url": IMAGE_URL}}, + id="chat_image_url", + ), + ], + ) + def test_other_parts_are_preserved(self, part): + assert self._convert([part]) == [part] + + def test_string_content_is_preserved(self): + assert self._convert("hello") == "hello" + + def test_part_order_is_preserved(self): + converted = self._convert( + [ + {"type": "input_text", "text": "before"}, + {"type": "input_image", "image_url": self.IMAGE_URL, "detail": "auto"}, + {"type": "input_file", "file_id": "file_1"}, + {"type": "input_text", "text": "after"}, + ] + ) + assert [part["type"] for part in converted] == [ + "text", + "image_url", + "input_file", + "text", + ] + assert converted[0]["text"] == "before" + assert converted[3]["text"] == "after" + + def test_request_item_is_not_mutated(self): + item = {"role": "user", "content": [{"type": "input_text", "text": "hello"}]} + + construct_input_messages(request_input=[item]) + + assert item == { + "role": "user", + "content": [{"type": "input_text", "text": "hello"}], + } + + class TestConstructInputMessagesInstructionsLeak: """Regression tests for #37697: instructions from a prior response should NOT leak through previous_response_id.""" diff --git a/tests/entrypoints/scale_out/render/test_render.py b/tests/entrypoints/scale_out/render/test_render.py index 862a89dc8e46..c74712bd65aa 100644 --- a/tests/entrypoints/scale_out/render/test_render.py +++ b/tests/entrypoints/scale_out/render/test_render.py @@ -40,6 +40,7 @@ MODEL_NAME = "hmellor/tiny-random-LlamaForCausalLM" GPT_OSS_MODEL_NAME = "openai/gpt-oss-20b" +MISTRAL_MODEL_NAME = "mistralai/Magistral-Small-2509" @pytest.mark.parametrize("multiple", [False, True]) @@ -454,6 +455,33 @@ async def test_responses_render_basic(client): assert data["token_ids"] +@pytest.mark.asyncio +async def test_responses_render_input_text_matches_chat_text_part(client): + text = "Which color should I remember?" + responses_render = await client.post( + "/v1/responses/render", + json={ + "model": MODEL_NAME, + "input": [ + {"role": "user", "content": [{"type": "input_text", "text": text}]} + ], + }, + ) + # The Responses route rejects "text" parts and always adds special tokens. + chat_render = await client.post( + "/v1/chat/completions/render", + json={ + "model": MODEL_NAME, + "messages": [{"role": "user", "content": [{"type": "text", "text": text}]}], + "add_special_tokens": True, + }, + ) + + assert responses_render.status_code == 200 + assert chat_render.status_code == 200 + assert responses_render.json()["token_ids"] == chat_render.json()["token_ids"] + + @pytest.mark.asyncio async def test_responses_render_includes_prior_input_items(client): current_turn = { @@ -1081,3 +1109,52 @@ async def test_tokenize_matches_chat_render_for_gpt_oss(gpt_oss_server): assert render.status_code == tokenize.status_code == 200 assert tokenize.json()["tokens"] == render.json()["token_ids"] + + +@pytest.fixture(scope="module") +def mistral_server(): + args = ["--tokenizer-mode", "mistral"] + with RemoteLaunchRenderServer(MISTRAL_MODEL_NAME, args) as remote_server: + yield remote_server + + +@pytest.mark.asyncio +async def test_responses_render_content_parts_match_strings_on_mistral(mistral_server): + """Mistral tokenizers only accept chat parts, so Responses parts must convert.""" + system = "Answer in one word." + question = "What is the capital of France?" + answer = "Paris." + follow_up = "And of Italy?" + string_input = [ + {"role": "system", "content": system}, + {"role": "user", "content": question}, + {"role": "assistant", "content": answer}, + {"role": "user", "content": follow_up}, + ] + parts_input = [ + {"role": "system", "content": [{"type": "input_text", "text": system}]}, + {"role": "user", "content": [{"type": "input_text", "text": question}]}, + { + "type": "message", + "id": "msg_1", + "role": "assistant", + "status": "completed", + "content": [{"type": "output_text", "text": answer, "annotations": []}], + }, + {"role": "user", "content": [{"type": "input_text", "text": follow_up}]}, + ] + async with httpx.AsyncClient( + base_url=mistral_server.url_for(""), timeout=30.0 + ) as client: + string_render = await client.post( + "/v1/responses/render", + json={"model": MISTRAL_MODEL_NAME, "input": string_input}, + ) + parts_render = await client.post( + "/v1/responses/render", + json={"model": MISTRAL_MODEL_NAME, "input": parts_input}, + ) + + assert string_render.status_code == 200 + assert parts_render.status_code == 200, parts_render.text + assert parts_render.json()["token_ids"] == string_render.json()["token_ids"] diff --git a/vllm/entrypoints/openai/responses/utils.py b/vllm/entrypoints/openai/responses/utils.py index 69ff81cd483a..1f1af1aae737 100644 --- a/vllm/entrypoints/openai/responses/utils.py +++ b/vllm/entrypoints/openai/responses/utils.py @@ -368,6 +368,20 @@ def construct_chat_messages_with_tool_call( return messages +def _to_chat_content_part(part: dict[str, Any]) -> dict[str, Any]: + part_type = part.get("type") + if part_type in ("input_text", "output_text"): + return {**part, "type": "text"} + if part_type == "input_image" and isinstance(url := part.get("image_url"), str): + image_url = {"url": url} + # Chat image parts reject the Responses-only "original" detail. + if (detail := part.get("detail")) in ("auto", "low", "high"): + image_url["detail"] = detail + extra_fields = {k: v for k, v in part.items() if k not in ("detail", "file_id")} + return {**extra_fields, "type": "image_url", "image_url": image_url} + return part + + def _construct_message_from_response_item( item: ResponseInputOutputItem, prev_msg: ChatCompletionMessageParam | None = None, @@ -494,7 +508,13 @@ def _construct_message_from_response_item( return None return {"role": "assistant", "content": text} if isinstance(item, dict) and "role" in item: - return item # type: ignore[return-value] + content = item.get("content") + if not isinstance(content, list): + return item # type: ignore[return-value] + return { # type: ignore[return-value] + **item, + "content": [_to_chat_content_part(part) for part in content], + } item_type = item.get("type") if isinstance(item, dict) else item.type raise VLLMValidationError( f"Unsupported input item type: {item_type}", From 83db89356beed5dc73d514acb1b8d6c13312182d Mon Sep 17 00:00:00 2001 From: Therapy <5164179+yuk7392@users.noreply.github.com> Date: Sun, 1 Nov 2026 15:56:09 +0900 Subject: [PATCH 2/5] [Bugfix][Frontend] Convert Responses tool output parts to chat parts List output on function_call_output and custom_tool_call_output reached the renderers unconverted, so Mistral rejected input_text with a 400. Two more shapes failed differently. Custom tool output is typed Iterable, so a list arrives as a one-shot iterator: Mistral rendered an empty tool result with a 200. An item validated into ResponseFunctionToolCallOutputItem kept SDK objects as parts and returned a 500 on every renderer. Convert any non-string output with the rule role content already uses, and remove the ResponseFunctionToolCallOutputItem branch, since the generic branch dumps SDK items to dicts. Keep file_id on converted image parts: mistral-common ignores it and it is an extra field like the others. Remove three tests that add nothing beyond the conversion table tests. Signed-off-by: Therapy <5164179+yuk7392@users.noreply.github.com> Co-authored-by: Claude --- .../openai/responses/test_responses_utils.py | 86 ++++++++++++------- .../scale_out/render/test_render.py | 60 +++++++++++++ vllm/entrypoints/openai/responses/utils.py | 17 ++-- 3 files changed, 119 insertions(+), 44 deletions(-) diff --git a/tests/entrypoints/openai/responses/test_responses_utils.py b/tests/entrypoints/openai/responses/test_responses_utils.py index ffeba066a1d0..71ecdd62f95d 100644 --- a/tests/entrypoints/openai/responses/test_responses_utils.py +++ b/tests/entrypoints/openai/responses/test_responses_utils.py @@ -19,6 +19,7 @@ ) from vllm.entrypoints.generate.base.protocol import FunctionCall +from vllm.entrypoints.openai.responses.protocol import ResponsesRequest from vllm.entrypoints.openai.responses.utils import ( _construct_message_from_response_item, build_response_output_items, @@ -973,7 +974,12 @@ def test_converted_parts_pass_mistral_common_validation(self): content = self._convert( [ {"type": "input_text", "text": "Describe this."}, - {"type": "input_image", "image_url": self.IMAGE_URL, "detail": "low"}, + { + "type": "input_image", + "image_url": self.IMAGE_URL, + "detail": "low", + "file_id": "file_1", + }, ] ) @@ -986,6 +992,50 @@ def test_converted_parts_pass_mistral_common_validation(self): assert image_chunk.image_url.url == self.IMAGE_URL assert image_chunk.image_url.detail == "low" + @pytest.mark.parametrize( + "item", + [ + pytest.param({"type": "function_call_output"}, id="function"), + pytest.param( + { + "type": "function_call_output", + "id": "fco_1", + "status": "completed", + "created_by": "resp_1", + }, + id="function_output_item", + ), + pytest.param({"type": "custom_tool_call_output"}, id="custom"), + pytest.param( + { + "type": "custom_tool_call_output", + "id": "ctco_1", + "status": "completed", + }, + id="custom_output_item", + ), + ], + ) + def test_tool_output_parts_become_chat_parts(self, item): + request = ResponsesRequest( + model="test", + input=[ + { + **item, + "call_id": "call_1", + "output": [{"type": "input_text", "text": "22C"}], + } + ], + ) + + assert construct_input_messages(request_input=request.input) == [ + { + "role": "tool", + "content": [{"type": "text", "text": "22C"}], + "tool_call_id": "call_1", + } + ] + def test_extra_part_fields_survive_conversion(self): cache_control = {"type": "ephemeral"} converted = self._convert( @@ -995,7 +1045,7 @@ def test_extra_part_fields_survive_conversion(self): "type": "input_image", "image_url": self.IMAGE_URL, "detail": "auto", - "file_id": None, + "file_id": "file_1", "uuid": "cat", }, ] @@ -1005,6 +1055,7 @@ def test_extra_part_fields_survive_conversion(self): { "type": "image_url", "image_url": {"url": self.IMAGE_URL, "detail": "auto"}, + "file_id": "file_1", "uuid": "cat", }, ] @@ -1031,37 +1082,6 @@ def test_extra_part_fields_survive_conversion(self): def test_other_parts_are_preserved(self, part): assert self._convert([part]) == [part] - def test_string_content_is_preserved(self): - assert self._convert("hello") == "hello" - - def test_part_order_is_preserved(self): - converted = self._convert( - [ - {"type": "input_text", "text": "before"}, - {"type": "input_image", "image_url": self.IMAGE_URL, "detail": "auto"}, - {"type": "input_file", "file_id": "file_1"}, - {"type": "input_text", "text": "after"}, - ] - ) - assert [part["type"] for part in converted] == [ - "text", - "image_url", - "input_file", - "text", - ] - assert converted[0]["text"] == "before" - assert converted[3]["text"] == "after" - - def test_request_item_is_not_mutated(self): - item = {"role": "user", "content": [{"type": "input_text", "text": "hello"}]} - - construct_input_messages(request_input=[item]) - - assert item == { - "role": "user", - "content": [{"type": "input_text", "text": "hello"}], - } - class TestConstructInputMessagesInstructionsLeak: """Regression tests for #37697: instructions from a prior response diff --git a/tests/entrypoints/scale_out/render/test_render.py b/tests/entrypoints/scale_out/render/test_render.py index c74712bd65aa..6b2b96b197e3 100644 --- a/tests/entrypoints/scale_out/render/test_render.py +++ b/tests/entrypoints/scale_out/render/test_render.py @@ -1158,3 +1158,63 @@ async def test_responses_render_content_parts_match_strings_on_mistral(mistral_s assert string_render.status_code == 200 assert parts_render.status_code == 200, parts_render.text assert parts_render.json()["token_ids"] == string_render.json()["token_ids"] + + +@pytest.mark.asyncio +@pytest.mark.parametrize( + ("call", "output_item"), + [ + pytest.param( + {"type": "function_call", "name": "get_weather", "arguments": "{}"}, + {"type": "function_call_output"}, + id="function", + ), + pytest.param( + {"type": "function_call", "name": "get_weather", "arguments": "{}"}, + { + "type": "function_call_output", + "id": "fco_1", + "status": "completed", + "created_by": "resp_1", + }, + id="function_output_item", + ), + pytest.param( + {"type": "custom_tool_call", "name": "run", "input": "date"}, + {"type": "custom_tool_call_output"}, + id="custom", + ), + pytest.param( + {"type": "custom_tool_call", "name": "run", "input": "date"}, + {"type": "custom_tool_call_output", "id": "ctco_1", "status": "completed"}, + id="custom_output_item", + ), + ], +) +async def test_responses_render_tool_output_parts_match_strings_on_mistral( + mistral_server, call, output_item +): + def render_body(output): + return { + "model": MISTRAL_MODEL_NAME, + "input": [ + {"role": "user", "content": "What is the weather in Paris?"}, + {**call, "call_id": "abcdef123"}, + {**output_item, "call_id": "abcdef123", "output": output}, + ], + } + + async with httpx.AsyncClient( + base_url=mistral_server.url_for(""), timeout=30.0 + ) as client: + string_render = await client.post( + "/v1/responses/render", json=render_body("22C") + ) + parts_render = await client.post( + "/v1/responses/render", + json=render_body([{"type": "input_text", "text": "22C"}]), + ) + + assert string_render.status_code == 200 + assert parts_render.status_code == 200, parts_render.text + assert parts_render.json()["token_ids"] == string_render.json()["token_ids"] diff --git a/vllm/entrypoints/openai/responses/utils.py b/vllm/entrypoints/openai/responses/utils.py index 1f1af1aae737..2192c54d0d76 100644 --- a/vllm/entrypoints/openai/responses/utils.py +++ b/vllm/entrypoints/openai/responses/utils.py @@ -23,9 +23,6 @@ ResponseReasoningItem, ) from openai.types.responses.response import ToolChoice -from openai.types.responses.response_function_tool_call_output_item import ( - ResponseFunctionToolCallOutputItem, -) from openai.types.responses.response_output_text import Logprob from openai.types.responses.response_reasoning_item import ( Content as ResponseReasoningTextContent, @@ -377,7 +374,7 @@ def _to_chat_content_part(part: dict[str, Any]) -> dict[str, Any]: # Chat image parts reject the Responses-only "original" detail. if (detail := part.get("detail")) in ("auto", "low", "high"): image_url["detail"] = detail - extra_fields = {k: v for k, v in part.items() if k not in ("detail", "file_id")} + extra_fields = {k: v for k, v in part.items() if k != "detail"} return {**extra_fields, "type": "image_url", "image_url": image_url} return part @@ -480,17 +477,15 @@ def _construct_message_from_response_item( "role": "assistant", "content": output_text, } - elif isinstance(item, ResponseFunctionToolCallOutputItem): - return ChatCompletionToolMessageParam( - role="tool", - content=item.output, - tool_call_id=item.call_id, - ) elif _item_type(item) in ("function_call_output", "custom_tool_call_output"): output = _item_dict(item) + content = output.get("output") + # Custom tool output is typed Iterable, so it arrives as a one-shot iterator. + if content is not None and not isinstance(content, str): + content = [_to_chat_content_part(part) for part in content] return ChatCompletionToolMessageParam( role="tool", - content=output.get("output"), + content=content, tool_call_id=output.get("call_id"), ) elif isinstance(item, dict) and item.get("role") == "assistant": From ae0a9ced3661705c4ba6f82b1b1aa3713df5c5cd Mon Sep 17 00:00:00 2001 From: Therapy <5164179+yuk7392@users.noreply.github.com> Date: Mon, 2 Nov 2026 08:54:53 +0000 Subject: [PATCH 3/5] [Bugfix][Frontend] Drop None fields when dumping Responses SDK items _item_dict used a plain model_dump, so tool output items validated into SDK objects leaked every None-valued field into the converted chat parts, such as file_id on image parts and prompt_cache_breakpoint on text parts with newer openai releases. Dict input never carried these keys, so the same request produced different parts depending on its shape. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01HUQzthypoXkipm4h3tTTS4 Signed-off-by: Therapy <5164179+yuk7392@users.noreply.github.com> --- vllm/entrypoints/openai/responses/utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vllm/entrypoints/openai/responses/utils.py b/vllm/entrypoints/openai/responses/utils.py index 76159af20f0b..f0d816e73057 100644 --- a/vllm/entrypoints/openai/responses/utils.py +++ b/vllm/entrypoints/openai/responses/utils.py @@ -139,7 +139,7 @@ def _item_type(item: ResponseInputOutputItem) -> str | None: def _item_dict(item: ResponseInputOutputItem) -> dict[str, Any]: - return item if isinstance(item, dict) else item.model_dump() + return item if isinstance(item, dict) else item.model_dump(exclude_none=True) def response_item_status( From 19bdb0c12675d33b190f8267578d8ca97c5d30f2 Mon Sep 17 00:00:00 2001 From: Felix Marty Date: Fri, 13 Nov 2026 14:54:46 +0000 Subject: [PATCH 4/5] Empty commit: check maintainer push access Signed-off-by: Felix Marty From 4e2675a94b2a51c0985edc50824d39747fd23c41 Mon Sep 17 00:00:00 2001 From: Felix Marty Date: Fri, 13 Nov 2026 15:17:06 +0000 Subject: [PATCH 5/5] [Bugfix][Frontend] Drop the type: ignore and document _to_chat_content_part The role-bearing message returns type-check without a suppression (isinstance(item, dict) narrows to a compatible dict type), so the type: ignore[return-value] is removed. Add a one-line docstring to _to_chat_content_part. Signed-off-by: Felix Marty --- vllm/entrypoints/openai/responses/utils.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/vllm/entrypoints/openai/responses/utils.py b/vllm/entrypoints/openai/responses/utils.py index f0d816e73057..5a47e23291f5 100644 --- a/vllm/entrypoints/openai/responses/utils.py +++ b/vllm/entrypoints/openai/responses/utils.py @@ -366,6 +366,7 @@ def construct_chat_messages_with_tool_call( def _to_chat_content_part(part: dict[str, Any]) -> dict[str, Any]: + """Convert a Responses content part to its chat completions equivalent.""" part_type = part.get("type") if part_type in ("input_text", "output_text"): return {**part, "type": "text"} @@ -545,11 +546,8 @@ def _construct_message_from_response_item( if isinstance(item, dict) and "role" in item: content = item.get("content") if not isinstance(content, list): - return item # type: ignore[return-value] - return { # type: ignore[return-value] - **item, - "content": [_to_chat_content_part(part) for part in content], - } + return item + return {**item, "content": [_to_chat_content_part(part) for part in content]} item_type = item.get("type") if isinstance(item, dict) else item.type raise VLLMValidationError( f"Unsupported input item type: {item_type}",