Skip to content

Fix team max budget check to block at exact budget (>= instead of >)#28109

Open
rakesh-vs wants to merge 1 commit into
BerriAI:shin_agent_oss_staging_05_17_2026from
rakesh-vs:rakesh-vs-fix-team-budget-comparator
Open

Fix team max budget check to block at exact budget (>= instead of >)#28109
rakesh-vs wants to merge 1 commit into
BerriAI:shin_agent_oss_staging_05_17_2026from
rakesh-vs:rakesh-vs-fix-team-budget-comparator

Conversation

@rakesh-vs
Copy link
Copy Markdown

@rakesh-vs rakesh-vs commented May 17, 2026

Relevant issues

Fixes #28020

Type

🐛 Bug Fix

Changes

_team_max_budget_check used spend > team_object.max_budget, while every
other budget check in auth_checks.py (key, key budget window, team budget
window, team member, team soft, org) uses >=. As a result, a team whose
spend exactly matched its max_budget was allowed through, but a key in
the same state was correctly blocked.

This PR changes the team check to >= for consistency. Added a regression
test in tests/test_litellm/proxy/auth/test_auth_checks.py that asserts
BudgetExceededError is raised when spend == max_budget.

Pre-Submission checklist

  • Added a regression test in tests/test_litellm/proxy/auth/test_auth_checks.py
  • Full tests/test_litellm/proxy/auth/test_auth_checks.py passes locally (117 passed)
  • PR scope is isolated - single one-character fix + one test
  • Greptile review

@CLAassistant
Copy link
Copy Markdown

CLAassistant commented May 17, 2026

CLA assistant check
All committers have signed the CLA.

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented May 17, 2026

Greptile Summary

This PR fixes an off-by-one bug in the team budget enforcement path: _team_max_budget_check previously used > instead of >=, allowing a team whose spend exactly matched max_budget to proceed when every other budget check in auth_checks.py would have blocked it.

  • auth_checks.py: Single operator change (>>=) on line 3697 aligns the team check with the key, key-window, team-window, team-member, team-soft, and org checks.
  • test_auth_checks.py: New regression test mocks get_current_spend to return a value exactly equal to max_budget and asserts BudgetExceededError is raised with correct current_cost and max_budget attributes.

Confidence Score: 5/5

Safe to merge — the change is a one-character correction that closes a gap between the team budget check and every other budget check in the same file, with a targeted regression test covering the exact boundary case.

The fix is minimal and surgical: a single > to >= change that brings the team budget check into alignment with six other checks in the same function file. The regression test correctly mocks get_current_spend, makes no real network calls, and pins both the raised exception type and its current_cost/max_budget attributes.

No files require special attention.

Important Files Changed

Filename Overview
litellm/proxy/auth/auth_checks.py One-character fix: >>= in _team_max_budget_check so teams are blocked when spend exactly equals max_budget, consistent with all other budget checks in the file.
tests/test_litellm/proxy/auth/test_auth_checks.py Adds a regression test test_team_budget_check_blocks_when_spend_equals_max_budget that mocks get_current_spend to return exactly max_budget and asserts BudgetExceededError is raised — no real network calls.

Reviews (4): Last reviewed commit: "Fix team max budget check to block at ex..." | Re-trigger Greptile

@codspeed-hq
Copy link
Copy Markdown
Contributor

codspeed-hq Bot commented May 17, 2026

Merging this PR will not alter performance

✅ 16 untouched benchmarks


Comparing rakesh-vs:rakesh-vs-fix-team-budget-comparator (69f28fd) with main (a72414a)

Open in CodSpeed

@codecov
Copy link
Copy Markdown

codecov Bot commented May 17, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@rakesh-vs rakesh-vs changed the base branch from main to litellm_oss_staging May 17, 2026 05:20
@rakesh-vs rakesh-vs force-pushed the rakesh-vs-fix-team-budget-comparator branch from 69f28fd to 8cb8c96 Compare May 17, 2026 05:24
@rakesh-vs
Copy link
Copy Markdown
Author

@greptileai retrigger on latest commit

@oss-pr-review-agent-shin
Copy link
Copy Markdown
Contributor

🤖 litellm-agent: Auto-merge skipped — the staging branch shin_agent_oss_staging_05_17_2026 has 1180 commit(s) not in your branch. Merging as-is would produce a confusing diff on the staging PR.

Please rebase your branch onto shin_agent_oss_staging_05_17_2026 and push; the agent will re-review automatically.

@rakesh-vs rakesh-vs force-pushed the rakesh-vs-fix-team-budget-comparator branch from 8cb8c96 to 0e4df2d Compare May 17, 2026 05:39
@rakesh-vs rakesh-vs changed the base branch from litellm_oss_staging to shin_agent_oss_staging_05_17_2026 May 17, 2026 05:39
@rakesh-vs
Copy link
Copy Markdown
Author

@greptileai please retrigger on rebased commit

Aligns _team_max_budget_check with the >= comparator used by
_virtual_key_max_budget_check, key budget windows, team budget windows,
team member budget, team soft budget, and org budget. Previously a team
whose spend exactly matched its max_budget was allowed through, while a
key with the same spend/budget was correctly blocked.

Fixes BerriAI#28020
@rakesh-vs rakesh-vs force-pushed the rakesh-vs-fix-team-budget-comparator branch from 0e4df2d to 8abe074 Compare May 17, 2026 05:49
@rakesh-vs
Copy link
Copy Markdown
Author

@greptileai please retrigger on rebased commit

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