Skip to content

fix(budget): align reset times for legacy entities (Team Members, End Users) with standardized calendar - #25440

Merged
krrish-berri-2 merged 1 commit into
BerriAI:litellm_oss_staging_04_11_2026from
DmitriyAlergant:fix/budget-table-calendar-aligned-reset
Apr 12, 2026
Merged

fix(budget): align reset times for legacy entities (Team Members, End Users) with standardized calendar#25440
krrish-berri-2 merged 1 commit into
BerriAI:litellm_oss_staging_04_11_2026from
DmitriyAlergant:fix/budget-table-calendar-aligned-reset

Conversation

@DmitriyAlergant

Copy link
Copy Markdown
Contributor

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

  • I have Added testing in the tests/test_litellm/ directory, - [X] Passes impacted/relevant tests
  • My PR's scope is as isolated as possible, it only solves 1 specific problem
  • I will have requested a Greptile review by commenting @greptileai and will receive a Confidence Score of at least 4/5 before requesting a maintainer review

Type

🐛 Bug Fix

@vercel

vercel Bot commented Apr 9, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
litellm Ready Ready Preview, Comment Apr 9, 2026 7:49pm

Request Review

@greptile-apps

greptile-apps Bot commented Apr 9, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR aligns budget reset times for legacy entities (Team Members, End Users) with the standardized calendar schedule by replacing the old sliding-window offset (current_time + timedelta(seconds=duration)) with get_budget_reset_time() — a thin wrapper around the existing get_next_standardized_reset_time utility — in both _reset_budget_reset_at_date and the /budget/new endpoint. The new tests cover calendar alignment, weekly (7d), None-duration, and None-reset-at cases using mocks only.

Confidence Score: 5/5

Safe 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.

Vulnerabilities

No security concerns identified.

Important Files Changed

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
Loading

Reviews (2): Last reviewed commit: "fix(budget): align budget table reset ti..." | Re-trigger Greptile

@codspeed-hq

codspeed-hq Bot commented Apr 9, 2026

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

✅ 16 untouched benchmarks


Comparing DmitriyAlergant:fix/budget-table-calendar-aligned-reset (1e8174f) with main (3a6db70)

Open in CodSpeed

@codecov

codecov Bot commented Apr 9, 2026

Copy link
Copy Markdown

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>
@DmitriyAlergant

Copy link
Copy Markdown
Contributor Author

@krrish-berri-2 pls review/merge.

@krrish-berri-2
krrish-berri-2 changed the base branch from main to litellm_oss_staging_04_11_2026 April 12, 2026 02:45
@krrish-berri-2
krrish-berri-2 merged commit e1bf114 into BerriAI:litellm_oss_staging_04_11_2026 Apr 12, 2026
49 of 51 checks passed
fzowl pushed a commit to fzowl/litellm that referenced this pull request Jun 24, 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants