Skip to content

Bug: Dead code - sse.event == "error" check is unreachable in _streaming.py #2796

Closed as not planned

Description

@joyceleeor

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.

Reference: https://github.com/openai/openai-python/blob/main/src/openai/_streaming.py#L169-L181

To Reproduce

  1. Open src/openai/_streaming.py
  2. Go to line 167-181
  3. Observe that sse.event == "error" is inside if sse.event.startswith("thread.") block
  4. This condition is logically impossible to satisfy

Code snippets

# Line 167-168: outer condition
if sse.event and sse.event.startswith("thread."):
    data = sse.json()

    # Line 170: inner condition - ALWAYS False
    # "error" does not start with "thread.", so this is unreachable
    if sse.event == "error" and is_mapping(data) and data.get("error"):
        raise APIError(...)  # Dead code!

OS

Windows

Python version

Python v3.11.4

Library version

openai v2.11.0

Activity

  1. added a commit that references this issue on Dec 25, 2025
    b6f7aef
  2. added 2 commits that reference this issue on Dec 28, 2025
    f0ea16b
    9e4c5c8
  3. added a commit that references this issue on Feb 7, 2026
    25e8830
  4. nightcityblade commented on Jul 1, 2026

    @nightcityblade
    Contributor

    Hi, I'd like to work on this. I'll submit a PR shortly.

  5. LOGO127 commented on Sep 3, 2026

    @LOGO127

    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.

  6. LOGO127 commented on Sep 3, 2026

    @LOGO127

    @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.

  7. marcuswood-oai commented on Sep 14, 2026

    @marcuswood-oai
    Contributor

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions