Fix cache miss in replay mode for subsequent tests#16
Merged
Conversation
ONCE mode now replays existing entries AND records new ones on cache miss, instead of failing when encountering instructions not in the cassette. This fixes the bug where the first test passes but subsequent tests fail with "Cache miss in replay mode" even though noot should be recording. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Add blank line after imports in cache.py - Remove unused imports in test_cache_modes.py Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
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.
Summary
Problem
When running multiple tests in a pytest session (or adding new tests in subsequent sessions), the second test would fail with:
Root Cause
In ONCE mode, after the first test created the cassette file, subsequent
Cache.from_env()calls would see the cassette exists and switch to replay-only mode (_should_record=False), causing any new instructions to fail instead of being recorded.Solution
Changed ONCE mode semantics to always allow recording while also loading existing entries:
This is the expected behavior for a "record once" mode - it should accumulate entries over time, not lock after the first test.
Test plan
pytest tests/test_cache_modes.py -vpasses🤖 Generated with Claude Code