fix(reset_budget_job): skip rows with empty/falsy budget_duration

Harden the three places in the budget reset job that call
compute_budget_reset_at against stale rows carrying budget_duration="":

- _BudgetCascade construction: filter guard changes from "is not None"
  to a truthy check so empty strings are excluded.
- _reset_budget_common: same truthy guard prevents an empty-string
  budget_duration from triggering compute_budget_reset_at.
- _reset_expired_window: explicit early-return with a warning when
  budget_duration is falsy.

Companion to the duration_parser change that replaces the silent fallback
with ValueError.

Fixes: BerriAI/litellm#39368
This commit is contained in:
Aftab 2026-09-03 13:38:10 +05:30
parent 2a266d764e
commit eb2782c7c9

View file

@ -657,7 +657,7 @@ class ResetBudgetJob:
compute_budget_reset_at(budget_duration=b.budget_duration, settings=self.reset_settings),
)
for b in budgets_to_reset
if b.budget_id is not None and b.budget_duration is not None
if b.budget_id is not None and b.budget_duration
),
endusers=await self._collect_endusers_to_reset(budget_ids),
counter_resets=(
@ -1266,6 +1266,12 @@ class ResetBudgetJob:
except Exception as redis_err:
verbose_proxy_logger.warning("Failed to reset Redis counter %s: %s", counter_key, redis_err)
budget_duration: Final = window["budget_duration"]
if not budget_duration:
verbose_proxy_logger.warning(
"Skipping window reset for entity %s: budget_duration is empty or missing",
entity_id,
)
return False
next_reset_at: Final = compute_budget_reset_at(budget_duration=budget_duration, settings=reset_settings)
window["reset_at"] = next_reset_at.isoformat()
await ResetBudgetJob._roll_window_spend_row(
@ -1444,7 +1450,7 @@ class ResetBudgetJob:
"""
try:
item.spend = _carried_spend(item.spend, _rollover_cap(item.max_budget)) if _rollover_enabled() else 0.0
if hasattr(item, "budget_duration") and item.budget_duration is not None:
if hasattr(item, "budget_duration") and item.budget_duration:
item.budget_reset_at = compute_budget_reset_at(
budget_duration=item.budget_duration, settings=reset_settings
)