litellm/tests/unit/router_utils
joshua-berri d801022c64
fix(router): let latency-routed sessions leave exhausted deployments (#54998)
* fix(router): let a latency-exhausted session pin fall back to the other deployments

With latency-based routing and session affinity, a session pinned to a
deployment that reached its rpm/tpm limit in the latency map got "No
deployments available" until the minute reset, because the pin narrowed
the candidates to that one deployment before the strategy rejected it.

When latency routing is the request's effective strategy (request override,
routing group or router default, under the name the pick keys its latency
map by), a session pin to a deployment that a pick among it alone would
reject now falls through to the healthy deployments, and a caller-key pin
to that same deployment is skipped too. previous_response_id and
encrypted-content pins still hold, and a pin check that fails keeps the
pin. The check is the selector's own pick over the pinned deployment, so it
reads the same counts and token estimate and takes the request input as
given.

With session_affinity_repin_on_failover on, a successful replacement moves
the declined pin; the declined id rides in the request's own metadata and
the proxy strips it from client metadata. Off by default, nothing changes.

* fix(router): check a session pin against the input its pick counts

A pick made through select() with its input passed beside the request
(router.async_get_available_deployment(..., input=...)) kept that input out
of the request kwargs, so the session pin check estimated no input tokens,
kept a pin whose tpm budget the input would overrun, and the strategy then
rejected it with no deployment left. The callback filters now receive the
pick's own messages and input, and the session pin check estimates from
that same input.

* fix(router): keep declined affinity metadata out of provider payloads

* fix(router): keep declined session pins in internal metadata

* test(router): isolate declined pin metadata assertions

* test(router): verify declined pin metadata isolation

* refactor(router): reuse existing selection for session pin admission

---------

Co-authored-by: Joshua Valluru <326636767+joshua-berri@users.noreply.github.com>
2026-11-30 15:20:25 -08:00
..
pre_call_checks fix(router): let latency-routed sessions leave exhausted deployments (#54998) 2026-11-30 15:20:25 -08:00
__init__.py
test_access_windows.py refactor(router): route the router family through RoutingContext and close the outside surface (#49118) 2026-10-30 19:18:54 -07:00
test_add_retry_fallback_headers.py fix(responses): accept a string or tuple allowed_openai_params on Responses models instead of answering 500 (#51751) 2026-11-14 04:32:38 -05:00
test_client_initalization_utils.py refactor(router): delete the python router core, the rust core is the only core (#50178) 2026-11-05 10:40:46 -08:00
test_cooldown_cache.py feat(redis): serve the proxy's common Redis call with Rust stores (#50170) 2026-11-06 06:01:11 +00:00
test_cooldown_handlers.py fix(ocr): report an unreachable document URL as a 400, not a provider 500 (#54215) 2026-11-26 07:56:58 +00:00
test_deployment_pricing.py refactor(router): route the router family through RoutingContext and close the outside surface (#49118) 2026-10-30 19:18:54 -07:00
test_dynamic_queue.py feat(router): add bounded congestion queue controller (#51883) 2026-11-17 17:15:24 -08:00
test_dynamic_queue_redis.py feat(router): coordinate congestion queues through Redis (#52367) 2026-11-17 19:29:39 -08:00
test_dynamic_queue_router.py fix(router): preserve destination bearer credentials on Anthropic fallbacks (#54271) 2026-11-24 17:12:02 -08:00
test_embedding_batch_size_check.py feat(embeddings): enforce per-request input batch limit (#44574) 2026-10-20 11:35:18 +00:00
test_endpoint_eligibility.py refactor(router): delete router code nothing calls (#52516) 2026-11-19 06:11:10 +09:00
test_fallback_event_handlers.py refactor(router): delete router code nothing calls (#52516) 2026-11-19 06:11:10 +09:00
test_fallback_event_v2_dispatch.py feat(custom-logger-v2): add types, dispatcher and route callback call sites (step 0) (#51214) 2026-11-13 22:08:05 +00:00
test_get_retry_from_policy.py fix(ocr): report an unreachable document URL as a 400, not a provider 500 (#54215) 2026-11-26 07:56:58 +00:00
test_handle_error.py refactor(router): delete router code nothing calls (#52516) 2026-11-19 06:11:10 +09:00
test_health_check_allowed_fails_integration.py feat(redis): serve the proxy's common Redis call with Rust stores (#50170) 2026-11-06 06:01:11 +00:00
test_health_state_cache.py feat(redis): serve the health checks' deployment states from a native store (#50357) 2026-11-13 03:22:28 +00:00
test_kubernetes_pod_discovery.py refactor(router): delete router code nothing calls (#52516) 2026-11-19 06:11:10 +09:00
test_pattern_match_deployments.py refactor(typing): clear 1146 basedpyright Any errors across 365 files (#52768) 2026-11-21 04:25:33 +00:00
test_prompt_caching_cache.py fix(logging): log Anthropic base64 sources on /v1/messages and pass-through routes as a size placeholder (#54161) 2026-11-24 12:13:09 -08:00
test_ptu_shares.py refactor(router): route the router family through RoutingContext and close the outside surface (#49118) 2026-10-30 19:18:54 -07:00
test_reasoning_effort_capability.py fix(openai): drop or refuse an o-series reasoning_effort level the model map turns off (#54066) 2026-11-24 06:42:03 -08:00
test_request_priority.py fix(openai): relay provider error codes, types, and Responses params from OpenAI-compatible backends (#51809) 2026-11-24 02:23:00 +00:00
test_router_health_check_routing.py refactor(router): delete the python router core, the rust core is the only core (#50178) 2026-11-05 10:40:46 -08:00
test_router_interactions_endpoints.py refactor(router): delete the python router core, the rust core is the only core (#50178) 2026-11-05 10:40:46 -08:00
test_router_utils_common_utils.py fix(responses): accept a string or tuple allowed_openai_params on Responses models instead of answering 500 (#51751) 2026-11-14 04:32:38 -05:00
test_routing_read_batch.py refactor(redis): delete the Python RedisBatch now that every request op is native (#51383) 2026-11-13 03:22:28 +00:00