Skip to content

fix(router): keep a lone deployment warm under router allowed_fails unless the policy names the exception - #48644

Merged
kerry-berri merged 4 commits into
mainfrom
litellm_lone_deployment_router_allowed_fails
Oct 27, 2026
Merged

kerry-berri merged 4 commits into
mainfrom
litellm_lone_deployment_router_allowed_fails

Conversation

@kerry-berri

@kerry-berri kerry-berri commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

When router_settings.allowed_fails is set and a model group has exactly one deployment and no fallback, the router used to bench that deployment after allowed_fails + 1 retryable failures, so for cooldown_time every call came back 429 "No deployments available" without ever reaching the provider. The deployment level allowed_fails already refused to do that (#34416): a plain count leaves a lone deployment warm, only an allowed_fails_policy entry 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 no fallbacks entry for the requested group, so a primary that has a fallback is still benched and traffic moves to the fallback

Details

TLDR

Problem this solves:

  • router allowed_fails benched the only deployment of a group with no fallback
  • callers then got 429 for cooldown_time with no provider call
  • the deployment level allowed_fails already kept a lone deployment warm, the two disagreed

How it solves it:

  • the router level path now checks for a lone deployment before counting fails
  • lone means one deployment in the group and no fallbacks entry for it
  • a lone deployment stays warm under a plain allowed_fails, also with an empty deployment policy
  • a router allowed_fails_policy entry naming the exception type still cools it
  • groups with a second deployment or a fallback cool exactly as before

Intentional product change: a proxy with router allowed_fails and a single deployment with no fallback no longer answers 429 during cooldown_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 in allowed_fails_policy (for example TimeoutErrorAllowedFails: 1)

User Flow

Before: a developer whose proxy has one nano-single deployment and allowed_fails: 1 is locked out of the model for a minute after two timeouts

  1. They send POST http://localhost:4000/v1/chat/completions with "model": "nano-single" three times while the provider is timing out and get 408 litellm.Timeout twice
  2. The third call comes back 429 No deployments available for selected model, Try again in 60 seconds in under 50 ms, nothing was sent to OpenAI
  3. They retry with "timeout": 600 in the body once the provider is fine, and still get the same 429 until the minute is up

After: the same developer gets the provider's answer on every call

  1. They send the same three POST http://localhost:4000/v1/chat/completions calls and get 408 litellm.Timeout three times
  2. They retry with "timeout": 600 in the body and get 200 with the model's reply from OpenAI
  3. With allowed_fails removed from router_settings the same four calls give the same 408, 408, 408, 200, the two configs now agree
  4. In a group with a second deployment, or a lone primary with a fallback group, the timing out deployment is still benched after its second failure and the other one serves every later call

Relevant issues

Related to #46182 (an explicit allowed_fails: 3 is treated as unset because it equals the default). Not fixed here, this PR touches only the branch that runs once allowed_fails is seen as set. Related PR: #46183 by @HardMax71 works on _is_allowed_fails_set_on_router and 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 explicit allowed_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

  • I have added meaningful tests
  • The handful of test files covering my change pass locally, e.g. 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 more
  • My PR passes all required CI/CD checks (e.g., lint, schema.d.ts sync check, etc.)
  • My PR's scope is as isolated as possible; it only solves 1 specific problem
  • Every automated review on my PR's latest commit has finished, and I have addressed or replied to each of its findings before requesting a maintainer review

Tests. tests/unit/router_utils/test_cooldown_handlers.py: the old test_allowed_fails_cools_a_single_deployment pinned the bug for the allowed_fails case, so it is replaced by test_router_allowed_fails_benches_a_lone_deployment_only_when_the_policy_names_the_exception (plain allowed_fails, plain allowed_fails with an empty model_info.allowed_fails_policy, a policy naming another exception, a policy naming Timeout, plain allowed_fails with a fallbacks entry for the group, plain allowed_fails with a dictionary fallback target such as {"model": "backup-model", "temperature": 0}) and test_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_fallback boots a proxy with allowed_fails: 1 and a fallbacks entry, 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 in tests/unit/test_router/test_router.py (TestBackgroundResponseCostPollCooldown, TestCallerTimeoutCooldown) and tests/unit/router_utils/test_fallback_event_handlers.py (TestTriggerCooldownForFailedDeployment, test_a_fallback_deployment_whose_stream_stalled_stays_out_of_cooldown) used a single deployment with allowed_fails=0 as 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 unchanged

Red leg, the first three unit cases against the code without the guard (the mutation is deleting the if in the router level else of _should_cooldown_deployment), captured before the fallback and empty policy cases were added:

>       assert seen == outcomes
E       AssertionError: assert (<class 'lite...eLimitError'>) == (<class 'lite...ons.Timeout'>)
E         
E         At index 2 diff: <class 'litellm.types.router.RouterRateLimitError'> != <class 'litellm.exceptions.Timeout'>
E         Use -v to get more diff
>       assert seen == outcomes
E       AssertionError: assert (<class 'lite...eLimitError'>) == (<class 'lite...ons.Timeout'>)
E         
E         At index 4 diff: <class 'litellm.types.router.RouterRateLimitError'> != <class 'litellm.exceptions.Timeout'>
E         Use -v to get more diff
FAILED tests/unit/router_utils/test_cooldown_handlers.py::test_router_allowed_fails_benches_a_lone_deployment_only_when_the_policy_names_the_exception[allowed_fails]
FAILED tests/unit/router_utils/test_cooldown_handlers.py::test_router_allowed_fails_benches_a_lone_deployment_only_when_the_policy_names_the_exception[policy_names_another_exception]
2 failed, 2 passed, 177 deselected in 1.75s

Green leg on this tip:

FAILED tests/unit/router_utils/test_cooldown_handlers.py::test_router_allowed_fails_still_benches_a_deployment_whose_group_has_a_fallback
1 failed, 3 passed, 177 deselected in 1.49s

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.001 on the deployment gives a real 408 from the OpenAI client, the last call carries "timeout": 600 in the body so it reaches OpenAI

Configs

lone.yaml (the ticket's config)

model_list:
  - model_name: nano-single
    litellm_params:
      model: openai/gpt-5.4-nano
      api_key: os.environ/OPENAI_API_KEY
      timeout: 0.001
router_settings:
  num_retries: 0
  cooldown_time: 60
  allowed_fails: 1
general_settings:
  master_key: sk-c24-master

lone_no_allowed_fails.yaml

model_list:
  - model_name: nano-single
    litellm_params:
      model: openai/gpt-5.4-nano
      api_key: os.environ/OPENAI_API_KEY
      timeout: 0.001
router_settings:
  num_retries: 0
  cooldown_time: 60
general_settings:
  master_key: sk-c24-master

fallback.yaml

model_list:
  - model_name: nano-primary
    litellm_params:
      model: openai/gpt-5.4-nano
      api_key: os.environ/OPENAI_API_KEY
      timeout: 0.001
    model_info:
      id: nano-primary-timeout
  - model_name: nano-backup
    litellm_params:
      model: openai/gpt-5.4-nano
      api_key: os.environ/OPENAI_API_KEY
    model_info:
      id: nano-backup-healthy
router_settings:
  num_retries: 0
  cooldown_time: 60
  allowed_fails: 1
  fallbacks: [{"nano-primary": ["nano-backup"]}]
general_settings:
  master_key: sk-c24-master

pair.yaml

model_list:
  - model_name: nano-pair
    litellm_params:
      model: openai/gpt-5.4-nano
      api_key: os.environ/OPENAI_API_KEY
      timeout: 0.001
    model_info:
      id: nano-timeout
  - model_name: nano-pair
    litellm_params:
      model: openai/gpt-5.4-nano
      api_key: os.environ/OPENAI_API_KEY
    model_info:
      id: nano-healthy
router_settings:
  num_retries: 0
  cooldown_time: 60
  allowed_fails: 1
general_settings:
  master_key: sk-c24-master

Before (5667ac8)

Lone deployment with allowed_fails: 1 (the ticket)

  1. Proxy: uv run --no-sync litellm --config lone.yaml --detailed_debug --port 4000 with Postgres up and OPENAI_API_KEY in the environment
  2. Client, the ticket's sequence (three calls that time out at 0.001s, then one with "timeout": 600 in the body):
for i in 1 2 3; do curl -s http://127.0.0.1:4000/v1/chat/completions -H 'Authorization: Bearer sk-c24-master' -H 'Content-Type: application/json' -d '{"model":"nano-single","messages":[{"role":"user","content":"say ok"}],"max_completion_tokens":16}'; echo; done
curl -s -w '\nHTTP %{http_code} in %{time_total}s\n' http://127.0.0.1:4000/v1/chat/completions -H 'Authorization: Bearer sk-c24-master' -H 'Content-Type: application/json' -d '{"model":"nano-single","messages":[{"role":"user","content":"say ok"}],"max_completion_tokens":16,"timeout":600}'
  1. Output (each body cut to one line):
{"error":{"message":"litellm.Timeout: APITimeoutError - Request timed out. Error_str: Request timed out. - timeout value=0.001, time taken=0.01 seconds\n\nDeployment Info: request_timeout: None\ntimeout: 0.001\nstream_timeout: Non ...
{"error":{"message":"litellm.Timeout: APITimeoutError - Request timed out. Error_str: Request timed out. - timeout value=0.001, time taken=0.0 seconds\n\nDeployment Info: request_timeout: None\ntimeout: 0.001\nstream_timeout: None ...
{"error":{"message":"No deployments available for selected model, Try again in 60 seconds. All deployments for selected model are in cooldown. Passed model=nano-single. pre-call-checks=False, cooldown_list=['cd99940299e8ee397716ca ...
{"error":{"message":"No deployments available for selected model, Try again in 60 seconds. All deployments for selected model are in cooldown. Passed model=nano-single. pre-call-checks=False, cooldown_list=['cd99940299e8ee397716ca ...
HTTP 429 in 0.048857s
  1. Proxy log, cooldown lines:
      2 19:54:42 - LiteLLM Router:DEBUG: router.py:16686 - cooldown deployments: ['cd99940299e8ee397716ca8e16e8b8bae637236166a93c01fe0f0286045a082b']
      2 19:54:42 - LiteLLM Router:DEBUG: router.py:15054 - cooldown deployments: ['cd99940299e8ee397716ca8e16e8b8bae637236166a93c01fe0f0286045a082b']
  1. Spend rows, 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:
        startTime        | status  |  call_type  |        model        | error_code | spend 
-------------------------+---------+-------------+---------------------+------------+-------
 2026-10-27 19:54:42.799 | failure | acompletion | nano-single         | 429        |     0
 2026-10-27 19:54:42.746 | failure | acompletion | nano-single         | 429        |     0
 2026-10-27 19:54:42.648 | failure | acompletion | openai/gpt-5.4-nano | 408        |     0
 2026-10-27 19:54:42.16  | failure | acompletion | openai/gpt-5.4-nano | 408        |     0
(4 rows)

Lone deployment with allowed_fails removed

  1. Proxy: uv run --no-sync litellm --config lone_no_allowed_fails.yaml --detailed_debug --port 4000 with Postgres up and OPENAI_API_KEY in the environment
  2. Client, the ticket's sequence (three calls that time out at 0.001s, then one with "timeout": 600 in the body):
for i in 1 2 3; do curl -s http://127.0.0.1:4000/v1/chat/completions -H 'Authorization: Bearer sk-c24-master' -H 'Content-Type: application/json' -d '{"model":"nano-single","messages":[{"role":"user","content":"say ok"}],"max_completion_tokens":16}'; echo; done
curl -s -w '\nHTTP %{http_code} in %{time_total}s\n' http://127.0.0.1:4000/v1/chat/completions -H 'Authorization: Bearer sk-c24-master' -H 'Content-Type: application/json' -d '{"model":"nano-single","messages":[{"role":"user","content":"say ok"}],"max_completion_tokens":16,"timeout":600}'
  1. Output (each body cut to one line):
{"error":{"message":"litellm.Timeout: APITimeoutError - Request timed out. Error_str: Request timed out. - timeout value=0.001, time taken=0.0 seconds\n\nDeploy
{"error":{"message":"litellm.Timeout: APITimeoutError - Request timed out. Error_str: Request timed out. - timeout value=0.001, time taken=0.0 seconds\n\nDeploy
{"error":{"message":"litellm.Timeout: APITimeoutError - Request timed out. Error_str: Request timed out. - timeout value=0.001, time taken=0.0 seconds\n\nDeploy
{"id":"chatcmpl-EdhYeDswGehFxleqeIi5He6dbFOg2","created":1793130936,"model":"nano-single","object":"chat.completion","choices":[{"finish_reason":"stop","index":
HTTP 200 in 0.938481s
  1. Proxy log, cooldown lines:
(no deployment entered cooldown, every 'cooldown deployments' line reads [])
  1. Spend rows, 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:
        startTime        | status  |  call_type  |        model        | error_code |         spend         
-------------------------+---------+-------------+---------------------+------------+-----------------------
 2026-10-27 19:55:36.249 | success | acompletion | openai/gpt-5.4-nano |            | 7.850000000000001e-06
 2026-10-27 19:55:36.121 | failure | acompletion | openai/gpt-5.4-nano | 408        |                     0
 2026-10-27 19:55:36.013 | failure | acompletion | openai/gpt-5.4-nano | 408        |                     0
 2026-10-27 19:55:35.505 | failure | acompletion | openai/gpt-5.4-nano | 408        |                     0
(4 rows)

Two deployment group with allowed_fails: 1

  1. Proxy: uv run --no-sync litellm --config pair.yaml --detailed_debug --port 4000, two deployments in nano-pair, nano-timeout (timeout 0.001) and nano-healthy, allowed_fails: 1
  2. Client, ten calls printing the status, the deployment that answered and the seconds taken:
for i in $(seq 1 10); do
  out=$(curl -s -D - -o /dev/null -w "HTTP %{http_code} %{time_total}s" http://127.0.0.1:4000/v1/chat/completions -H 'Authorization: Bearer sk-c24-master' -H 'Content-Type: application/json' -d '{"model":"nano-pair","messages":[{"role":"user","content":"say ok"}],"max_completion_tokens":16}')
  echo "call $i: $(echo "$out" | tail -1) model_id=$(echo "$out" | grep -i '^x-litellm-model-id' | awk '{print $2}' | tr -d '\r')"
done
  1. Output:
call 1: HTTP 200 1.391101s model_id=nano-healthy
call 2: HTTP 408 0.493729s model_id=nano-timeout
call 3: HTTP 200 0.783843s model_id=nano-healthy
call 4: HTTP 200 0.580061s model_id=nano-healthy
call 5: HTTP 408 0.100200s model_id=nano-timeout
call 6: HTTP 200 0.623660s model_id=nano-healthy
call 7: HTTP 200 0.779572s model_id=nano-healthy
call 8: HTTP 200 0.634830s model_id=nano-healthy
call 9: HTTP 200 0.568184s model_id=nano-healthy
call 10: HTTP 200 0.496839s model_id=nano-healthy
  1. Proxy log, cooldown lines:
      2 19:56:56 - LiteLLM Router:DEBUG: router.py:16686 - cooldown deployments: ['nano-timeout']
      2 19:56:56 - LiteLLM Router:DEBUG: router.py:15054 - cooldown deployments: ['nano-timeout']
  1. Spend rows, SELECT "startTime", status, model_id, metadata::jsonb->'error_information'->>'error_code' AS error_code, spend FROM "LiteLLM_SpendLogs" ORDER BY "startTime" DESC LIMIT 10:
        startTime        | status  |   model_id   | error_code |         spend         
-------------------------+---------+--------------+------------+-----------------------
 2026-10-27 19:56:56.603 | success | nano-healthy |            |               6.6e-06
 2026-10-27 19:56:56.022 | success | nano-healthy |            | 7.850000000000001e-06
 2026-10-27 19:56:55.413 | success | nano-healthy |            |               6.6e-06
 2026-10-27 19:56:54.623 | success | nano-healthy |            | 7.850000000000001e-06
 2026-10-27 19:56:53.975 | success | nano-healthy |            |               6.6e-06
 2026-10-27 19:56:53.821 | failure | nano-timeout | 408        |               1.8e-06
 2026-10-27 19:56:53.256 | success | nano-healthy |            |               6.6e-06
 2026-10-27 19:56:52.456 | success | nano-healthy |            |               6.6e-06
 2026-10-27 19:56:51.933 | failure | nano-timeout | 408        |               1.8e-06
 2026-10-27 19:56:50.801 | success | nano-healthy |            | 7.850000000000001e-06
(10 rows)

Lone primary with a fallback group and allowed_fails: 1

  1. Proxy: uv run --no-sync litellm --config fallback.yaml --detailed_debug --port 4000, one nano-primary deployment (timeout 0.001), fallbacks: [{"nano-primary": ["nano-backup"]}], allowed_fails: 1
  2. Client, six calls to nano-primary:
for i in $(seq 1 6); do
  out=$(curl -s -D - -o /dev/null -w "HTTP %{http_code} %{time_total}s" http://127.0.0.1:4000/v1/chat/completions -H 'Authorization: Bearer sk-c24-master' -H 'Content-Type: application/json' -d '{"model":"nano-primary","messages":[{"role":"user","content":"say ok"}],"max_completion_tokens":16}')
  echo "call $i: $(echo "$out" | tail -1) model_id=$(echo "$out" | grep -i '^x-litellm-model-id' | awk '{print $2}' | tr -d '\r')"
done
  1. Output:
call 1: HTTP 200 1.197627s model_id=nano-backup-healthy
call 2: HTTP 200 0.923050s model_id=nano-backup-healthy
call 3: HTTP 200 0.697099s model_id=nano-backup-healthy
call 4: HTTP 200 1.002869s model_id=nano-backup-healthy
call 5: HTTP 429 0.176897s model_id=
call 6: HTTP 429 0.139840s model_id=
  1. Proxy log, cooldown lines:
      4 20:53:15 - LiteLLM Router:DEBUG: router.py:16686 - cooldown deployments: ['nano-primary-timeout', 'nano-backup-healthy']
      4 20:53:15 - LiteLLM Router:DEBUG: router.py:15054 - cooldown deployments: ['nano-primary-timeout', 'nano-backup-healthy']
  1. Spend rows, SELECT "startTime", status, model_id, metadata::jsonb->'error_information'->>'error_code' AS error_code, spend FROM "LiteLLM_SpendLogs" ORDER BY "startTime" DESC LIMIT n:
        startTime        | status  |      model_id       | error_code |         spend         
-------------------------+---------+---------------------+------------+-----------------------
 2026-10-27 20:53:15.804 | failure |                     | 429        |                     0
 2026-10-27 20:53:15.615 | failure |                     | 429        |                     0
 2026-10-27 20:53:14.644 | success | nano-backup-healthy |            | 7.850000000000001e-06
 2026-10-27 20:53:13.929 | success | nano-backup-healthy |            | 7.850000000000001e-06
 2026-10-27 20:53:13.048 | success | nano-backup-healthy |            |               6.6e-06
 2026-10-27 20:53:12.033 | success | nano-backup-healthy |            | 7.850000000000001e-06
(6 rows)

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)

  1. Proxy: uv run --no-sync litellm --config lone.yaml --detailed_debug --port 4000 with Postgres up and OPENAI_API_KEY in the environment
  2. Client, the ticket's sequence (three calls that time out at 0.001s, then one with "timeout": 600 in the body):
for i in 1 2 3; do curl -s http://127.0.0.1:4000/v1/chat/completions -H 'Authorization: Bearer sk-c24-master' -H 'Content-Type: application/json' -d '{"model":"nano-single","messages":[{"role":"user","content":"say ok"}],"max_completion_tokens":16}'; echo; done
curl -s -w '\nHTTP %{http_code} in %{time_total}s\n' http://127.0.0.1:4000/v1/chat/completions -H 'Authorization: Bearer sk-c24-master' -H 'Content-Type: application/json' -d '{"model":"nano-single","messages":[{"role":"user","content":"say ok"}],"max_completion_tokens":16,"timeout":600}'
  1. Output (each body cut to one line):
{"error":{"message":"litellm.Timeout: APITimeoutError - Request timed out. Error_str: Request timed out. - timeout value=0.001, time taken=0.0 seconds\n\nDeployment Info: request_timeout: None\ntimeout: 0.001\nstream_timeout: None ...
{"error":{"message":"litellm.Timeout: APITimeoutError - Request timed out. Error_str: Request timed out. - timeout value=0.001, time taken=0.0 seconds\n\nDeployment Info: request_timeout: None\ntimeout: 0.001\nstream_timeout: None ...
{"error":{"message":"litellm.Timeout: APITimeoutError - Request timed out. Error_str: Request timed out. - timeout value=0.001, time taken=0.0 seconds\n\nDeployment Info: request_timeout: None\ntimeout: 0.001\nstream_timeout: None ...
{"id":"chatcmpl-Edh98qzyRomR5ZeTAXxDRqlznvcWW","created":1793129354,"model":"nano-single","object":"chat.completion","choices":[{"finish_reason":"stop","index":0,"message":{"content":"Ok","role":"assistant","annotations":[],"refus ...
HTTP 200 in 0.700807s
  1. Proxy log, cooldown lines:
(no deployment entered cooldown, every 'cooldown deployments' line reads [])
  1. Spend rows, 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:
        startTime        | status  |  call_type  |        model        | error_code |  spend  
-------------------------+---------+-------------+---------------------+------------+---------
 2026-10-27 19:29:13.651 | success | acompletion | openai/gpt-5.4-nano |            | 6.6e-06
 2026-10-27 19:29:13.527 | failure | acompletion | openai/gpt-5.4-nano | 408        |       0
 2026-10-27 19:29:13.422 | failure | acompletion | openai/gpt-5.4-nano | 408        |       0
 2026-10-27 19:29:12.917 | failure | acompletion | openai/gpt-5.4-nano | 408        |       0
(4 rows)

Lone deployment with allowed_fails removed

  1. Proxy: uv run --no-sync litellm --config lone_no_allowed_fails.yaml --detailed_debug --port 4000 with Postgres up and OPENAI_API_KEY in the environment
  2. Client, the ticket's sequence (three calls that time out at 0.001s, then one with "timeout": 600 in the body):
for i in 1 2 3; do curl -s http://127.0.0.1:4000/v1/chat/completions -H 'Authorization: Bearer sk-c24-master' -H 'Content-Type: application/json' -d '{"model":"nano-single","messages":[{"role":"user","content":"say ok"}],"max_completion_tokens":16}'; echo; done
curl -s -w '\nHTTP %{http_code} in %{time_total}s\n' http://127.0.0.1:4000/v1/chat/completions -H 'Authorization: Bearer sk-c24-master' -H 'Content-Type: application/json' -d '{"model":"nano-single","messages":[{"role":"user","content":"say ok"}],"max_completion_tokens":16,"timeout":600}'
  1. Output (each body cut to one line):
{"error":{"message":"litellm.Timeout: APITimeoutError - Request timed out. Error_str: Request timed out. - timeout value=0.001, time taken=0.0 seconds\n\nDeploy
{"error":{"message":"litellm.Timeout: APITimeoutError - Request timed out. Error_str: Request timed out. - timeout value=0.001, time taken=0.0 seconds\n\nDeploy
{"error":{"message":"litellm.Timeout: APITimeoutError - Request timed out. Error_str: Request timed out. - timeout value=0.001, time taken=0.0 seconds\n\nDeploy
{"id":"chatcmpl-EdhVVeR7iSTSZIOoLax6TsT9MXYVP","created":1793130741,"model":"nano-single","object":"chat.completion","choices":[{"finish_reason":"stop","index":
HTTP 200 in 0.996744s
  1. Proxy log, cooldown lines:
(no deployment entered cooldown, every 'cooldown deployments' line reads [])
  1. Spend rows, 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:
        startTime        | status  |  call_type  |        model        | error_code |         spend         
-------------------------+---------+-------------+---------------------+------------+-----------------------
 2026-10-27 19:52:20.576 | success | acompletion | openai/gpt-5.4-nano |            | 7.850000000000001e-06
 2026-10-27 19:52:20.463 | failure | acompletion | openai/gpt-5.4-nano | 408        |                     0
 2026-10-27 19:52:20.367 | failure | acompletion | openai/gpt-5.4-nano | 408        |                     0
 2026-10-27 19:52:19.895 | failure | acompletion | openai/gpt-5.4-nano | 408        |                     0
(4 rows)

Two deployment group with allowed_fails: 1

  1. Proxy: uv run --no-sync litellm --config pair.yaml --detailed_debug --port 4000, two deployments in nano-pair, nano-timeout (timeout 0.001) and nano-healthy, allowed_fails: 1
  2. Client, ten calls printing the status, the deployment that answered and the seconds taken:
for i in $(seq 1 10); do
  out=$(curl -s -D - -o /dev/null -w "HTTP %{http_code} %{time_total}s" http://127.0.0.1:4000/v1/chat/completions -H 'Authorization: Bearer sk-c24-master' -H 'Content-Type: application/json' -d '{"model":"nano-pair","messages":[{"role":"user","content":"say ok"}],"max_completion_tokens":16}')
  echo "call $i: $(echo "$out" | tail -1) model_id=$(echo "$out" | grep -i '^x-litellm-model-id' | awk '{print $2}' | tr -d '\r')"
done
  1. Output:
call 1: HTTP 408 0.957028s model_id=nano-timeout
call 2: HTTP 408 0.092372s model_id=nano-timeout
call 3: HTTP 200 0.996753s model_id=nano-healthy
call 4: HTTP 200 0.729541s model_id=nano-healthy
call 5: HTTP 200 0.785419s model_id=nano-healthy
call 6: HTTP 200 0.630707s model_id=nano-healthy
call 7: HTTP 200 0.797208s model_id=nano-healthy
call 8: HTTP 200 0.897692s model_id=nano-healthy
call 9: HTTP 200 2.866882s model_id=nano-healthy
call 10: HTTP 200 0.975720s model_id=nano-healthy
  1. Proxy log, cooldown lines:
      2 19:53:29 - LiteLLM Router:DEBUG: router.py:16686 - cooldown deployments: ['nano-timeout']
      2 19:53:29 - LiteLLM Router:DEBUG: router.py:15054 - cooldown deployments: ['nano-timeout']
      1 19:53:34 - LiteLLM Router:DEBUG: router.py:16686 - cooldown deployments: ['nano-timeout']
      1 19:53:34 - LiteLLM Router:DEBUG: router.py:15054 - cooldown deployments: ['nano-timeout']
  1. Spend rows, SELECT "startTime", status, model_id, metadata::jsonb->'error_information'->>'error_code' AS error_code, spend FROM "LiteLLM_SpendLogs" ORDER BY "startTime" DESC LIMIT 10:
        startTime        | status  |   model_id   | error_code |         spend         
-------------------------+---------+--------------+------------+-----------------------
 2026-10-27 19:53:34.308 | success | nano-healthy |            | 7.850000000000001e-06
 2026-10-27 19:53:31.434 | success | nano-healthy |            |               6.6e-06
 2026-10-27 19:53:30.522 | success | nano-healthy |            | 7.850000000000001e-06
 2026-10-27 19:53:29.721 | success | nano-healthy |            | 7.850000000000001e-06
 2026-10-27 19:53:29.114 | success | nano-healthy |            | 7.850000000000001e-06
 2026-10-27 19:53:28.316 | success | nano-healthy |            |               6.6e-06
 2026-10-27 19:53:27.539 | success | nano-healthy |            |               6.6e-06
 2026-10-27 19:53:26.531 | success | nano-healthy |            | 7.850000000000001e-06
 2026-10-27 19:53:26.41  | failure | nano-timeout | 408        |                     0
 2026-10-27 19:53:25.562 | failure | nano-timeout | 408        |                     0
(10 rows)

Lone primary with a fallback group and allowed_fails: 1

  1. Proxy: uv run --no-sync litellm --config fallback.yaml --detailed_debug --port 4000, one nano-primary deployment (timeout 0.001), fallbacks: [{"nano-primary": ["nano-backup"]}], allowed_fails: 1
  2. Client, six calls to nano-primary:
for i in $(seq 1 6); do
  out=$(curl -s -D - -o /dev/null -w "HTTP %{http_code} %{time_total}s" http://127.0.0.1:4000/v1/chat/completions -H 'Authorization: Bearer sk-c24-master' -H 'Content-Type: application/json' -d '{"model":"nano-primary","messages":[{"role":"user","content":"say ok"}],"max_completion_tokens":16}')
  echo "call $i: $(echo "$out" | tail -1) model_id=$(echo "$out" | grep -i '^x-litellm-model-id' | awk '{print $2}' | tr -d '\r')"
done
  1. Output:
call 1: HTTP 200 1.281711s model_id=nano-backup-healthy
call 2: HTTP 200 0.937065s model_id=nano-backup-healthy
call 3: HTTP 200 0.539697s model_id=nano-backup-healthy
call 4: HTTP 200 1.071940s model_id=nano-backup-healthy
call 5: HTTP 200 0.657093s model_id=nano-backup-healthy
call 6: HTTP 200 0.751047s model_id=nano-backup-healthy
  1. Proxy log, cooldown lines:
      2 20:50:57 - LiteLLM Router:DEBUG: router.py:16686 - cooldown deployments: ['nano-primary-timeout']
      2 20:50:57 - LiteLLM Router:DEBUG: router.py:15054 - cooldown deployments: ['nano-primary-timeout']
  1. Spend rows, SELECT "startTime", status, model_id, metadata::jsonb->'error_information'->>'error_code' AS error_code, spend FROM "LiteLLM_SpendLogs" ORDER BY "startTime" DESC LIMIT n:
        startTime        | status  |      model_id       | error_code |         spend         
-------------------------+---------+---------------------+------------+-----------------------
 2026-10-27 20:50:57.198 | success | nano-backup-healthy |            | 7.850000000000001e-06
 2026-10-27 20:50:56.531 | success | nano-backup-healthy |            | 7.850000000000001e-06
 2026-10-27 20:50:55.449 | success | nano-backup-healthy |            | 7.850000000000001e-06
 2026-10-27 20:50:54.901 | success | nano-backup-healthy |            |               6.6e-06
 2026-10-27 20:50:53.984 | success | nano-backup-healthy |            | 7.850000000000001e-06
 2026-10-27 20:50:52.837 | success | nano-backup-healthy |            |               6.6e-06
 2026-10-27 19:56:56.603 | success | nano-healthy        |            |               6.6e-06
 2026-10-27 19:56:56.022 | success | nano-healthy        |            | 7.850000000000001e-06
(8 rows)

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 siblings

Type

🐛 Bug Fix

Caveats (if any)

Medium

  • an operator who used router allowed_fails to bench a lone deployment on purpose loses that, the After lone case above shows every call now reaches the provider
    • allowed_fails_policy with the exception type named (TimeoutErrorAllowedFails: 1) keeps the bench, covered by the policy_names_timeout unit case

Low

  • a router allowed_fails_policy that does not name the failing exception type also leaves a lone deployment warm now, matching the deployment level rule, covered by the policy_names_another_exception unit case
  • the new integration test first runs on main after merge, CircleCI does not run tests/integration on pull requests
  • the fallback case of that test asserts the fell-back and later calls reached the backup and that the primary saw at most one call after its cooldown, not that the backup wire saw nothing else, since one extra marker from the earlier two deployment phase showed up on the backup wire in local runs

Final Attestation

  • The tests check the right things, including the edge cases, and regressions in the respective real-world customer use-cases are not possible after this PR

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_fails on single-deployment groups (no more 429 benching without an explicit per-exception policy); operators who relied on that for load shedding need allowed_fails_policy instead.

Overview
Aligns router-level allowed_fails with deployment-level behavior so a lone deployment (one member in its model group and no fallbacks entry for that group) is not benched from a plain failure count alone.

_should_cooldown_deployment now defines is_lone_deployment via new _has_fallback_group (parses router fallbacks with get_fallback_model_group) and uses it instead of only “single deployment in group” when applying deployment-policy skips and the router allowed_fails branch. Under router allowed_fails / generic policy, lone deployments stay warm unless allowed_fails_policy names 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_fails is 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=0 can 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.

…nless the policy names the exception

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@devin-ai-integration

Copy link
Copy Markdown
Contributor

I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".

  • Disable automatic comment, CI, and merge conflict monitoring

@codspeed

codspeed Bot commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

1 warning

⚠️ 1 benchmark is dominated by system calls

System calls cannot be simulated consistently and are left out of the measure. The reported value understates the real cost. Switch to the Walltime instrument to measure them.

Learn more about system calls

See affected benchmarks

✅ 35 untouched benchmarks


Comparing litellm_lone_deployment_router_allowed_fails (874b128) with main (a53ea5b)1

Open in CodSpeed

Footnotes

  1. No successful run was found on main (ad4b35d) during the generation of this report, so a53ea5b was used instead as the comparison base. There might be some changes unrelated to this pull request in this report. ↩

@codecov

codecov Bot commented Oct 27, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@kerry-berri

Copy link
Copy Markdown
Contributor Author

@greptileai

@kerry-berri

Copy link
Copy Markdown
Contributor Author

@BugBot run

@joshua-berri joshua-berri left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@greptile-apps

greptile-apps Bot commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The latest changes appear safe to merge, with no new actionable issues found

Summary

Router allowed_fails now keeps a lone deployment warm unless a policy names the failing exception. Deployments with siblings or configured fallbacks can still enter cooldown

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 allowed_fails_policy preserves cooldown

The previous title-format thread was manually resolved without explanation. All supplied previous threads were unnumbered

  • A lone deployment stays available unless its policy names the failure.

Reviews (3) · Last reviewed commit: "fix(router): accept dictionary fallback ..." · Reviewed by Greptile

@cursor cursor Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale Bugbot comment from a previous run.

@kerry-berri

Copy link
Copy Markdown
Contributor Author

@greptileai

@kerry-berri

Copy link
Copy Markdown
Contributor Author

@BugBot run

@cursor cursor Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale Bugbot comment from a previous run.

…t check

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@devin-ai-integration
devin-ai-integration Bot force-pushed the litellm_lone_deployment_router_allowed_fails branch from 2ae458e to 874b128 Compare October 27, 2026 21:46
@kerry-berri

Copy link
Copy Markdown
Contributor Author

@greptileai

@kerry-berri

Copy link
Copy Markdown
Contributor Author

@BugBot run

@cursor cursor Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ 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.

@kerry-berri
kerry-berri merged commit 8f31c71 into main Oct 27, 2026
144 of 147 checks passed
@kerry-berri
kerry-berri deleted the litellm_lone_deployment_router_allowed_fails branch October 27, 2026 22:12
mateo-berri added a commit to HardMax71/litellm that referenced this pull request Oct 28, 2026
…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.
yuneng-berri added a commit that referenced this pull request Oct 30, 2026
…ed changes (#49310)

Seven integration tests fail on main for reasons that are not product bugs. Two are order or race bugs in the tests, one reads rows other tests wrote, one passed on an error body, and three still expect behavior that #48644, #39864 and #39540 changed on purpose
DeoLeung pushed a commit to aiyou178/litellm that referenced this pull request Nov 7, 2026
…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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants