fix(health): keep a team deployment's internal name narrow when a limit holds only that name

An agent or key limit that holds one team deployment's internal name no longer reaches every deployment behind the team's public name. The internal name maps to its public name only when the public name is also admitted.
This commit is contained in:
mateo-berri 2026-10-29 21:46:06 -07:00
parent 99fb392b91
commit 4b9d579d87
2 changed files with 23 additions and 3 deletions

View file

@ -1256,8 +1256,11 @@ class _AccessGroupGrants:
granted_names: frozenset[str]
ids_in_granted_groups: frozenset[str]
def requested_name(self, name: str, public_names: Mapping[str, str]) -> str:
return name if name in self.granted_names else public_names.get(name, name)
def requested_name(self, name: str, public_names: Mapping[str, str], admitted_names: frozenset[str]) -> str:
public_name: Final = public_names.get(name)
if public_name is None or public_name not in admitted_names or name in self.granted_names:
return name
return public_name
def narrow(self, serving_ids: frozenset[str], served_names: frozenset[str]) -> frozenset[str]:
in_granted_groups: Final = serving_ids & self.ids_in_granted_groups
@ -1365,7 +1368,7 @@ async def _deployments_key_may_reach(
access_group_grants: Final = _access_group_grants(llm_model_list, user_api_key_dict)
public_names: Final = _public_names_by_internal_name(llm_model_list, user_api_key_dict.team_id)
groups: Final = frozenset(
_served_group(access_group_grants.requested_name(name, public_names), aliases, llm_router)
_served_group(access_group_grants.requested_name(name, public_names, admitted_names), aliases, llm_router)
for name in admitted_names
)
ids_by_name: Final = _ids_by_requested_name(llm_model_list, user_api_key_dict.team_id)

View file

@ -4973,6 +4973,23 @@ async def test_health_endpoint_probes_a_team_deployment_whose_internal_name_the_
assert probed == {"id-team-premium", "id-team-standard"}
@pytest.mark.asyncio
async def test_health_endpoint_probes_only_the_team_deployment_whose_internal_name_an_agent_holds() -> None:
from litellm.types.agents import AgentResponse
policy: Final = AgentResponse(
agent_id="managed",
agent_name="Managed",
agent_card_params={},
object_permission={"models": ["model_name_team-a_9d2f6e01"]},
)
caller: Final = _team_key(["gpt-5.4-mini"]).model_copy(update={"managed_agent_policy": policy})
probed: Final = await _live_probed_model_ids(_team_split_model_list("gpt-5.4-mini", "openai/gpt-5.4-mini"), caller)
assert probed == {"id-team-standard"}
def test_resolve_targeted_model_ids_lets_model_id_win_over_model():
resolve = _health_endpoints_module._resolve_targeted_model_ids