Repository navigation
fix(tests): stabilize image-edit VCR cassettes to stop live gpt-image-1 spend #28110
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
yuneng-berri
merged 19 commits into
litellm_internal_staging
from
litellm_stabilize_image_edit_vcr_cassettes
May 18, 2026
Merged
Changes from 5 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
e58a561
Merge pull request #27906 from BerriAI/litellm_internal_staging
shin-berri a72414a
Merge pull request #28100 from BerriAI/litellm_internal_staging
yuneng-berri 4254c4a
fix(tests): stabilize image-edit VCR cassettes to stop live gpt-image…
mateo-berri ba3915d
DIAGNOSTIC: log VCR body mismatches + per-episode body hashes
mateo-berri 85430bc
DIAGNOSTIC: route VCR diagnostics through per-PID files (bypass xdist…
mateo-berri 8e08272
fix(tests): coalesce iterable request bodies before matching/recording
mateo-berri 9e2e5b6
fix(tests): handle bytes_iterator + never leave an exhausted body
mateo-berri 1c51ad1
fix(tests): clear vcrpy's sticky _was_iter flag so materialized bodie…
mateo-berri 927c554
revert(tests): drop the temp per-episode body-hash diagnostic
mateo-berri c7d6d4d
chore(tests): delete unused flush script + wire VCR diagnostic dump e…
mateo-berri 78ada20
chore(tests): trim non-essential comments per project comment policy
mateo-berri a3c36f0
chore(tests): forward **kwargs in pin_httpx_multipart_boundary wrapper
mateo-berri 6e3d4b0
chore(tests): canonicalize VCR matchers and surface shouldn't-happen …
mateo-berri 32369ed
chore(tests): symmetrize diag-log cleanup across every VCR-using conf…
mateo-berri 1957d6d
fix(tests): gate body materialization on __next__ and strip PR comments
mateo-berri bfa1cb8
fix(tests): JSON-encode dict bodies in canonical_body for stable matc…
mateo-berri f41a2b1
fix(tests): guard emit_vcr_diagnostic_log against multi-conftest re-e…
cursoragent dc59efb
fix(tests): globalize multipart-boundary pin + stabilize whisper fixt…
mateo-berri ea77162
chore(tests): drop per-episode body-hash dump and redundant emit guard
mateo-berri File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,131 @@ | ||
| #!/usr/bin/env python3 | ||
| """Flush the bloated image-edit VCR cassettes from the cassette Redis. | ||
|
|
||
| Run this **once** after merging the multipart-boundary stabilization | ||
| PR. The pre-fix cassettes for the async image-edit tests have | ||
| accumulated >50 episodes (random multipart boundary on every run + | ||
| ``record_mode="new_episodes"`` = monotonic growth), so the persister | ||
| refuses to save updates -- meaning every CI run after the fix would | ||
| still try to re-record against the stale 51-entry cassette, hit | ||
| ``MAX_EPISODES_PER_CASSETTE`` again, get refused, and re-bill the live | ||
| provider. | ||
|
|
||
| Deleting these keys forces the next CI run to record a clean cassette | ||
| under the new fixed-boundary + raw-bytes fixtures (1 episode per | ||
| unique call), after which the 24-hour TTL replay loop kicks in | ||
| normally. | ||
|
|
||
| Scope is intentionally narrow: | ||
| * Only ``tests/image_gen_tests/test_image_edits/*`` cassette keys | ||
| are touched. Image-*generation* cassettes (TestOpenAIGPTImage1 | ||
| etc.) are unaffected -- they were already in the VCR HIT state. | ||
| * Lists every match in dry-run mode before deleting anything so the | ||
| operator can confirm the impact. | ||
|
|
||
| Usage: | ||
| CASSETTE_REDIS_URL=redis://... \ | ||
| uv run python scripts/flush_image_edit_vcr_cassettes.py --dry-run | ||
|
|
||
| CASSETTE_REDIS_URL=redis://... \ | ||
| uv run python scripts/flush_image_edit_vcr_cassettes.py --yes | ||
|
|
||
| ``CASSETTE_REDIS_URL`` is the same env var the persister reads at CI | ||
| start (see ``tests/_vcr_redis_persister.py``). | ||
| """ | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| import argparse | ||
| import os | ||
| import sys | ||
|
|
||
| import redis | ||
|
|
||
|
|
||
| CASSETTE_REDIS_URL_ENV = "CASSETTE_REDIS_URL" | ||
| REDIS_KEY_PREFIX = "litellm:vcr:cassette:" | ||
| TARGET_KEY_PATTERN = f"{REDIS_KEY_PREFIX}tests/image_gen_tests/test_image_edits/*" | ||
|
|
||
|
|
||
| def _build_client(url: str) -> redis.Redis: | ||
| return redis.Redis.from_url( | ||
| url, | ||
| socket_timeout=10, | ||
| socket_connect_timeout=10, | ||
| decode_responses=False, | ||
| ) | ||
|
|
||
|
|
||
| def _scan_matching_keys(client: redis.Redis, pattern: str) -> list[bytes]: | ||
| return sorted(client.scan_iter(match=pattern, count=500)) | ||
|
|
||
|
|
||
| def _delete_keys(client: redis.Redis, keys: list[bytes]) -> int: | ||
| if not keys: | ||
| return 0 | ||
| # Batch into chunks so a single DEL call does not exceed the | ||
| # server's argument-count or buffer limits on large key sets. | ||
| deleted = 0 | ||
| chunk_size = 200 | ||
| for start in range(0, len(keys), chunk_size): | ||
| batch = keys[start : start + chunk_size] | ||
| deleted += int(client.delete(*batch)) | ||
| return deleted | ||
|
|
||
|
|
||
| def main(argv: list[str] | None = None) -> int: | ||
| parser = argparse.ArgumentParser(description=__doc__) | ||
| parser.add_argument( | ||
| "--yes", | ||
| action="store_true", | ||
| help="Actually delete the matched keys. Without this flag the script " | ||
| "runs in dry-run mode and only lists what would be deleted.", | ||
| ) | ||
| parser.add_argument( | ||
| "--dry-run", | ||
| action="store_true", | ||
| help="List matched keys without deleting (default behaviour when " | ||
| "--yes is omitted; kept as an explicit flag for clarity).", | ||
| ) | ||
| parser.add_argument( | ||
| "--pattern", | ||
| default=TARGET_KEY_PATTERN, | ||
| help=f"Override the SCAN match pattern. Default: {TARGET_KEY_PATTERN}", | ||
| ) | ||
| args = parser.parse_args(argv) | ||
|
|
||
| url = os.environ.get(CASSETTE_REDIS_URL_ENV) | ||
| if not url: | ||
| print( | ||
| f"error: {CASSETTE_REDIS_URL_ENV} is not set. Set it to the " | ||
| "cassette Redis URL (same URL the persister reads in CI).", | ||
| file=sys.stderr, | ||
| ) | ||
| return 2 | ||
|
|
||
| client = _build_client(url) | ||
| try: | ||
| client.ping() | ||
| except redis.RedisError as exc: | ||
| print(f"error: cannot reach cassette Redis: {exc}", file=sys.stderr) | ||
| return 2 | ||
|
|
||
| matches = _scan_matching_keys(client, args.pattern) | ||
| print(f"matched {len(matches)} key(s) under pattern: {args.pattern}") | ||
| for key in matches: | ||
| print(f" {key.decode('utf-8', errors='replace')}") | ||
|
|
||
| if not matches: | ||
| return 0 | ||
|
|
||
| if not args.yes: | ||
| print("\ndry run -- pass --yes to actually delete these keys.") | ||
| return 0 | ||
|
|
||
| deleted = _delete_keys(client, matches) | ||
| print(f"\ndeleted {deleted} key(s).") | ||
| return 0 | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| raise SystemExit(main()) |
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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.