Skip to content

fix: use integer output_index instead of boolean in streaming handler#3119

Closed
kuishou68 wants to merge 2 commits intoopenai:mainfrom
kuishou68:fix/streaming-output-index-bool
Closed

fix: use integer output_index instead of boolean in streaming handler#3119
kuishou68 wants to merge 2 commits intoopenai:mainfrom
kuishou68:fix/streaming-output-index-bool

Conversation

@kuishou68
Copy link
Copy Markdown
Contributor

Problem

The Chat Completions streaming handler uses a boolean expression for :

This produces / instead of integer /. While Python treats bool as int subclass, downstream JSON consumers and event snapshots can observe the wrong type.

Solution

Replace all 8 occurrences with explicit integer expression:

Testing

Verified no remaining boolean expressions for output_index in chatcmpl_stream_handler.py.

Fixes #3109

- Replace boolean expression (state.reasoning_content_index_and_output is not None)
  with explicit integer (1 if ... else 0) for output_index field
- Fixes issue where streamed events could expose boolean True/False instead
  of integer 0/1 for output_index, breaking downstream JSON consumers
- Affects 8 event types: ResponseOutputItemAddedEvent, ResponseContentPartAddedEvent,
  ResponseTextDeltaEvent, ResponseRefusalDeltaEvent

Fixes openai#3109
@github-actions github-actions Bot added bug Something isn't working feature:chat-completions labels May 5, 2026
- Line 422 was missing explicit 'is not None' comparison
- This ensures output_index is always an integer (0 or 1), not a boolean
- Consistent with all other output_index fixes in this PR
@seratch
Copy link
Copy Markdown
Member

seratch commented May 5, 2026

Thanks for your interest here, but we're looking into more comprehensive solutions like #3108

@seratch seratch closed this May 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working feature:chat-completions

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Chat Completions streaming computes assistant output_index with a bool expression

2 participants