litellm/tests/unit/test_router/core
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
..
__init__.py
conftest.py refactor(router): delete the python router core, the rust core is the only core (#50178) 2026-11-05 10:40:46 -08:00
construction_precall_helpers.py feat(router): add the Rust router core with the host as its only boundary (#49513) 2026-11-04 21:47:58 -08:00
endpoints_helpers.py feat(router): add the Rust router core with the host as its only boundary (#49513) 2026-11-04 21:47:58 -08:00
fallbacks_helpers.py feat(router): add the Rust router core with the host as its only boundary (#49513) 2026-11-04 21:47:58 -08:00
gaps_l11100_helpers.py feat(router): add the Rust router core with the host as its only boundary (#49513) 2026-11-04 21:47:58 -08:00
registry_helpers.py feat(router): add the Rust router core with the host as its only boundary (#49513) 2026-11-04 21:47:58 -08:00
retries_health_helpers.py feat(router): add the Rust router core with the host as its only boundary (#49513) 2026-11-04 21:47:58 -08:00
rust_parity_pending.txt feat(router): add the Rust router core with the host as its only boundary (#49513) 2026-11-04 21:47:58 -08:00
scripted_host.py fix(router): free a failed rust router call's request without waiting for a full gc (#51963) 2026-11-15 17:04:38 -05:00
selection_helpers.py feat(router): add the Rust router core with the host as its only boundary (#49513) 2026-11-04 21:47:58 -08:00
streaming_helpers.py feat(router): add the Rust router core with the host as its only boundary (#49513) 2026-11-04 21:47:58 -08:00
test_callback_filters_step.py perf(router): skip unused deployment reads in the callback filter step and cache anthropic capability probes (#50641) 2026-11-08 17:59:55 -08:00
test_callback_filters_v2_dispatch.py feat(custom-logger-v2): add the contract for rust callbacks and bind the proxy request scope (#51526) 2026-11-14 02:33:27 +00:00
test_construction_precall_characterization.py fix(router): give the rust core's priority scheduler the router's redis cache (#50265) 2026-11-06 08:50:42 +09:00
test_construction_precall_characterization_precall.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_deprecated_members.py fix(router): re-check and reserve per-model rate limits on fallback targets (#50994) 2026-11-10 16:36:10 -08:00
test_endpoints.py fix(router): free a failed rust router call's request without waiting for a full gc (#51963) 2026-11-15 17:04:38 -05:00
test_endpoints_characterization_batch.py feat(proxy): let teams use their own allowed S3 buckets for batch files (#50571) 2026-11-10 11:06:17 -08:00
test_endpoints_characterization_generic.py feat(bedrock): search knowledge bases by image and return image hits (#51063) 2026-11-12 00:19:34 +00:00
test_endpoints_characterization_inference.py fix(azure_ai): send reasoning_effort to Foundry reasoning models (#51775) 2026-11-16 16:40:16 -08:00
test_fallbacks.py fix(router): honor fallback opt-out for 413 and 422 bad requests (#52195) 2026-11-16 21:51:23 -08:00
test_fallbacks_characterization.py fix(router): validate request fields and ignore scalar fallback overrides (#51502) 2026-11-13 01:24:23 +00:00
test_fallbacks_characterization_outcomes.py feat(router): add the Rust router core with the host as its only boundary (#49513) 2026-11-04 21:47:58 -08:00
test_fallbacks_characterization_refusal.py feat(router): add the Rust router core with the host as its only boundary (#49513) 2026-11-04 21:47:58 -08:00
test_fallbacks_walk_parity.py feat(redis): serve the router's session pins from a native store (#50870) 2026-11-13 03:22:28 +00:00
test_gaps_adapter_timeout.py feat(router): add the Rust router core with the host as its only boundary (#49513) 2026-11-04 21:47:58 -08:00
test_gaps_fuzz_access.py feat(router): add the Rust router core with the host as its only boundary (#49513) 2026-11-04 21:47:58 -08:00
test_gaps_l0001.py fix(proxy): serve Codex its own Bedrock catalog entries for Bedrock deployments (#50743) 2026-11-09 19:00:22 -08:00
test_gaps_l2800.py fix(router)!: stop a client's metadata flag from turning off silent_model mirroring (#52083) 2026-11-16 15:45:56 -08:00
test_gaps_l2800_streaming.py feat(router): add the Rust router core with the host as its only boundary (#49513) 2026-11-04 21:47:58 -08:00
test_gaps_l5600.py feat(router): add the Rust router core with the host as its only boundary (#49513) 2026-11-04 21:47:58 -08:00
test_gaps_l5600_anthropic.py feat(router): add the Rust router core with the host as its only boundary (#49513) 2026-11-04 21:47:58 -08:00
test_gaps_l8400_precall.py feat(router): add the Rust router core with the host as its only boundary (#49513) 2026-11-04 21:47:58 -08:00
test_gaps_l8400_pricing.py feat(router): add the Rust router core with the host as its only boundary (#49513) 2026-11-04 21:47:58 -08:00
test_gaps_l8400_retries.py feat(router): add the Rust router core with the host as its only boundary (#49513) 2026-11-04 21:47:58 -08:00
test_gaps_l11100_registry.py feat(router): add the Rust router core with the host as its only boundary (#49513) 2026-11-04 21:47:58 -08:00
test_gaps_l11100_strategy.py fix(management): keep classifier deployments serving during reloads (#51111) 2026-11-11 18:48:06 +00:00
test_gaps_l14000.py feat(router): add the Rust router core with the host as its only boundary (#49513) 2026-11-04 21:47:58 -08:00
test_gaps_l14000_selection.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_gaps_pick_input_and_compaction.py feat(router): add the Rust router core with the host as its only boundary (#49513) 2026-11-04 21:47:58 -08:00
test_gaps_request_overrides.py feat(router): add the Rust router core with the host as its only boundary (#49513) 2026-11-04 21:47:58 -08:00
test_gaps_router_core_crate.py feat(router): add the Rust router core with the host as its only boundary (#49513) 2026-11-04 21:47:58 -08:00
test_gaps_router_core_crate_picks.py feat(router): add the Rust router core with the host as its only boundary (#49513) 2026-11-04 21:47:58 -08:00
test_health_registry_views.py feat(router): add the Rust router core with the host as its only boundary (#49513) 2026-11-04 21:47:58 -08:00
test_host_settings_changes_characterization.py feat(router): add the Rust router core with the host as its only boundary (#49513) 2026-11-04 21:47:58 -08:00
test_legacy_members.py feat(redis): serve the proxy's common Redis call with Rust stores (#50170) 2026-11-06 06:01:11 +00:00
test_parity_cooldown_service_model.py feat(router): add the Rust router core with the host as its only boundary (#49513) 2026-11-04 21:47:58 -08:00
test_parity_decisions_routing.py feat(router): add the Rust router core with the host as its only boundary (#49513) 2026-11-04 21:47:58 -08:00
test_parity_failure_logging.py feat(redis): serve the proxy's common Redis call with Rust stores (#50170) 2026-11-06 06:01:11 +00:00
test_parity_malformed_after_rate_limit.py feat(router): add the Rust router core with the host as its only boundary (#49513) 2026-11-04 21:47:58 -08:00
test_parity_pick_count_and_fallback_log.py feat(router): add the Rust router core with the host as its only boundary (#49513) 2026-11-04 21:47:58 -08:00
test_parity_provider_scoped_fallbacks.py feat(router): add the Rust router core with the host as its only boundary (#49513) 2026-11-04 21:47:58 -08:00
test_parity_regress5.py fix(bedrock)!: split the OpenAI breakpoint and Bedrock cachePoint model flags (#52180) 2026-11-16 18:50:32 -08:00
test_parity_regress5_errors.py fix(router): sync responses() applies the Router's num_retries and fallbacks (#51011) 2026-11-10 12:55:49 -08:00
test_parity_regress5_settings.py feat(router): add the Rust router core with the host as its only boundary (#49513) 2026-11-04 21:47:58 -08:00
test_parity_regress5_streams.py feat(router): add the Rust router core with the host as its only boundary (#49513) 2026-11-04 21:47:58 -08:00
test_parity_response_headers.py feat(router): add the Rust router core with the host as its only boundary (#49513) 2026-11-04 21:47:58 -08:00
test_parity_rulings_2026_11.py feat(redis): serve the health checks' deployment states from a native store (#50357) 2026-11-13 03:22:28 +00:00
test_registry_changesets.py feat(router): add the Rust router core with the host as its only boundary (#49513) 2026-11-04 21:47:58 -08:00
test_registry_characterization_construction.py feat(router): add the Rust router core with the host as its only boundary (#49513) 2026-11-04 21:47:58 -08:00
test_registry_characterization_lookups.py fix(router): hold the registry lock across router-core writes and mirror reads (#50933) 2026-11-10 17:58:46 +00:00
test_registry_characterization_model_info.py refactor(router): count the whole router_usage family on the native store (#50862) 2026-11-13 03:22:28 +00:00
test_registry_characterization_writes.py fix(management): keep classifier deployments serving during reloads (#51111) 2026-11-11 18:48:06 +00:00
test_request_scoped_outcomes.py feat(redis): serve the proxy's common Redis call with Rust stores (#50170) 2026-11-06 06:01:11 +00:00
test_retries_cooldowns.py feat(proxy): total_timeout bounds a whole non-streaming request (#50496) 2026-11-08 00:43:50 -08:00
test_retries_health_characterization_cooldowns.py feat(router): add the Rust router core with the host as its only boundary (#49513) 2026-11-04 21:47:58 -08:00
test_retries_health_characterization_failure_exits.py feat(router): add the Rust router core with the host as its only boundary (#49513) 2026-11-04 21:47:58 -08:00
test_retries_health_characterization_retries.py feat(router): add the Rust router core with the host as its only boundary (#49513) 2026-11-04 21:47:58 -08:00
test_selection.py feat(router): add the Rust router core with the host as its only boundary (#49513) 2026-11-04 21:47:58 -08:00
test_selection_characterization_groups.py feat(router): add the Rust router core with the host as its only boundary (#49513) 2026-11-04 21:47:58 -08:00
test_selection_characterization_prerouting.py feat(router): add the Rust router core with the host as its only boundary (#49513) 2026-11-04 21:47:58 -08:00
test_selection_characterization_session_repin.py feat(redis): serve the router's session pins from a native store (#50870) 2026-11-13 03:22:28 +00:00
test_selection_characterization_strategies.py feat(router): add the Rust router core with the host as its only boundary (#49513) 2026-11-04 21:47:58 -08:00
test_selection_characterization_traffic.py feat(router): add the Rust router core with the host as its only boundary (#49513) 2026-11-04 21:47:58 -08:00
test_streaming_characterization_anthropic.py fix(router): keep both errors when a streamed cross-group fallback also fails (#52217) 2026-11-16 22:04:16 -08:00
test_streaming_characterization_chat.py fix(router): map Gemini stream-opening errors (#51218) 2026-11-11 12:18:44 -08:00
test_streaming_characterization_outcomes.py feat(redis): serve the proxy's common Redis call with Rust stores (#50170) 2026-11-06 06:01:11 +00:00
test_streaming_characterization_responses.py fix(router): keep both errors when a streamed cross-group fallback also fails (#52217) 2026-11-16 22:04:16 -08:00
test_usage_and_failure_counting_parity.py fix(router): record retries and fallback hops past a request's first logged failure (#50445) 2026-11-06 19:48:25 -08:00