litellm/tests/unit/test_router
joshua-berri 2314e5e7d1
fix(router): keep both errors when a streamed cross-group fallback also fails (#52217)
* fix(router): keep both errors when a streamed cross-group fallback also fails

On /v1/messages and /v1/responses streams, a recovery walk appended the
fallback outcome to the MidStreamFallbackError envelope and the stream then
raised the inner provider error without it. A fallback hop whose stream opened
and then failed before any content never reached the walk, so the primary's
error was dropped. The outcome now lands on the surfaced error, and a fallback
hop's pre-content failure reads as the walk's own failure would.

* fix(proxy): keep the router fallback outcome in Responses response.failed events

The response.failed formatter preferred the upstream body message, so the
primary error and fallback outcome the router put on the exception never
reached the client. Use the exception message when it carries that outcome.

* fix(router): only add the primary error to a fallback stream's failure before any content

Count any chunk past message_start and pings, split or not, as content on
/v1/messages, track forwarded output events on Responses, and switch the
response.failed message only on a fallback-also-failed outcome.

* fix(router): scope the streamed fallback outcome to pre-content messages and Responses failures

Leave the router core and chat streams as they were. Carry the outcome the
walk put on the stream's envelope onto the provider error only before any
content, and read a fallback hop's /v1/messages stream as whole SSE frames so
split or merged chunks are judged by event, not by chunk.

* fix(router): keep a Responses stream's own error once it has sent output

A primary Responses stream that already sent output no longer lets its
fallback stream's failure read as the primary's. Keep CRLF line endings in a
rewritten error frame, and read a bridge chunk's type through a typed mapping.

* test(router): cover partial frames on a fallback stream's end and raise

* fix(router): carry the primary error through a fallback stream's retry and redact the combined frame

A fallback group's same-group stream retry keeps the fallback's error context,
every fallback-level /v1/messages stream is read as whole frames, and the
rewritten error frame goes through the client message redactor.

* fix(router): treat a cut-off message_start on a fallback stream as before content

* fix(router): redact the primary error and the fallback outcome separately before joining them

A traceback in the primary's error made the client redactor drop the fallback
outcome that followed it. Make the fallback-retry tests deterministic with a
single-deployment fallback group.

* test(router): cover a split error frame on a fallback group's retried stream

---------

Co-authored-by: Joshua Valluru <326636767+joshua-berri@users.noreply.github.com>
2026-11-16 22:04:16 -08:00
..
core fix(router): keep both errors when a streamed cross-group fallback also fails (#52217) 2026-11-16 22:04:16 -08:00
__init__.py
test_enforce_model_rate_limits.py refactor(router): count the whole router_usage family on the native store (#50862) 2026-11-13 03:22:28 +00:00
test_io_token_rate_limits.py refactor(router): count the whole router_usage family on the native store (#50862) 2026-11-13 03:22:28 +00:00
test_router.py perf(token_counter): memoize token counts of long texts per tokenizer (#51904) 2026-11-16 19:21:55 +00:00
test_router_callback_hook_sequence.py test: replace 61 live logging and otel tests with offline unit and integration coverage (#45362) 2026-10-08 15:55:57 -07:00
test_router_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_entry_points.py feat(proxy): mixed Codex model picker and LiteLLM routing on native codex routes (#49408) 2026-11-06 11:14:47 -08:00
test_router_facade.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_fallbacks.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_fuzz_regressions_rust_only.py ci(unit): cut unit check time with cheaper per-test resets and fewer non-unit tests (#51864) 2026-11-14 15:41:30 -08:00
test_router_get_deployments.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_helper_utils.py refactor(router): count the whole router_usage family on the native store (#50862) 2026-11-13 03:22:28 +00:00
test_router_host.py ci(unit): cut unit check time with cheaper per-test resets and fewer non-unit tests (#51864) 2026-11-14 15:41:30 -08:00
test_router_max_parallel_requests.py fix(health): log Test Connection spend with the mode's call type and model id (#50987) 2026-11-11 16:07:33 -08:00
test_router_provider_endpoints.py feat(redis): serve the proxy's common Redis call with Rust stores (#50170) 2026-11-06 06:01:11 +00:00
test_router_retries.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_surface_check.py chore: move workspace packages under litellm (#51000) 2026-11-12 04:19:57 +00:00
test_router_timeout.py feat(messages): serve bedrock invoke messages on rust only (#51330) 2026-11-15 16:58:31 -08:00
test_router_vector_store_endpoints.py test: migrate SDK and proxy-booting legacy CircleCI tests to their tiers (#45758) 2026-10-11 00:17:21 -07:00