fix: UnboundLocalError for role in streaming audio/image responses#784
Merged
david6666666 merged 3 commits intovllm-project:mainfrom Jan 30, 2026
Merged
Conversation
3a7e290 to
6917265
Compare
The role variable was only assigned inside the text-specific condition block, but was used unconditionally by audio and image handlers in the streaming path. Move role assignment outside the text-specific block so it's initialized for all modalities, matching the non-streaming path behavior. Signed-off-by: Pierre Le Guen <[email protected]>
6917265 to
e5c8de3
Compare
Collaborator
|
@GG-li PTAL |
7fb8045 to
5efca07
Compare
Improve code comments based on PR feedback: - Clarify role initialization purpose to prevent UnboundLocalError - Consolidate split comment into single line for better readability Signed-off-by: Pierre Le Guen <[email protected]>
5efca07 to
0d80d17
Compare
1 task
Collaborator
|
@yenuo26 PTAL |
Contributor
|
I have verified that after adding this modification, #932 can be fixed. |
Collaborator
|
LGTM |
david6666666
approved these changes
Jan 30, 2026
dongbo910220
pushed a commit
to dongbo910220/vllm-omni
that referenced
this pull request
Feb 1, 2026
…llm-project#784) Signed-off-by: Pierre Le Guen <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes an
UnboundLocalErrorwhen streaming audio or image responses. Therolevariable was only assigned inside the text-specific condition block, but was used unconditionally by audio and image handlers.Problem
When making a streaming request with
modalities: ["audio"], the server returns:{"error": {"message": "cannot access local variable 'role' where it is not associated with a value", "type": "BadRequestError", "param": null, "code": 400}}This happens because
roleis assigned only whenfinal_output_type == "text"(line 648), but_create_audio_choice()and_create_image_choice()reference it regardless of output type.Fix
Move
role = self.get_chat_request_role(request)outside the text-specific condition block so it's initialized for all modalities, matching the non-streaming path behavior (line 1295).Reproduction