Skip to content

Fix cache miss in replay mode for subsequent tests#16

Merged
ab-10 merged 2 commits intomainfrom
fix/cache-miss-replay-mode
Jan 27, 2026
Merged

Fix cache miss in replay mode for subsequent tests#16
ab-10 merged 2 commits intomainfrom
fix/cache-miss-replay-mode

Conversation

@recursiveAF
Copy link
Contributor

Summary

  • Fix bug where first test passes but subsequent tests fail with "Cache miss in replay mode"
  • ONCE mode now replays existing entries AND records new ones on cache miss
  • Added comprehensive test suite for all three recording modes (ONCE, NONE, ALL)

Problem

When running multiple tests in a pytest session (or adding new tests in subsequent sessions), the second test would fail with:

AssertionError: Flow.expect failed
Expected: world
Reason: Assertion generation/execution failed: Cache miss in replay mode: expect() with instruction: 'world'

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:

  • Before: Record if cassette missing, replay-only if exists
  • After: Replay existing entries, record new ones on cache miss

This is the expected behavior for a "record once" mode - it should accumulate entries over time, not lock after the first test.

Test plan

  • Added 15 unit tests covering all recording modes
  • pytest tests/test_cache_modes.py -v passes

🤖 Generated with Claude Code

recursiveAF and others added 2 commits January 27, 2026 09:56
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>
@ab-10 ab-10 merged commit d25d867 into main Jan 27, 2026
2 checks passed
@ab-10 ab-10 deleted the fix/cache-miss-replay-mode branch January 27, 2026 18:40
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.

2 participants