litellm/tests/unit/proxy/proxy_server
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
..
.coverage_baseline test(proxy): move proxy_server, _experimental and db tests into tests/unit/proxy (#44012) 2026-10-01 18:14:24 +00:00
__init__.py test(proxy): move proxy_server, _experimental and db tests into tests/unit/proxy (#44012) 2026-10-01 18:14:24 +00:00
_coverage_check.py test(proxy): move proxy_server, _experimental and db tests into tests/unit/proxy (#44012) 2026-10-01 18:14:24 +00:00
_pin_check.py test(proxy): move proxy_server, _experimental and db tests into tests/unit/proxy (#44012) 2026-10-01 18:14:24 +00:00
conftest.py fix(azure): drop the traceback from stream-cut errors sent to clients and alerts (#51760) 2026-11-14 08:00:58 +00:00
test_background_health.py refactor(router): route the router family through RoutingContext and close the outside surface (#49118) 2026-10-30 19:18:54 -07:00
test_exception_handlers.py fix(anthropic_endpoints)!: return Anthropic error envelopes on /v1/messages auth failures (#48466) 2026-11-03 01:53:29 +00:00
test_harness_smoke.py test(proxy): move proxy_server, _experimental and db tests into tests/unit/proxy (#44012) 2026-10-01 18:14:24 +00:00
test_lifecycle.py feat(auth): decide key and JWT authentication in a Rust core (#51374) 2026-11-17 14:07:47 +09:00
test_openapi_customization.py refactor(typing): clear 1181 basedpyright Any errors across 431 files (#47789) 2026-10-24 11:31:09 -07:00
test_proxy_config.py feat(auth): decide key and JWT authentication in a Rust core (#51374) 2026-11-17 14:07:47 +09:00
test_routes_anthropic_beta.py test(proxy): move proxy_server, _experimental and db tests into tests/unit/proxy (#44012) 2026-10-01 18:14:24 +00:00
test_routes_assistants.py fix(proxy): keep the mapped status on assistants and threads route errors (#44994) 2026-10-09 16:55:15 -07:00
test_routes_audio.py feat(realtime)!: support latest OpenAI audio models (#35600) 2026-11-03 07:27:52 +00:00
test_routes_chat_completions.py fix(azure): drop the traceback from stream-cut errors sent to clients and alerts (#51760) 2026-11-14 08:00:58 +00:00
test_routes_completions.py fix(azure): drop the traceback from stream-cut errors sent to clients and alerts (#51760) 2026-11-14 08:00:58 +00:00
test_routes_config.py fix(proxy): store boolean settings as JSON booleans on /config/field/update (#48595) 2026-10-28 17:39:01 +00:00
test_routes_embeddings.py refactor(proxy): expose public names for private proxy helpers (#45170) 2026-10-07 18:59:27 -07:00
test_routes_invitation.py refactor(proxy): expose public names for private proxy helpers (#45170) 2026-10-07 18:59:27 -07:00
test_routes_login_sso.py test: fix flaky spend-log cleanup budget, login lockout, and wedged Redis tests (#47108) 2026-10-29 03:46:32 -07:00
test_routes_misc.py refactor(router): move router callers onto the entry points and invert the proxy imports (#48847) 2026-10-29 17:26:33 +00:00
test_routes_model_cost_map.py refactor(model-cost): move the cost map inputs, fetch and register_model overlay into Rust (#50501) 2026-11-10 02:37:35 +00:00
test_routes_model_info.py refactor(rust_bridge): route every Rust-to-Python call through host modules (#50822) 2026-11-11 01:57:54 +00:00
test_routes_model_metrics.py test(proxy): move proxy_server, _experimental and db tests into tests/unit/proxy (#44012) 2026-10-01 18:14:24 +00:00
test_routes_models.py fix(proxy): serve Codex its own Bedrock catalog entries for Bedrock deployments (#50743) 2026-11-09 19:00:22 -08:00
test_routes_moderations.py fix(proxy): log each endpoint's own call type on failed audio, moderation, image, and rerank spend rows (#49684) 2026-11-02 23:57:11 +00:00
test_routes_onboarding.py test(proxy): move proxy_server, _experimental and db tests into tests/unit/proxy (#44012) 2026-10-01 18:14:24 +00:00
test_routes_queue.py fix(proxy): run baggage tag mappings and budget checks on /queue/chat/completions (#51753) 2026-11-14 08:54:54 -05:00
test_routes_threads.py fix(proxy): keep the mapped status on assistants and threads route errors (#44994) 2026-10-09 16:55:15 -07:00
test_routes_utils.py refactor(rust_bridge): route every Rust-to-Python call through host modules (#50822) 2026-11-11 01:57:54 +00:00
test_spend_counters.py feat(budgets): replace the python budget hold and settle engine with a rust engine admitted at auth (#51535) 2026-11-15 16:03:51 -08:00
test_streaming_helpers.py fix(router): keep both errors when a streamed cross-group fallback also fails (#52217) 2026-11-16 22:04:16 -08:00
test_team_model_name_translation.py fix(proxy)!: price expanded wildcard /model/info rows as the model their calls route to (#49128) 2026-11-08 19:08:22 +00:00