Repository navigation
fix(caching): don't trip redis circuit breaker on short timeout bursts - #38999
yassin-berriai merged 3 commits into
Conversation
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
|
|
|
No action taken on #38999 — repo and author check out ( |
Greptile SummaryThe PR separates timeout streaks from hard Redis connectivity failures and adds state and failure-class metrics.
Confidence Score: 5/5The PR appears safe to merge. No blocking failure remains.
|
| Filename | Overview |
|---|---|
| litellm/caching/redis_cache.py | Adds class-specific breaker accounting, a timeout-duration gate, and aggregate state and transition metrics. |
| litellm/constants.py | Adds the environment-configurable minimum duration for timeout-only breaker activation. |
| tests/test_litellm/caching/test_redis_cache.py | Adds focused regression coverage for timeout bursts, mixed failure sequences, recovery, and metrics. |
Reviews (3): Last reviewed commit: "fix(caching): reset the timeout streak o..." | Re-trigger Greptile
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
…nt breaker states per label Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
…outs cannot pre-age the duration gate Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
|
Fixed in 5481729: a hard failure now resets the timeout streak, so a later burst must span the duration itself |
942a46f
into
litellm_internal_staging
TLDR
Problem this solves:
How it solves it:
REDIS_CIRCUIT_BREAKER_TIMEOUT_MIN_DURATION(default 5s); the duration gate counts timeouts alone, and a hard failure resets the timeout streak, so mixed sequences and stale timeouts cannot open it earlyUser Flow
Before: a proxy admin running Redis caching sees caching silently stop after a brief latency blip even though Redis is fine
redis-cli pingstill answers PONGAfter: the same blip is ridden out and caching stays on
Relevant issues
Linear ticket
Resolves LIT-6562
Pre-Submission checklist
Please complete all items before asking a LiteLLM maintainer to review your PR
uv run pytest tests/test_litellm/<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 more@greptileaito re-request a review after pushing changes)Delays in PR merge?
If you're seeing a delay in your PR being merged, ping the LiteLLM Team on Slack (#pr-review).
Screenshots / Proof of Fix
Shared setup: local
redis-serveron 6379, proxy on port 4000 withcache: {type: redis, socket_timeout: 0.1}and one Anthropic model, real Anthropic API calls. The stall is induced withredis-cli DEBUG SLEEP 6(Redis stops answering for 6s, then is healthy again), which makes all in-flight cache reads and writes time out together, the same shape as an event-loop stall from the breaker's point of viewBefore (3905c9d)
Timeout burst against healthy Redis opens the breaker
curl -s http://localhost:4000/chat/completions -H "Authorization: Bearer sk-1234" -d '{"model":"anthropic-haiku-4-5","messages":[{"role":"user","content":"Say OK"}],"max_tokens":5}'returns 200 with a real completion (control)(redis-cli DEBUG SLEEP 6 &)then 8 concurrent identical curls: all return200 200 200 200 200 200 200 200redis-cli pingright after returnsPONG(Redis healthy)18:52:02 - LiteLLM:WARNING: redis_cache.py:156 - Redis circuit breaker OPENED after 5 consecutive failures — fast-failing Redis calls for 60s, so caching is disabled for 60s against a healthy RedisAfter (5481729)
Timeout burst against healthy Redis keeps the breaker closed
control:200(redis-cli DEBUG SLEEP 6 &)plus 8 concurrent curls: all 200, worst latency 0.13sredis-cli pingreturnsPONG; proxy log has 25Timeout reading from 127.0.0.1:6379entries and zerocircuit breaker OPENEDlines, so the burst was seen and ridden outrecovery:200) reads and writes the cache normallyReal outage still fails fast
sudo service redis-server stop, then 6 sequential curls: all return 200 (cache skipped, LLM still served)19:30:47 - LiteLLM:WARNING: redis_cache.py:190 - Redis circuit breaker OPENED after 5 consecutive failures (5 hard connectivity) — fast-failing Redis calls for 60sBenchmark, one worker, reproduced load profile
Type
🐛 Bug Fix
Caveats (if any)
Low
time.sleepREDIS_CIRCUIT_BREAKER_TIMEOUT_MIN_DURATION(default 5s, env-configurable) before opening; a genuinely hung Redis that only times out is evicted ~5s later than beforeFinal Attestation
Link to Devin session: https://app.devin.ai/sessions/c5971319db694f0db319fbe75f40e09d
Open in Devin Desktop: https://app.devin.ai/desktop/session/c5971319db694f0db319fbe75f40e09d?variant=devin
Requested by: @yassin-berriai