From c0302d949740321c145b6b19852706b6f1b43854 Mon Sep 17 00:00:00 2001 From: Mahad Rehman <114791389+mahadrehmann@users.noreply.github.com> Date: Wed, 15 Jul 2026 15:01:17 +0500 Subject: [PATCH] [Bugfix] Fix parallel_tool_calls=null crash in Responses API from_request() (#48098) Signed-off-by: mahadrehmann Signed-off-by: Mahad Rehman <114791389+mahadrehmann@users.noreply.github.com> Co-authored-by: muhammadfawaz1 <135441198+professorsab@users.noreply.github.com> Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> Co-authored-by: Chauncey --- .../test_responses_request_validations.py | 44 ++++++++++++++++++- vllm/entrypoints/openai/responses/protocol.py | 4 +- 2 files changed, 46 insertions(+), 2 deletions(-) diff --git a/tests/tool_use/test_responses_request_validations.py b/tests/tool_use/test_responses_request_validations.py index 63a1828c50..59b156b76a 100644 --- a/tests/tool_use/test_responses_request_validations.py +++ b/tests/tool_use/test_responses_request_validations.py @@ -4,7 +4,10 @@ import pytest from pydantic import ValidationError -from vllm.entrypoints.openai.responses.protocol import ResponsesRequest +from vllm.entrypoints.openai.responses.protocol import ( + ResponsesRequest, + ResponsesResponse, +) SAMPLE_TOOL = { "type": "function", @@ -182,3 +185,42 @@ def test_responses_request_empty_tools_named_tool_choice(): "tool_choice": NAMED_TOOL_CHOICE, } ) + + +# Regression tests for parallel_tool_calls=null crash in Responses API +# (from_request() passed None to ResponsesResponse.parallel_tool_calls, +# a non-optional bool field, causing a Pydantic ValidationError during +# response construction) +@pytest.mark.parametrize( + "value,expected", + [ + (True, True), + (False, False), + (None, True), # null must resolve to the documented default (true) + ], +) +def test_responses_response_parallel_tool_calls_null_resolves_to_default( + value, expected +): + request = ResponsesRequest.model_validate( + {"input": "Hello", "model": "test-model", "parallel_tool_calls": value} + ) + sampling_params = request.to_sampling_params(default_max_tokens=16) + r = ResponsesResponse.from_request( + request=request, + sampling_params=sampling_params, + model_name="test-model", + created_time=0, + output=[], + status="completed", + usage=None, + ) + assert r.parallel_tool_calls == expected + + +def test_responses_request_parallel_tool_calls_null_accepted(): + """Client sending null must be accepted at request validation time.""" + req = ResponsesRequest.model_validate( + {"input": "Hello", "model": "test-model", "parallel_tool_calls": None} + ) + assert req.parallel_tool_calls is None diff --git a/vllm/entrypoints/openai/responses/protocol.py b/vllm/entrypoints/openai/responses/protocol.py index fabc79677c..d4708a5fb3 100644 --- a/vllm/entrypoints/openai/responses/protocol.py +++ b/vllm/entrypoints/openai/responses/protocol.py @@ -749,7 +749,9 @@ class ResponsesResponse(OpenAIBaseModel): output=output, input_messages=input_messages, output_messages=output_messages, - parallel_tool_calls=request.parallel_tool_calls, + parallel_tool_calls=request.parallel_tool_calls + if request.parallel_tool_calls is not None + else ResponsesRequest.model_fields["parallel_tool_calls"].default, temperature=sampling_params.temperature, tool_choice=request.tool_choice, tools=request.tools,