Repository navigation
test(caching): baseline breaker metrics from live state after gc - #46652
Conversation
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
|
I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".
|
|
Automatic reviews are disabled for this repository. |
|
|
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
|
@litereview code-review |
✅ code-review5/5 · Ready for human reviewScope: full · Full PR review. No correctness findings. The change only touches tests. Checks and execution details
View review · Reviewed |
…reads live breakers
|
@litereview code-review |
|
bugbot run |
There was a problem hiding this comment.
✅ Bugbot reviewed your changes and found no new issues!
Comment @cursor review or bugbot run to trigger another review on this PR
Reviewed by Cursor Bugbot for commit 93163f3. Configure here.
|
@litellm-stampbot |
litellm-stampbot: risk lowApproved at Rules (
Judge (gpt-6-luna): low, probability of high 0.00 (high at or above 0.90)
Pushes do not re-run this check. Comment |
kerry-berri
left a comment
There was a problem hiding this comment.
Low risk by rule and by judgement at 93163f3
TLDR
Problem this solves:
test_breaker_metrics_track_state_and_failure_classflakes in thecaching-localunit shardassert 0.0 == 2.0on the open-state gauge, then passes on rerunHow it solves it:
redis_breaker_state_counts()instead of the stale gaugetest_prometheus_services_logger_starts_from_the_breakers_already_built, which reads the gauge the same wayUser Flow
Before: a contributor whose PR touches no caching code gets a red required
unit passedcheckunitworkflow runs itscaching-localjobtest_breaker_metrics_track_state_and_failure_classwithassert 0.0 == 2.0orassert 0.0 == 1.0unit passedgoes red and they rerun the job, sometimes more than once, until it passesAfter: the same PR's
caching-localjob passes on the first rununitworkflow runs itscaching-localjobunit passedgoes green without a rerunMechanism
The
litellm_redis_circuit_breaker_stategauge is a snapshot of every liveRedisCircuitBreaker. It refreshes when a breaker is built, on every recorded failure, on every state change, and when the Prometheus services logger starts. Earlier tests on the same xdist worker can leave breakers behind as cyclic garbage. The test read its open and closed baselines while those breakers were still alive, and when the garbage collector freed them mid-test, the next refresh reported fewer breakers thanbaseline + deltaexpected. Which tests share the worker and when the collector runs decides whether it fails, which is why it flips on rerunCalling
gc.collect()before the baselines frees that garbage first, so nothing left by earlier tests can die during the test, and reading the baselines fromredis_breaker_state_counts()uses the same live source the gauge refreshes from.test_prometheus_services_logger_starts_from_the_breakers_already_builtcompares the gauge the logger sets at startup with the live count, so garbage freed between those two reads failed it the same way, and it now collects first too. Production code is unchanged. The gauge bug behind the flake is pre-existing and filed as a follow-up, kept out of this tests-only PRPre-Submission checklist
Please complete all items before asking a LiteLLM maintainer to review your PR
uv run pytest tests/unit/<your_test_file>.py -v. Leave the suites (make test-unit-*,make test-unit) to CI: it finishes in ~15 minutes where a laptop takes an hour or moreScreenshots / Proof of Fix
The flake is a garbage collection that lands mid-test, so the repro forces exactly that. A probe test runs first on the same worker, leaves two open breakers as cyclic garbage, and runs the collector the moment the real test's breaker closes. The base leg runs main's copy of the test file, the after leg the PR's copy, both against the same unchanged product code
Probe test (scratch file, not part of this PR)
Before (35970c3)
git show 35970c3eac:tests/unit/caching/test_redis_cache.py > tests/unit/caching/test_redis_cache_at_base.pypython -m pytest -p no:randomly -n 0 -q -s tests/unit/caching/test_zz_breaker_garbage_probe.py tests/unit/caching/test_redis_cache_at_base.py::test_breaker_metrics_track_state_and_failure_classThat is the same assertion, line and label the CI runs below failed on
After (93163f3)
python -m pytest -p no:randomly -n 0 -q -s tests/unit/caching/test_zz_breaker_garbage_probe.py tests/unit/caching/test_redis_cache.py::test_breaker_metrics_track_state_and_failure_classSibling test, before (35970c3) and after (93163f3)
A second probe leaves two closed breakers as garbage and runs the collector right after the logger sets the gauge at startup
Sibling probe test (scratch file, not part of this PR)
Before, against main's copy of the test file
After, against this PR's copy
Type
✅ Test
Caveats (if any)
Low
litellm_redis_circuit_breaker_statestill counts breakers that gc already freed until the next breaker event, so a cache or Router rebuild can show phantom breakers. That is pre-existing on main, and the follow-up computes the gauge from live breakerstests/unit/caching/test_redis_cache.pychanges. The probe legs stand in, and one greencaching-localrun cannot show a flake rateFinal Attestation
Link to Devin session: https://app.devin.ai/sessions/15f41c28ccbf40a095eeb626850220cd
Open in Devin Desktop: https://app.devin.ai/desktop/session/15f41c28ccbf40a095eeb626850220cd?variant=devin
Note
Low Risk
Tests-only change; no production code paths are modified.
Overview
Stabilizes flaky Redis circuit breaker Prometheus metric tests in
test_redis_cache.pyby accounting for leftoverRedisCircuitBreakerinstances on shared xdist workers.test_breaker_metrics_track_state_and_failure_classnow runsgc.collect()before recording baselines, and derives open/closed state baselines fromredis_breaker_state_counts()(live weakref registry) instead of thelitellm_redis_circuit_breaker_stategauge snapshot, so mid-test GC cannot drop phantom breakers and breakbaseline + deltaassertions.test_prometheus_services_logger_starts_from_the_breakers_already_builtalso callsgc.collect()before initializing the Prometheus services logger so gauge vs live-count comparison is not racy. Production behavior is unchanged.Reviewed by Cursor Bugbot for commit 93163f3. Bugbot is set up for automated code reviews on this repo. Configure here.