litellm/tests/unit/test_router
ryan-crabbe-berri 454989e516
fix(router): free streamed Responses API requests without waiting for a full gc (#52215)
* test(router): streamed Responses API requests are freed without a gc pass

Covers a Responses stream read to the end, one that fell back mid-stream and one the caller closed mid-stream at the Router, and a streamed /v1/responses call through the proxy read to the end or dropped by the client (#51936). Streamed chat completions through the proxy stay covered as a guard.

* fix(router): free streamed Responses API requests without waiting for a full gc

The Responses stream wrapper was a class defined per call, so the class and
its closures over the attempt sat in a reference cycle, and the fallback
generator held the wrapper strongly. A finished or dropped stream kept its
request, logging object and provider iterator alive until a gen-2 gc.

Move FallbackResponsesStreamWrapper to module level, let the generator and
recovery helpers reach it only through a weakref, and stop binding the caught
mid-stream error to a generator frame local, whose traceback pinned that frame
after a fallback or same-group retry.

Fixes #51936

* test(router): name the freed-stream cases by how they end and rerun-proof the held-open gate

Derive the parametrized endings from their Literal, drop a guard that repeated an existing fallback
ordering test, reset the integration upstream gate per run, and keep the terminal event tuple private.

* style(router): keep the existing complexity suppression on the Responses stream wrapper builder

* test(router): drop the section heading comment from the freed-stream tests

* fix(router): drop a finished Responses stream's failure explainer so the fallback walk can be freed

The explainer added for cross-group fallback errors closes over the walk, and the walk keeps the
last fallback stream, so a stream that fell back mid-way stayed alive until a full gc. Release it
once the stream ends, after every place that reads it.
2026-11-17 15:55:39 -08:00
..
core fix(router): free streamed Responses API requests without waiting for a full gc (#52215) 2026-11-17 15:55:39 -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 feat(tts)!: stream audio from the provider as it arrives on /v1/audio/speech (#46222) 2026-11-17 15:03:12 +00: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