Skip to content

[OpenAI] Fix tool_choice=required streaming when output has trailing extra data#31610

Merged
chaunceyjiang merged 2 commits intovllm-project:mainfrom
maylikenoother:tool-call-required-streaming-extra-data-pr2
Jan 8, 2026
Merged

[OpenAI] Fix tool_choice=required streaming when output has trailing extra data#31610
chaunceyjiang merged 2 commits intovllm-project:mainfrom
maylikenoother:tool-call-required-streaming-extra-data-pr2

Conversation

@maylikenoother
Copy link
Copy Markdown
Contributor

@maylikenoother maylikenoother commented Jan 2, 2026

Problem:

When using tool_choice="required", OpenAIServingChat.extract_tool_call_required_streaming parses the partial stream as JSON. If the model emits a valid JSON tool-call array and then continues with trailing tokens (e.g. "\nDONE"), parsing can hit a JSON "Extra data" case and stop/behave incorrectly.

Fix:

  • Parse required-tool streaming output using partial_json_loads(..., Allow.ALL) so we can safely parse the first JSON value while tolerating trailing extra data.
  • Continue to treat incomplete JSON as "not enough tokens yet" (no behavior change there).

Tests:

  • Add regression test: test_streaming_output_valid_with_trailing_extra_data (tests/tool_use/test_tool_choice_required.py)

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request addresses an issue in streaming mode with tool_choice="required" where trailing data after a valid JSON tool call would cause a parsing error. The fix correctly uses a partial JSON parser that tolerates extra data. The changes are logical and a regression test is included. I've provided two suggestions to improve the code: one to make the new test case more robust by adding specific assertions, and another to simplify exception handling by combining redundant except blocks.

Signed-off-by: maylikenoother <ogedengbemary19@gmail.com>
@maylikenoother maylikenoother force-pushed the tool-call-required-streaming-extra-data-pr2 branch from 7a2b04e to 3d83932 Compare January 2, 2026 00:45
Copy link
Copy Markdown
Collaborator

@chaunceyjiang chaunceyjiang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks~

@chaunceyjiang chaunceyjiang added the ready ONLY add when PR is ready to merge/full CI is needed label Jan 4, 2026
@chaunceyjiang chaunceyjiang self-assigned this Jan 4, 2026
@maylikenoother
Copy link
Copy Markdown
Contributor Author

Thanks~

@chaunceyjiang
All the failed checks – are they going to be fixed from your end?

@chaunceyjiang chaunceyjiang merged commit 7645bc5 into vllm-project:main Jan 8, 2026
47 of 48 checks passed
yugong333 pushed a commit to yugong333/vllm that referenced this pull request Jan 9, 2026
…extra data (vllm-project#31610)

Signed-off-by: maylikenoother <ogedengbemary19@gmail.com>
Co-authored-by: Chauncey <chaunceyjiang@gmail.com>
akh64bit pushed a commit to akh64bit/vllm that referenced this pull request Jan 16, 2026
…extra data (vllm-project#31610)

Signed-off-by: maylikenoother <ogedengbemary19@gmail.com>
Co-authored-by: Chauncey <chaunceyjiang@gmail.com>
dsuhinin pushed a commit to dsuhinin/vllm that referenced this pull request Jan 21, 2026
…extra data (vllm-project#31610)

Signed-off-by: maylikenoother <ogedengbemary19@gmail.com>
Co-authored-by: Chauncey <chaunceyjiang@gmail.com>
Signed-off-by: dsuhinin <suhinin.dmitriy@gmail.com>
ItzDEXX pushed a commit to ItzDEXX/vllm that referenced this pull request Feb 19, 2026
…extra data (vllm-project#31610)

Signed-off-by: maylikenoother <ogedengbemary19@gmail.com>
Co-authored-by: Chauncey <chaunceyjiang@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

frontend ready ONLY add when PR is ready to merge/full CI is needed tool-calling

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants