Repository navigation
Conversation
|
Comments Outside DiffThese findings could not be posted inline.
|
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
3477d04 to
6a74230
Compare
| 2. there are fallbacks for the completion call | ||
| """ | ||
| if fallback_available: | ||
| return 0 |
There was a problem hiding this comment.
Low: Unbounded immediate retry burst
An authenticated client can send x-litellm-num-retries: 100 with a short client-controlled timeout when a configured or allowed fallback exists, causing one proxy request to issue 101 immediate primary attempts before falling back. The header is accepted without a cap, and router retries reuse the original request's rate-limit reservation, so returning zero here bypasses the intended pacing; transfer control directly to the fallback or enforce a bounded retry count/minimum delay.
PR overviewThis PR changes router retry behavior to skip backoff when a configured fallback can take over a failed request. One security issue remains open. An authenticated client can request an uncapped number of retries and trigger a burst of immediate primary attempts before fallback handling, potentially amplifying backend load from a single proxy request. No issues have yet been addressed. Open issues (1)
Fixed/addressed: 0 · PR risk: 5/10 |
f1fef4d to
08b1354
Compare
|
@greptileai rebased onto current main with the test file's new path, and re-measured the real provider proof at this tip. |
|
@mateo-berri could you take a look when you have a chance? This addresses the latency part of #40405: when a fallback can take over, the router skips the retry backoff instead of sleeping first. Greptile's P1 about an unusable fallback is handled in 2a12366, which checks the fallback the dispatcher will actually use before skipping the backoff, with tests in 08b1354. Rebased on main on 9/28. |
08b1354 to
40ed433
Compare
|
@greptileai rebased to resolve a conflict with #43600, which added its own fallback helpers next to these. Both kept, proof re-measured. |
40ed433 to
073de7b
Compare
|
@greptileai good catch on the empty chain. The gate now requires a resolved chain with entries, with an integration and a unit regression test. |
|
Confirmed. Requiring a non-empty resolved chain fixes the empty-chain case, and the regression coverage verifies that |
|
@greptileai please re-review the current commit 073de7b and refresh the confidence score; the badge still points at the previous one. |
073de7b to
fca7a3d
Compare
|
@greptileai the backoff tests now assert the delay the router chose, with asyncio.sleep patched, so nothing reads the clock. |
TLDR
Problem this solves:
How it solves it:
User Flow
Before: an app whose primary model has one deployment and a fallback gets answers about 5 seconds late while the primary provider is down
primarywith one deployment,backupas its fallback, andnum_retries: 2"model": "primary"backupafter about 5.5 secondsAfter: the same request is answered by the fallback as soon as the retries fail
primarywith one deployment,backupas its fallback, andnum_retries: 2"model": "primary"backupin under a secondRelevant issues
Addresses the latency part of #40405. The cooldown and docs asks in that issue are left for a separate change
Affected release
Linear ticket
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
The fallback is a real OpenAI call. The primary is a small local server that answers every request with HTTP 500, since a real provider outage cannot be triggered on demand
primary_down.pyconfig.yamlrun.shsends 10 requests to the primary model and prints the status, total time, the fallback header, and the reply.run_client.shis the same loop with a client-side fallback list in the request body,"fallbacks": [{"model": "backup"}]For both sides,
python3 primary_down.pyruns in one shell andpython litellm/proxy/proxy_cli.py --config config.yaml --port 4100in anotherBefore (7d9cc28)
Fallbacks from the router config
zsh run.shClient-side fallback list in the request
zsh run_client.shAfter (fca7a3d)
Fallbacks from the router config
zsh run.shClient-side fallback list in the request
zsh run_client.shAcross both cases the down primary logged 62 attempts before the change and 62 after, so the retries still happen and only the waiting between them is gone
An earlier run of the same two cases hit backup-provider latency, one request at 22.3s and another at 12.0s, with medians of 1.01s and 1.41s. That is the fallback call itself, not backoff: under backoff every request in the run is slow, as the before blocks show. Over both runs (20 requests per case) the medians are 0.80s and 0.96s
Type
🐛 Bug Fix
Caveats (if any)
Medium
Retry-AfterLow
num_retries + 1attempts per requestallowed_failswithcooldown_timeis still how to stop those3e6097d9f8and were removed an hour later in4d648a6d89fallbacks: [{"primary": []}]) keeps the backoffhas_unattempted_fallback_targetreports an unattempted target for an empty chain while the request carries no attempt record, so the gate guards that case before askingFinal Attestation