Repository navigation
fix(router): keep a lone deployment warm under router allowed_fails unless the policy names the exception - #48644
Conversation
…nless the policy names the exception 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)".
|
Merging this PR will not alter performance1 warning
Comparing Footnotes |
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
…fails=0 still forces a cooldown
|
@BugBot run |
[Medium impact] The latest changes appear safe to merge, with no new actionable issues found SummaryRouter The latest change accepts dictionary fallback targets and adds a regression case. The previous fallback, empty-policy, and dictionary-target findings are addressed kerry-berri explicitly describes the loss of lone-deployment load shedding as intentional, to match deployment-level behavior. Naming the exception in The previous title-format thread was manually resolved without explanation. All supplied previous threads were unnumbered
Reviews (3) · Last reviewed commit: "fix(router): accept dictionary fallback ..." · Reviewed by Greptile |
…p or an empty deployment policy
|
@BugBot run |
…t check Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
2ae458e to
874b128
Compare
|
@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 874b128. Configure here.
…llowed-fails Main's BerriAI#48644 keeps a lone deployment warm under router allowed_fails, so the explicit-3 tests now use a group with a sibling deployment.
…nless the policy names the exception (BerriAI#48644) Backport of BerriAI#48644 to lts/1.108.x. Cherry-picked from 8f31c71 (main). Dropped the pick's edit to a stream-stall test the line does not have. Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
When
router_settings.allowed_failsis set and a model group has exactly one deployment and no fallback, the router used to bench that deployment afterallowed_fails + 1retryable failures, so forcooldown_timeevery call came back 429 "No deployments available" without ever reaching the provider. The deployment levelallowed_failsalready refused to do that (#34416): a plain count leaves a lone deployment warm, only anallowed_fails_policyentry naming the exception type still cools it. This PR applies the same rule to the router level setting, so the two settings agree and a lone deployment keeps forwarding every call. "Lone" means one deployment in its group and nofallbacksentry for the requested group, so a primary that has a fallback is still benched and traffic moves to the fallbackDetails
TLDR
Problem this solves:
allowed_failsbenched the only deployment of a group with no fallbackcooldown_timewith no provider callallowed_failsalready kept a lone deployment warm, the two disagreedHow it solves it:
fallbacksentry for itallowed_fails, also with an empty deployment policyallowed_fails_policyentry naming the exception type still cools itIntentional product change: a proxy with router
allowed_failsand a single deployment with no fallback no longer answers 429 duringcooldown_time. Every call reaches the provider and gets the provider's own answer (a 408, or a 200 once the provider recovers). An operator who relied on that bench to shed load from a lone deployment loses it, and gets it back by naming the exception type inallowed_fails_policy(for exampleTimeoutErrorAllowedFails: 1)User Flow
Before: a developer whose proxy has one
nano-singledeployment andallowed_fails: 1is locked out of the model for a minute after two timeouts"model": "nano-single"three times while the provider is timing out and get 408litellm.TimeouttwiceNo deployments available for selected model, Try again in 60 secondsin under 50 ms, nothing was sent to OpenAI"timeout": 600in the body once the provider is fine, and still get the same 429 until the minute is upAfter: the same developer gets the provider's answer on every call
litellm.Timeoutthree times"timeout": 600in the body and get 200 with the model's reply from OpenAIallowed_failsremoved fromrouter_settingsthe same four calls give the same 408, 408, 408, 200, the two configs now agreeRelevant issues
Related to #46182 (an explicit
allowed_fails: 3is treated as unset because it equals the default). Not fixed here, this PR touches only the branch that runs onceallowed_failsis seen as set. Related PR: #46183 by @HardMax71 works on_is_allowed_fails_set_on_routerand on fallback deployments in the same file. Nothing in this diff is taken from that branch, so no co-author trailer. That PR's description says a model with no fallback answers 429 after its 4th 408 under an explicitallowed_fails: 3. After this PR that lone deployment stays warm instead. Its primary-with-fallback case is kept, the primary is still benched (the fallback case below)Linear ticket
Resolves LIT-9773
Pre-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 moreTests.
tests/unit/router_utils/test_cooldown_handlers.py: the oldtest_allowed_fails_cools_a_single_deploymentpinned the bug for theallowed_failscase, so it is replaced bytest_router_allowed_fails_benches_a_lone_deployment_only_when_the_policy_names_the_exception(plainallowed_fails, plainallowed_failswith an emptymodel_info.allowed_fails_policy, a policy naming another exception, a policy namingTimeout, plainallowed_failswith afallbacksentry for the group, plainallowed_failswith a dictionary fallback target such as{"model": "backup-model", "temperature": 0}) andtest_router_allowed_fails_still_benches_a_deployment_that_has_a_sibling_in_its_group.tests/integration/routing/test_payment_required_cooldown.py:test_a_router_allowed_fails_count_leaves_a_lone_deployment_warm_but_benches_one_with_a_sibling_or_fallbackboots a proxy withallowed_fails: 1and afallbacksentry, a scripted upstream answering 500, and checks a lone deployment takes four calls without cooling while the same upstream in a two deployment group, or as a lone primary with a fallback group, is benched after its second failure and the healthy deployment takes every later call (the fallback case allows the one call that can still reach the primary while the cooldown written to Redis propagates to the router). The file passed locally at this tip (16 passed in 120s). CircleCI runs it on main after merge, not on this PR. Four existing unit fixtures intests/unit/test_router/test_router.py(TestBackgroundResponseCostPollCooldown,TestCallerTimeoutCooldown) andtests/unit/router_utils/test_fallback_event_handlers.py(TestTriggerCooldownForFailedDeployment,test_a_fallback_deployment_whose_stream_stalled_stays_out_of_cooldown) used a single deployment withallowed_fails=0as a shortcut to force a cooldown while testing something else (caller timeouts, background poll 404s, stalled fallback streams). They now carry a second deployment in the group so that shortcut keeps working under the new rule, their assertions are unchangedRed leg, the first three unit cases against the code without the guard (the mutation is deleting the
ifin the router levelelseof_should_cooldown_deployment), captured before the fallback and empty policy cases were added:Green leg on this tip:
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
Real
openai/gpt-5.4-nano, Postgres, proxy on localhost:4000.timeout: 0.001on the deployment gives a real 408 from the OpenAI client, the last call carries"timeout": 600in the body so it reaches OpenAIConfigs
lone.yaml(the ticket's config)lone_no_allowed_fails.yamlfallback.yamlpair.yamlBefore (5667ac8)
Lone deployment with allowed_fails: 1 (the ticket)
uv run --no-sync litellm --config lone.yaml --detailed_debug --port 4000with Postgres up andOPENAI_API_KEYin the environment"timeout": 600in the body):SELECT "startTime", status, call_type, model, metadata::jsonb->'error_information'->>'error_code' AS error_code, spend FROM "LiteLLM_SpendLogs" ORDER BY "startTime" DESC LIMIT 4:Lone deployment with allowed_fails removed
uv run --no-sync litellm --config lone_no_allowed_fails.yaml --detailed_debug --port 4000with Postgres up andOPENAI_API_KEYin the environment"timeout": 600in the body):SELECT "startTime", status, call_type, model, metadata::jsonb->'error_information'->>'error_code' AS error_code, spend FROM "LiteLLM_SpendLogs" ORDER BY "startTime" DESC LIMIT 4:Two deployment group with allowed_fails: 1
uv run --no-sync litellm --config pair.yaml --detailed_debug --port 4000, two deployments innano-pair,nano-timeout(timeout 0.001) andnano-healthy,allowed_fails: 1SELECT "startTime", status, model_id, metadata::jsonb->'error_information'->>'error_code' AS error_code, spend FROM "LiteLLM_SpendLogs" ORDER BY "startTime" DESC LIMIT 10:Lone primary with a fallback group and allowed_fails: 1
uv run --no-sync litellm --config fallback.yaml --detailed_debug --port 4000, onenano-primarydeployment (timeout 0.001),fallbacks: [{"nano-primary": ["nano-backup"]}],allowed_fails: 1nano-primary:SELECT "startTime", status, model_id, metadata::jsonb->'error_information'->>'error_code' AS error_code, spend FROM "LiteLLM_SpendLogs" ORDER BY "startTime" DESC LIMIT n:The primary is benched after its second timeout as expected, but the healthy backup is benched too and calls 5 and 6 get 429. That is the fallback cooldown bug #46182 / #46183 describe (the no-deployment failure of the benched primary is charged to the backup), not something this PR touches
After (874b128, the fallback and lone deployment checks are unchanged since 75a3e1a)
Lone deployment with allowed_fails: 1 (the ticket)
uv run --no-sync litellm --config lone.yaml --detailed_debug --port 4000with Postgres up andOPENAI_API_KEYin the environment"timeout": 600in the body):SELECT "startTime", status, call_type, model, metadata::jsonb->'error_information'->>'error_code' AS error_code, spend FROM "LiteLLM_SpendLogs" ORDER BY "startTime" DESC LIMIT 4:Lone deployment with allowed_fails removed
uv run --no-sync litellm --config lone_no_allowed_fails.yaml --detailed_debug --port 4000with Postgres up andOPENAI_API_KEYin the environment"timeout": 600in the body):SELECT "startTime", status, call_type, model, metadata::jsonb->'error_information'->>'error_code' AS error_code, spend FROM "LiteLLM_SpendLogs" ORDER BY "startTime" DESC LIMIT 4:Two deployment group with allowed_fails: 1
uv run --no-sync litellm --config pair.yaml --detailed_debug --port 4000, two deployments innano-pair,nano-timeout(timeout 0.001) andnano-healthy,allowed_fails: 1SELECT "startTime", status, model_id, metadata::jsonb->'error_information'->>'error_code' AS error_code, spend FROM "LiteLLM_SpendLogs" ORDER BY "startTime" DESC LIMIT 10:Lone primary with a fallback group and allowed_fails: 1
uv run --no-sync litellm --config fallback.yaml --detailed_debug --port 4000, onenano-primarydeployment (timeout 0.001),fallbacks: [{"nano-primary": ["nano-backup"]}],allowed_fails: 1nano-primary:SELECT "startTime", status, model_id, metadata::jsonb->'error_information'->>'error_code' AS error_code, spend FROM "LiteLLM_SpendLogs" ORDER BY "startTime" DESC LIMIT n:The primary is still benched after its second timeout, so this PR keeps the bench for a lone primary that has a fallback. The backup stays warm here because the backup is itself a lone deployment with no fallback under a plain
allowed_fails, which is the rule this PR adds. #46183's own fix for the charged failure is still needed for a backup that has siblingsType
🐛 Bug Fix
Caveats (if any)
Medium
allowed_failsto bench a lone deployment on purpose loses that, the After lone case above shows every call now reaches the providerallowed_fails_policywith the exception type named (TimeoutErrorAllowedFails: 1) keeps the bench, covered by thepolicy_names_timeoutunit caseLow
allowed_fails_policythat does not name the failing exception type also leaves a lone deployment warm now, matching the deployment level rule, covered by thepolicy_names_another_exceptionunit casetests/integrationon pull requestsFinal Attestation
Link to Devin session: https://app.devin.ai/sessions/7e92ece173204697b0b021200c146cc9
Open in Devin Desktop: https://app.devin.ai/desktop/session/7e92ece173204697b0b021200c146cc9?variant=devin
Requested by: @kerry-berri
Note
Medium Risk
Changes core router cooldown behavior for proxies using router
allowed_failson single-deployment groups (no more 429 benching without an explicit per-exception policy); operators who relied on that for load shedding needallowed_fails_policyinstead.Overview
Aligns router-level
allowed_failswith deployment-level behavior so a lone deployment (one member in its model group and nofallbacksentry for that group) is not benched from a plain failure count alone._should_cooldown_deploymentnow definesis_lone_deploymentvia new_has_fallback_group(parses routerfallbackswithget_fallback_model_group) and uses it instead of only “single deployment in group” when applying deployment-policy skips and the routerallowed_failsbranch. Under routerallowed_fails/ generic policy, lone deployments stay warm unlessallowed_fails_policynames the failing exception (e.g.TimeoutErrorAllowedFails). Groups with a sibling deployment or a configured fallback still cool down after the threshold as before.Deployment-policy deferral when the exception isn’t named in policy is tightened: on lone groups it also defers when router-level policy doesn’t name the exception, not only when
dep_allowed_failsis set.Tests replace the old “single deployment always cools with allowed_fails” case with parametrized unit coverage and an integration test for lone vs paired vs primary-with-fallback; unrelated fixtures gain a second deployment so
allowed_fails=0can still force cooldown without relying on a lone group.Reviewed by Cursor Bugbot for commit 874b128. Bugbot is set up for automated code reviews on this repo. Configure here.