fix(proxy): keep a legacy model_max_budget row's stored cap when an org admin gives it a budget_duration

This commit is contained in:
mateo-berri 2026-10-28 13:37:08 -07:00
parent 441a9297d0
commit d150c818ca
2 changed files with 14 additions and 3 deletions

View file

@ -1498,9 +1498,10 @@ 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 and (is_enforced_budget_entry(existing) or not is_enforced_budget_entry(proposed)):
if existing is not None:
_check_existing_model_cap_kept(entry=entry, cap_entry=entry, proposed=proposed, existing=existing)
continue
if is_enforced_budget_entry(existing) or not is_enforced_budget_entry(proposed):
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(
@ -1583,7 +1584,7 @@ def _looser_model_cap(proposed: BudgetConfig, cap: BudgetConfig) -> bool:
return (
proposed.max_budget is None
or (cap.max_budget is not None and proposed.max_budget > cap.max_budget)
or proposed.budget_duration != cap.budget_duration
or (is_enforced_budget_entry(cap) and proposed.budget_duration != cap.budget_duration)
)

View file

@ -17797,6 +17797,16 @@ def test_team_admin_cannot_make_an_unenforced_entry_take_precedence_over_a_cap()
assert "'claude-opus*'" in exc.value.detail["error"]
def test_team_admin_cannot_raise_an_unenforced_cap_while_enforcing_it() -> None:
with pytest.raises(HTTPException) as exc:
_check_team_admin_model_caps(
existing={"gpt-4o": {"max_budget": 10.0}},
requested={"gpt-4o": {"max_budget": 20.0, "budget_duration": "1d"}},
)
assert exc.value.status_code == 403
assert "(entry 'gpt-4o')" in exc.value.detail["error"]
@pytest.mark.parametrize("added_entry", _BEDROCK_ROUTE_ADDED_ENTRIES, ids=["model", "pattern"])
def test_team_admin_cannot_lift_a_bedrock_vendor_cap_through_a_bedrock_wildcard_route(added_entry: str) -> None:
with pytest.raises(HTTPException) as exc: