fix(anthropic): stop leaked VCR httpx patch from failing live tests#38888
Open
Mason Daugherty (mdrxy) wants to merge 1 commit into
Open
fix(anthropic): stop leaked VCR httpx patch from failing live tests#38888Mason Daugherty (mdrxy) wants to merge 1 commit into
Mason Daugherty (mdrxy) wants to merge 1 commit into
Conversation
vcrpy skips its httpx un-patch step when saving a cassette raises during teardown, leaving httpx.HTTPTransport patched for the rest of the worker session. Later live integration tests then replay against the wrong cassette and fail with CannotOverwriteExistingCassetteException / APIConnectionError. Add an autouse fixture that restores pristine httpx transports around non-VCR tests so a leak can't cascade. Co-authored-by: open-swe[bot] <open-swe@users.noreply.github.com>
Mason Daugherty (mdrxy)
marked this pull request as ready for review
July 16, 2026 18:46
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.
Scheduled Anthropic integration runs have been flaking with a confusing mix of
anthropic.APIConnectionError: Connection error.andvcr.errors.CannotOverwriteExistingCassetteExceptionon live (non-cassette) tests. The failures always cluster on a singlepytest-xdistworker and reference one unrelated cassette (e.g.test_code_execution.yaml.gz), while the same tests pass on other workers.The culprit is a
vcrpyteardown bug.CassetteContextDecorator.__exit__callscassette._save()before it un-patches httpx; if the save raises (a dirty cassette whose serialization fails), the un-patch step is skipped andhttpx.HTTPTransport.handle_requeststays monkeypatched for the rest of that worker's session. Every later request — including live integration tests that should hit the real API — is then intercepted by the stale cassette and fails. I reproduced this locally: a cassette that errors on save leaves httpx patched, andmock.patchstacking lets that leaked wrapper resurface under otherwise-clean cassette tests.Rather than depend on a
vcrpyfix, this adds a small defensive guard in the Anthropic test suite: it captures the pristine httpx transport handlers at import time and, via an autouse fixture, restores them around every test that is not@pytest.mark.vcr(i.e. the live network tests). Cassette-backed tests are untouched, so VCR keeps managing its own patching; a leak from one test can no longer cascade into the live tests that follow.Made by Open SWE