test: roll back live router replay membership between tests - #36278
Merged
mateo-berri merged 1 commit intoAug 8, 2026
Conversation
Since #35491, every Router joins the module-global _live_routers weak set at construction, and every model cost map swap replays the deployments of every member on top of the freshly adopted map. #36039 isolated the register_model ledger half of that replay but not this half: under pytest-xdist, a Router created by an earlier test in the same worker that was still referenced (or simply not yet garbage collected) re-registered its deployments during TestPriceDataReloadIntegration::test_distributed_reload_check_function, and register_model hydrated the sparse mocked gpt-3.5-turbo entry into a full ModelInfo dict, failing the exact-equality assert (reruns cannot help since the polluting router survives in the worker process) The autouse isolate_litellm_state fixture now snapshots _live_routers before each test and restores its membership on teardown, so a test's routers stop contributing to cost map rebuilds once the test ends. A canary pair in test_conftest_isolation.py asserts the rollback
Contributor
Greptile SummaryThis PR extends test-state isolation to restore live Router membership between tests and adds regression coverage for that behavior.
Confidence Score: 5/5The PR appears safe to merge. No blocking failure remains.
|
| Filename | Overview |
|---|---|
| tests/test_litellm/conftest.py | Extends function-level LiteLLM state restoration to include the live Router weak-set membership. |
| tests/test_litellm/test_conftest_isolation.py | Adds regression coverage demonstrating that Router membership is removed between tests. |
Reviews (2): Last reviewed commit: "test: roll back live router replay membe..." | Re-trigger Greptile
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
Contributor
Author
yucheng-berri
approved these changes
Aug 8, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
TLDR
Problem this solves:
test_distributed_reload_check_functionafter test: roll back runtime model registrations between tests #36039RouterHow it solves it:
_live_routersmembershipUser Flow
Before: a contributor's PR touching nothing near pricing fails the proxy-infra required check on an unrelated test, and the automatic reruns fail the same way
https://github.com/BerriAI/litellm/actions/runs/31251929962/job/93089535345, they seeTestPriceDataReloadIntegration::test_distributed_reload_check_functionfailing on an assert that expected the two-field pricing entry{'input_cost_per_token': 0.001}and got a ~106-field dump of mostlyNonevalues, in a file their PR never touched2 rerun, so both automatic retries hit the identical assert and the red is sticky for this runAfter: the same PR's proxy-infra check passes, and the test no longer depends on which tests ran before it
test_distributed_reload_check_functionpasses regardless of which other tests ran earlier in the same worker, so no reruns are needed for this failureRelevant issues
Observed on PR #36276 (run 31251929962), whose head already contained #36039, so this is the second, previously unfixed half of the same #35491 replay pollution
Linear ticket
Pre-Submission checklist
Please complete all items before asking a LiteLLM maintainer to review your PR
@greptileaito re-request a review after pushing changes)Delays in PR merge?
If you're seeing a delay in your PR being merged, ping the LiteLLM Team on Slack (#pr-review).
Screenshots / Proof of Fix
This PR changes only test isolation, no proxy runtime code, so there is no end-user request to curl: the observable behavior is the CI shard itself. The proof is a deterministic reproduction of the exact CI failure and its disappearance at the exact commits
The reproduction plants a minimal polluter that does what many router tests already do, construct a
Routerwith agpt-3.5-turbodeployment, and holds it alive the way any module-level fixture or uncollected reference cycle would.PYTEST_XDIST_WORKER=gw0mimics a CI xdist worker, and the polluter's function name sorts first because the conftest orders tests by bare nameOn staging (e24a914) this fails with the same assert diff as the CI logs, the sparse
{"input_cost_per_token": 0.001}mock ballooned into a ~106-field mostly-NoneModelInfodict, and the captured log even shows the router's deployment re-registration firing inside the flaky test's reload call:On this branch (38c8e8d) the identical sequence passes:
The new canary pair in
tests/test_litellm/test_conftest_isolation.pyfails on staging at the rollback assert (1 failed, 3 passed) and passes here (4 passed). The full proxy-infra shard command from.github/workflows/test-unit-proxy-infra.yml(-n 2 --dist=loadscope --reruns 2) was also run on this branch: 6296 passed with the only failures being the 21 tests oftest_semantic_tool_filter.pyhitting a missing optionalsemantic_routerpackage in the local venv, which fail identically on clean staging (e24a914) without this changeType
✅ Test
Changes
tests/test_litellm/conftest.py: the autouseisolate_litellm_statefixture snapshotslitellm.router._live_routersmembership before each test and restores it on teardown. Since #35491 everyRouterjoins that weak set at construction, and every cost map swap walks it to re-register each member's deployments on top of the freshly adopted map, so a router constructed by one test kept rewriting the model entries a later test swapped in for as long as the object stayed referenced or uncollected. Restoring membership rather than dropping the routers keeps fixture-provided routers working within their own test while stopping them from contributing to later tests' cost map rebuildstests/test_litellm/test_conftest_isolation.py: a second canary pair; the first test constructs a router, holds it in a module-level slot so it deliberately stays alive, and asserts it joined_live_routers, the second asserts the fixture removed it despite the object still being alive. On current staging the second test fails, with this PR both passFinal Attestation