From 314b581f10925f85598cb4871562d728e09a38dc Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Mon, 26 Oct 2026 13:42:25 +0000 Subject: [PATCH] fix(proxy): quarantine only unparseable duration strings Integer durations stay a per-row failure. 1hr and fortnightly now raise instead of resetting at the next midnight. Co-authored-by: Zsanz3 --- litellm/proxy/common_utils/reset_budget_job.py | 4 +++- tests/unit/litellm_core_utils/test_duration_parser.py | 4 ++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/litellm/proxy/common_utils/reset_budget_job.py b/litellm/proxy/common_utils/reset_budget_job.py index 67ecc5db5d0..2c896792f6f 100644 --- a/litellm/proxy/common_utils/reset_budget_job.py +++ b/litellm/proxy/common_utils/reset_budget_job.py @@ -368,7 +368,9 @@ def _count_advanced(reset_ats: Iterable[object], cutoff: datetime) -> int: def _try_compute_budget_reset_at(duration: object, settings: BudgetResetSettings) -> datetime | None: if not isinstance(duration, str): - return None + raise ValueError( + f"Invalid budget_duration {duration!r}. Use the format (e.g. '1h', '7d', '30d', '1mo')." + ) try: return compute_budget_reset_at(budget_duration=duration, settings=settings) except ValueError: diff --git a/tests/unit/litellm_core_utils/test_duration_parser.py b/tests/unit/litellm_core_utils/test_duration_parser.py index 5773ece15a0..5576b7db6b3 100644 --- a/tests/unit/litellm_core_utils/test_duration_parser.py +++ b/tests/unit/litellm_core_utils/test_duration_parser.py @@ -339,7 +339,7 @@ class TestWordFormBudgetDurations(unittest.TestCase): def test_unparseable_duration_raises_instead_of_midnight_fallback(self): base_time = datetime(2023, 5, 15, 15, 0, 0, tzinfo=timezone.utc) - for duration in ("", " ", "garbage", "1x", "1dinvalid"): + for duration in ("", " ", "garbage", "1x", "1dinvalid", "1hr", "fortnightly"): with self.assertRaises(ValueError) as ctx: get_next_standardized_reset_time(duration, base_time, "UTC") self.assertIn("Invalid budget_duration", str(ctx.exception)) @@ -348,7 +348,7 @@ class TestWordFormBudgetDurations(unittest.TestCase): class TestGetBudgetWindowStart(unittest.TestCase): def test_window_start_is_the_previous_reset_on_the_same_schedule(self): created_at: Final = datetime(2024, 10, 1, 0, 30, tzinfo=timezone.utc) - durations: Final = "1d 24h daily 7d weekly 2w 10d 30d monthly 1mo 4h 5h 30m 45s 1hr fortnightly".split() + durations: Final = "1d 24h daily 7d weekly 2w 10d 30d monthly 1mo 4h 5h 30m 45s".split() for duration in durations: with self.subTest(duration=duration): reset_at = get_next_standardized_reset_time(duration, created_at, "UTC")