diff --git a/litellm/router.py b/litellm/router.py index eec393d6cef..12de75f9766 100644 --- a/litellm/router.py +++ b/litellm/router.py @@ -12498,7 +12498,14 @@ class Router: if early is not None: if not isinstance(early[1], list): return early - return early[0], self._drop_strategy_markers(early[0], early[1]) + # Wildcard and team-public names resolve here and return before the + # `_filter_blocked_deployments` call further down, so an admin pause has + # to be applied on this path too. When it removes every candidate, fall + # through rather than return an empty list: the normal path then reports + # "no healthy deployments" exactly as it does for an exact-name model. + routable_early: Final = self._filter_blocked_deployments(early[1]) + if routable_early: + return early[0], self._drop_strategy_markers(early[0], routable_early) ## get healthy deployments ### get all deployments diff --git a/tests/test_litellm/test_router.py b/tests/test_litellm/test_router.py index 26f9803a022..2ee70238532 100644 --- a/tests/test_litellm/test_router.py +++ b/tests/test_litellm/test_router.py @@ -16716,3 +16716,76 @@ class TestMemberAutoRouterInference: monkeypatch.setitem(sys.modules, "fastapi", None) monkeypatch.delitem(sys.modules, "litellm.proxy.auth.auto_router_checks", raising=False) assert (await self._route(router, {"metadata": {"user_api_key_team_id": "router-team"}})).model == "restricted-model" + + +class TestBlockedWildcardDeployments: + """An admin pause has to reach wildcard deployments too. + + A request whose model is not a configured name (`zzz-test-9` against + `zzz-test-*`) is resolved by the pattern router and returned before the + blocked filter the exact-name path runs, so a paused wildcard deployment kept + serving traffic until the process restarted. See #41580. + """ + + @staticmethod + def _router(model_name: str, blocked: bool): + import litellm + + return litellm.Router( + model_list=[ + { + "model_name": model_name, + "litellm_params": {"model": "openai/gpt-4o", "api_key": "sk-fake"}, + "model_info": {"id": "dep-wildcard", "blocked": blocked}, + } + ] + ) + + def test_paused_wildcard_deployment_is_not_routable(self): + import litellm + + router = self._router("zzz-test-*", blocked=True) + + with pytest.raises(litellm.BadRequestError): + router._common_checks_available_deployment( + model="zzz-test-9", + messages=[{"role": "user", "content": "hi"}], + request_kwargs={}, + ) + + def test_unpaused_wildcard_deployment_still_routes(self): + router = self._router("zzz-test-*", blocked=False) + + _, healthy = router._common_checks_available_deployment( + model="zzz-test-9", + messages=[{"role": "user", "content": "hi"}], + request_kwargs={}, + ) + + assert [deployment["model_info"]["id"] for deployment in healthy] == ["dep-wildcard"] + + def test_pausing_a_live_wildcard_deployment_takes_effect_without_restart(self): + import litellm + from litellm.types.router import Deployment, LiteLLM_Params + + router = self._router("zzz-test-*", blocked=False) + router._common_checks_available_deployment( + model="zzz-test-9", + messages=[{"role": "user", "content": "hi"}], + request_kwargs={}, + ) + + router.upsert_deployment( + deployment=Deployment( + model_name="zzz-test-*", + litellm_params=LiteLLM_Params(model="openai/gpt-4o", api_key="sk-fake"), + model_info={"id": "dep-wildcard", "blocked": True}, + ) + ) + + with pytest.raises(litellm.BadRequestError): + router._common_checks_available_deployment( + model="zzz-test-9", + messages=[{"role": "user", "content": "hi"}], + request_kwargs={}, + )