fix(budget): align reset times for legacy entities (Team Members, End Users) with standardized calendar - #25440
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Greptile SummaryThis PR aligns budget reset times for legacy entities (Team Members, End Users) with the standardized calendar schedule by replacing the old sliding-window offset ( Confidence Score: 5/5Safe to merge; all remaining findings are P2 style issues that do not affect correctness. The core logic change is correct and well-tested with mock-only unit tests. The two findings are P2: an inline import (CLAUDE.md style violation) and an unused current_time parameter (dead code). Neither causes incorrect behavior — the calendar-aligned reset time is computed correctly in all cases. No security, data-integrity, or backwards-compatibility issues beyond the intentional calendar-alignment shift. litellm/proxy/common_utils/reset_budget_job.py — inline import and dead current_time parameter in _reset_budget_reset_at_date.
|
| Filename | Overview |
|---|---|
| litellm/proxy/common_utils/reset_budget_job.py | Replaces sliding-window offset logic with calendar-aligned get_budget_reset_time call; introduces an inline import (style violation) and leaves current_time as an unused parameter. |
| litellm/proxy/management_endpoints/budget_management_endpoints.py | Cleanly replaces datetime.utcnow() + timedelta(seconds=duration_in_seconds(...)) with get_budget_reset_time(...) in new_budget; import moved to module level correctly. |
| tests/test_litellm/proxy/common_utils/test_reset_budget_job.py | Adds four new unit tests covering calendar alignment, 7-day weekly reset, None duration, and None reset-at cases; tests are mock-only and cover the key branches of the changed logic. |
Flowchart
%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[reset_budget_for_litellm_budget_table] --> B[Fetch budgets_to_reset from DB]
B --> C{budgets found?}
C -- No --> Z[Done]
C -- Yes --> D[For each budget: _reset_budget_reset_at_date]
D --> E{budget_duration is set?}
E -- No --> F[budget_reset_at unchanged]
E -- Yes --> G[get_budget_reset_time budget_duration]
G --> H[get_next_standardized_reset_time datetime.now UTC + timezone]
H --> I{unit?}
I -- 1d --> J[next midnight]
I -- 7d --> K[next Monday midnight]
I -- 30d / 1mo --> L[1st of next month]
I -- Nd other --> M[midnight + N days]
J & K & L & M --> N[budget.budget_reset_at = result]
F & N --> O[update_many budgets in DB]
O --> P[reset end-users / team-members / keys linked to budgets]
P --> Z
Reviews (2): Last reviewed commit: "fix(budget): align budget table reset ti..." | Re-trigger Greptile
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
…r schedule Budget table entries (team members, end-users) used duration_in_seconds() for a sliding-window reset, while keys/users/teams used calendar-aligned get_budget_reset_time(). This made "30d" and "1mo" mean different things depending on entity type. Now both paths use get_budget_reset_time() for consistent calendar-aligned resets (e.g. "30d" → 1st of next month). Fixes BerriAI#25432 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
5c2a2c1 to
1e8174f
Compare
|
@krrish-berri-2 pls review/merge. |
e1bf114
into
BerriAI:litellm_oss_staging_04_11_2026
…r schedule (BerriAI#25440) Budget table entries (team members, end-users) used duration_in_seconds() for a sliding-window reset, while keys/users/teams used calendar-aligned get_budget_reset_time(). This made "30d" and "1mo" mean different things depending on entity type. Now both paths use get_budget_reset_time() for consistent calendar-aligned resets (e.g. "30d" → 1st of next month). Fixes BerriAI#25432
Align budget table reset times with standardized calendar schedule.
Relevant issues
Fixes issue #25432
Pre-Submission checklist
Please complete all items before asking a LiteLLM maintainer to review your PR
tests/test_litellm/directory, - [X] Passes impacted/relevant tests@greptileaiand will receive a Confidence Score of at least 4/5 before requesting a maintainer reviewType
🐛 Bug Fix