test(openai): drain completion raw_response streams to fix cassette leak#19019
Merged
Conversation
test_completion_raw_response_stream and test_acompletion_raw_response_stream open completion_streamed.yaml with stream=True but never consume the response, leaving the VCR cassette connection unreleased. Under pytest-randomly orderings this bleeds into later tests and raises CannotOverwriteExistingCassetteException, matching the same leak pattern fixed for the chat_completion variants in #18778. Claude session: 46d356c1-1ac1-4826-b78b-ea87f4220dda Resume: claude --resume 46d356c1-1ac1-4826-b78b-ea87f4220dda Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Circular import analysis
|
Codeowners resolved as |
sabrenner
approved these changes
Jul 20, 2026
Kyle-Verhoog
enabled auto-merge (squash)
July 21, 2026 13:48
Kyle-Verhoog
disabled auto-merge
July 21, 2026 13:51
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.
What
The same VCR cassette-leak pattern fixed in #18778 for the
chat_completionraw-response streaming tests also exists two tests earlier for the plaincompletionvariants:test_completion_raw_response_streamandtest_acompletion_raw_response_streamopencompletion_streamed.yamlwithstream=Trueviawith_raw_response.create(...)but never consume the stream, so the VCR connection is never released. Underpytest-randomlyorderings the cassette bleeds into later tests, whose unrelated requests fail to match and raiseCannotOverwriteExistingCassetteException— the same failure mode reported as "~63 llmobs rate-limit failures" in the recent dd-trace-py CI incident (mislabeled as external API 429s by automated triage; it's actually this cassette leak).Fix
Drain the raw stream inside the cassette block (
resp.parse()/async for), same approach as #18778.Testing
Ran the affected tests directly and the full
test_openai_v1.pyfile under the exactpytest-randomlyseed (3338286823) that originally triggered the leak in #18778 — all pass, 0 failures.Claude session:
46d356c1-1ac1-4826-b78b-ea87f4220ddaResume:
claude --resume 46d356c1-1ac1-4826-b78b-ea87f4220dda