fix(streaming): remove unreachable dead code in error handling#2820
Open
skyvanguard wants to merge 1 commit intoopenai:mainfrom
Open
fix(streaming): remove unreachable dead code in error handling#2820skyvanguard wants to merge 1 commit intoopenai:mainfrom
skyvanguard wants to merge 1 commit intoopenai:mainfrom
Conversation
The check `sse.event == "error"` was inside a block that requires
`sse.event.startswith("thread.")`, making it logically impossible
to ever be true (since "error" doesn't start with "thread.").
This was a regression from commit abc2596 where the error check
was incorrectly moved inside the thread event branch.
The fix restructures the code to:
1. Parse JSON data first (common to both branches)
2. Check for errors in the data (common to both branches)
3. Then handle the thread.* event special case for yield
This removes ~28 lines of dead code while preserving all
intended functionality.
Fixes openai#2796
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
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
Removes unreachable dead code in
_streaming.pythat was caused by a logical impossibility in the conditional checks.Fixes #2796
Problem
The check
sse.event == "error"was inside a block that requiressse.event.startswith("thread."):Since
"error"does not start with"thread.", this condition can never be true, making the entire error handling block dead code.Solution
Restructured the code to:
thread.*event special case for the yieldThis removes ~28 lines of dead code while preserving all intended functionality. The error handling now works correctly for all SSE events, not just theoretically for
thread.*events.Changes
src/openai/_streaming.py: Fixed bothStream(sync) andAsyncStream(async) classesTest plan
data.get("error"))thread.*events still get wrapped with{"data": data, "event": sse.event}datadirectly🤖 Generated with Claude Code