fix(proxy): let an org admin give a legacy model_max_budget row a budget_duration at the same or a lower cap

This commit is contained in:
mateo-berri 2026-10-28 13:05:49 -07:00
parent 7a0693e91f
commit 441a9297d0
2 changed files with 15 additions and 4 deletions

View file

@ -1498,10 +1498,9 @@ def _check_team_model_budget_update_authority(
routed_models: Final = routed_models_source(data.team_id)
for entry, proposed in requested.items():
existing = _existing_model_cap(existing_model_max_budget.get(entry))
if existing is not None:
if existing is not None and (is_enforced_budget_entry(existing) or not is_enforced_budget_entry(proposed)):
_check_existing_model_cap_kept(entry=entry, cap_entry=entry, proposed=proposed, existing=existing)
if is_enforced_budget_entry(existing) or not is_enforced_budget_entry(proposed):
continue
continue
governing = resolve_model_budget(model=entry, model_max_budget=existing_model_max_budget, team_id=data.team_id)
if governing is not None and entry_names_model(entry=governing.budget_model, model=entry):
_check_existing_model_cap_kept(
@ -1575,7 +1574,9 @@ def _capped_entries_outranked_by(
entries_outranked_by(entry=entry, model_max_budget=existing_model_max_budget, routed_models=routed_models),
)
outranked_caps: Final = ((name, _existing_model_cap(existing_model_max_budget[name])) for name in outranked_names)
yield from ((name, cap) for name, cap in outranked_caps if cap is not None and cap.max_budget is not None)
yield from (
(name, cap) for name, cap in outranked_caps if name != entry and cap is not None and cap.max_budget is not None
)
def _looser_model_cap(proposed: BudgetConfig, cap: BudgetConfig) -> bool:

View file

@ -17754,6 +17754,14 @@ def test_team_admin_cannot_add_an_entry_that_takes_precedence_over_a_cap(
_TEAM_OPUS_FAMILY_CAP,
{**_TEAM_OPUS_FAMILY_CAP, "gemini-3-pro*": {"max_budget": 1000.0, "budget_duration": "1d"}},
),
(
{**_TEAM_OPUS_FAMILY_CAP, "gpt-4o": {"max_budget": 10.0}},
{**_TEAM_OPUS_FAMILY_CAP, "gpt-4o": {"max_budget": 10.0, "budget_duration": "1d"}},
),
(
{"z-anthropic-group": {"max_budget": 10.0}},
{"z-anthropic-group": {"max_budget": 10.0, "budget_duration": "1d"}},
),
],
ids=[
"less_specific_pattern",
@ -17767,6 +17775,8 @@ def test_team_admin_cannot_add_an_entry_that_takes_precedence_over_a_cap(
"uncapped_entry_edited",
"enforced_uncapped_entry_capped",
"pattern_sharing_only_a_wildcard_route",
"unenforced_capped_model_given_a_duration",
"unenforced_capped_wildcard_group_given_a_duration",
],
)
def test_team_admin_can_keep_or_tighten_entries_and_add_ones_that_outrank_no_cap(