fix(openai): preserve async parsing for streaming responses#607
Merged
Abhijeet Prasad (AbhiPrasad) merged 3 commits intoJul 21, 2026
Merged
Conversation
Abhijeet Prasad (AbhiPrasad)
marked this pull request as ready for review
July 21, 2026 17:41
Await async raw-response parsing before wrapping chat streams, and preserve the awaitable parse contract on the traced proxy. Reuse cassette-backed chat and Responses tests to cover real streaming behavior without mocks.
Abhijeet Prasad (AbhiPrasad)
approved these changes
Jul 21, 2026
Abhijeet Prasad (AbhiPrasad)
enabled auto-merge (squash)
July 21, 2026 17:55
Abhijeet Prasad (AbhiPrasad)
deleted the
codex/openai-agents-streaming-response
branch
July 21, 2026 18:03
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.
resolves https://linear.app/braintrustdata/issue/SDK-86/async-streaming-response-parsing-not-preserved
Summary
parse()contract exposed bywith_streaming_responseRoot cause
openai.AsyncAPIResponse.parse()is asynchronous, but the tracing proxy replaced it with a synchronous method that returned the traced stream directly. The wrappers also attempted to instrument the un-awaited parser coroutine rather than the parsed iterator.This broke callers such as OpenAI Agents that enter
with_streaming_responseand then callawait api_response.parse(). Chat Completions had the same issue on its async raw streaming path.The wrappers now detect and await asynchronous parsing before constructing the traced iterator, remember the original parse contract, and expose an awaitable
parse()on the raw-response proxy. Synchronous raw-response behavior remains unchanged.Validation
parse()was not awaitable and the underlying parser coroutine was never awaitedtest_openai(latest)session with cassette playback: 70 tests passed, plus attachment and OpenRouter gateway suites