Skip to content

Comments

fix: UnboundLocalError for role in streaming audio/image responses#784

Merged
david6666666 merged 3 commits intovllm-project:mainfrom
PierreLeGuen:fix/streaming-role-unbound-error
Jan 30, 2026
Merged

fix: UnboundLocalError for role in streaming audio/image responses#784
david6666666 merged 3 commits intovllm-project:mainfrom
PierreLeGuen:fix/streaming-role-unbound-error

Conversation

@PierreLeGuen
Copy link
Contributor

Summary

Fixes an UnboundLocalError when streaming audio or image responses. The role variable 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 role is assigned only when final_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

curl -s http://localhost:8000/v1/chat/completions \
  -H "Content-Type: application/json" \
  -d '{"model": "Qwen/Qwen3-Omni-30B-A3B-Instruct", "messages": [{"role": "user", "content": "Say hello"}], "modalities": ["audio"], "stream": true}'

@PierreLeGuen PierreLeGuen force-pushed the fix/streaming-role-unbound-error branch from 3a7e290 to 6917265 Compare January 14, 2026 16:04
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]>
@PierreLeGuen PierreLeGuen force-pushed the fix/streaming-role-unbound-error branch from 6917265 to e5c8de3 Compare January 14, 2026 16:09
@hsliuustc0106
Copy link
Collaborator

@GG-li PTAL

@PierreLeGuen PierreLeGuen force-pushed the fix/streaming-role-unbound-error branch 2 times, most recently from 7fb8045 to 5efca07 Compare January 15, 2026 11:14
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]>
@PierreLeGuen PierreLeGuen force-pushed the fix/streaming-role-unbound-error branch from 5efca07 to 0d80d17 Compare January 15, 2026 11:16
@hsliuustc0106
Copy link
Collaborator

@yenuo26 PTAL

@yenuo26
Copy link
Contributor

yenuo26 commented Jan 30, 2026

I have verified that after adding this modification, #932 can be fixed.

@david6666666
Copy link
Collaborator

LGTM

@david6666666 david6666666 merged commit 2c294a7 into vllm-project:main Jan 30, 2026
7 checks passed
dongbo910220 pushed a commit to dongbo910220/vllm-omni that referenced this pull request Feb 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready label to trigger buildkite CI

Projects

None yet

4 participants