fix(proxy): never open a reset band for a negative max_budget

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
This commit is contained in:
ryan 2026-09-18 11:40:49 +00:00
parent cfcdc3e45f
commit dee583470b
2 changed files with 9 additions and 1 deletions

View file

@ -143,7 +143,7 @@ class _ResetBand:
def _reset_band(max_budget: float | None, rollover_max_budget: float | None) -> _ResetBand | None:
if max_budget is None or not math.isfinite(max_budget):
if max_budget is None or not math.isfinite(max_budget) or max_budget < 0:
return None
keep_overage: Final = litellm.budget_rollover is True
lo: Final = (

View file

@ -3696,6 +3696,14 @@ def test_reset_band_zero_max_budget_keeps_overage_without_credit(rollover_enable
assert _reset_spend(0.0, band) == 0.0
def test_reset_band_negative_max_budget_never_opens_a_band(rollover_enabled):
"""A negative max_budget is not an allowance, so budget_rollover on must not
turn each reset into spend - (-budget) and ratchet the balance upward."""
assert _reset_band(-50.0, None) is None
assert _reset_band(-50.0, 600.0) is None
assert _reset_spend(30.0, _reset_band(-50.0, 600.0)) == 0.0
def test_direct_reset_carries_unused_allowance_as_negative_spend(
reset_budget_job, mock_prisma_client, monkeypatch
):