Skip to content

Improve streaming error handling - #2875

Closed
mrutunjay-kinagi wants to merge 3 commits into
openai:mainfrom
mrutunjay-kinagi:fix-responses-streaming-errors
Closed

mrutunjay-kinagi wants to merge 3 commits into
openai:mainfrom
mrutunjay-kinagi:fix-responses-streaming-errors

Conversation

@mrutunjay-kinagi

@mrutunjay-kinagi mrutunjay-kinagi commented Feb 18, 2026

Copy link
Copy Markdown

Summary

Testing

  • not run (not requested)

Closes #2853, #2796, #2868, #2761, #2776

@mrutunjay-kinagi
mrutunjay-kinagi requested a review from a team as a code owner February 18, 2026 14:56
@mrutunjay-kinagi

Copy link
Copy Markdown
Author

@marcuswood-oai Is this still relevant ?

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: df0a203dbc

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/openai/_streaming.py Outdated
Remove legacy duplicate error-checking code that was causing each non-thread
SSE event to be yielded twice. The refactored _raise_streaming_error() helper
now handles all error checking in a single pass, and we preserve the
synthesize_event_and_data wrapping behavior for the else branch.

Fixes issue where consumers received duplicate chunks, which could duplicate
streamed text, tool-call deltas, and state-machine events. Applies the same
fix to both sync (Stream) and async (AsyncStream) implementations.

Addresses Codex review feedback on PR openai#2875.

Copy link
Copy Markdown
Contributor

Yes—thanks for checking back, and for fixing the duplicate-yield issue from the review!

I checked current main and tested 3ac0c06. The AsyncStream.aclose() alias is still useful: contextlib.aclosing(stream) raises AttributeError on main and correctly closes the response with this patch. Keeping the existing async close() method makes that addition backward-compatible.

I'd focus this PR on the alias (#2853) and removing the unreachable checks (#2796). Main already raises APIError for nested {"error": ...} payloads in the non-thread branch, including event: error; the dead branch doesn't currently prevent that. We can remove the unreachable blocks while preserving existing event semantics, without the repeated helper calls. Please update the summary accordingly.

Please add focused regression tests for aclosing/response cleanup, exactly-once delivery, and existing error handling in both sync and async streams, including synthesize_event_and_data. The current 20 streaming tests pass, and my additional probes confirmed the duplicate-yield issue is resolved, but these regressions should be covered in the PR.

The other items are worth tracking separately: the missing ChatModel literal and generated compaction examples need fixes in their source schema/configuration, and a smaller Wikimedia image URL isn't yet a verified fix for the download error. Please leave those changes and their closing references out of this focused streaming patch.

Thanks again for working on this—there is still a useful contribution here.

@mrutunjay-kinagi

mrutunjay-kinagi commented Sep 10, 2026

Copy link
Copy Markdown
Author

Yes—thanks for checking back, and for fixing the duplicate-yield issue from the review!

I checked current main and tested 3ac0c06. The AsyncStream.aclose() alias is still useful: contextlib.aclosing(stream) raises AttributeError on main and correctly closes the response with this patch. Keeping the existing async close() method makes that addition backward-compatible.

I'd focus this PR on the alias (#2853) and removing the unreachable checks (#2796). Main already raises APIError for nested {"error": ...} payloads in the non-thread branch, including event: error; the dead branch doesn't currently prevent that. We can remove the unreachable blocks while preserving existing event semantics, without the repeated helper calls. Please update the summary accordingly.

Please add focused regression tests for aclosing/response cleanup, exactly-once delivery, and existing error handling in both sync and async streams, including synthesize_event_and_data. The current 20 streaming tests pass, and my additional probes confirmed the duplicate-yield issue is resolved, but these regressions should be covered in the PR.

The other items are worth tracking separately: the missing ChatModel literal and generated compaction examples need fixes in their source schema/configuration, and a smaller Wikimedia image URL isn't yet a verified fix for the download error. Please leave those changes and their closing references out of this focused streaming patch.

Thanks again for working on this—there is still a useful contribution here.

@marcuswood-oai

Thank you so much for such quick response. Can you please assign me the relevant issues ? I'll put sometime in getting those resolved.

@marcuswood-oai

marcuswood-oai commented Sep 10, 2026

Copy link
Copy Markdown
Contributor

Thanks for the contribution, and sorry for the delay in getting to this! We’re going with #2854 to address this, so I’m closing this PR.

Posted with Codex.

@mrutunjay-kinagi

Copy link
Copy Markdown
Author

Thanks for the contribution, and sorry for the delay in getting to this! We’re going with #2854 to address this, so I’m closing this PR.

@marcuswood-oai Okay, are there any other issues i can contribute to ?

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

AsyncStream missing aclose() causes AttributeError in streaming structured output

2 participants