You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Bug: Dead code - sse.event == "error" check is unreachable in _streaming.py #2796
Confirm this is an issue with the Python library and not an underlying OpenAI API
This is an issue with the Python library
Describe the bug
In src/openai/_streaming.py lines 169-181, there's unreachable dead code.
The outer condition requires sse.event.startswith("thread."), but the inner condition checks sse.event == "error". Since "error" does not start with "thread.", this check can never be true.
This appears to be a regression from commit abc25966 ("fix(streaming): correct indentation"). The original code had the error check in the else branch, but after refactors it was incorrectly moved inside the thread. branch.
Observe that sse.event == "error" is inside if sse.event.startswith("thread.") block
This condition is logically impossible to satisfy
Code snippets
# Line 167-168: outer conditionifsse.eventandsse.event.startswith("thread."):
data=sse.json()
# Line 170: inner condition - ALWAYS False# "error" does not start with "thread.", so this is unreachableifsse.event=="error"andis_mapping(data) anddata.get("error"):
raiseAPIError(...) # Dead code!
I opened #3790 to remove the unreachable sse.event == "error" checks from both Stream and AsyncStream. The existing reachable SSE error handling is unchanged; focused streaming tests and Ruff checks pass.
@nightcityblade, I noticed your July 1 note that you planned to submit a PR. I couldn't find a linked PR, so I opened #3790 as a minimal patch in the meantime. If you're still working on it, please let the maintainers know and I'll defer; otherwise #3790 is ready for review.
Thank you for flagging this and for the cleanup proposals. You’re right that event == "error" is unreachable inside the thread.* branch; the current source still contains it, while ordinary error events use the separate general handler. This is dead-code cleanup in the legacy Assistants path, and the related PRs were closed on that basis.
We’re closing this because the Assistants API was retired on August 26, 2026. For current integrations, please migrate to Responses and Conversations using the migration guide. This closure records that maintenance decision; the dead code has not been removed.
Activity
fix(streaming): move error event handling outside thread.* condition
fix(streaming): move error event check before thread.* handling
Fix unreachable dead code in error event handling
refactor: fix unreachable error handling code in streaming
Improve streaming error handling and robustness
nightcityblade commentedon Jul 1, 2026
Hi, I'd like to work on this. I'll submit a PR shortly.
LOGO127 commentedon Sep 3, 2026
I opened #3790 to remove the unreachable
sse.event == "error"checks from bothStreamandAsyncStream. The existing reachable SSE error handling is unchanged; focused streaming tests and Ruff checks pass.LOGO127 commentedon Sep 3, 2026
@nightcityblade, I noticed your July 1 note that you planned to submit a PR. I couldn't find a linked PR, so I opened #3790 as a minimal patch in the meantime. If you're still working on it, please let the maintainers know and I'll defer; otherwise #3790 is ready for review.
marcuswood-oai commentedon Sep 14, 2026
Thank you for flagging this and for the cleanup proposals. You’re right that
event == "error"is unreachable inside thethread.*branch; the current source still contains it, while ordinary error events use the separate general handler. This is dead-code cleanup in the legacy Assistants path, and the related PRs were closed on that basis.We’re closing this because the Assistants API was retired on August 26, 2026. For current integrations, please migrate to Responses and Conversations using the migration guide. This closure records that maintenance decision; the dead code has not been removed.