You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fix(alerting): send one budget alert when concurrent checks hit the same budget event - #45581
Please complete all items before asking a LiteLLM maintainer to review your PR
I have added meaningful tests
The handful of test files covering my change pass locally, e.g. uv run pytest tests/unit/<your_test_file>.py -v. Leave the suites (make test-unit-*, make test-unit) to CI: it finishes in ~15 minutes where a laptop takes an hour or more
My PR passes all required CI/CD checks (e.g., lint, schema.d.ts sync check, etc.)
My PR's scope is as isolated as possible; it only solves 1 specific problem
I have received a Greptile Confidence Score of at least 4/5 before requesting a maintainer review (Greptile reviews automatically once the PR is opened; only comment @greptileai to re-request a review after pushing changes)
Screenshots / Proof of Fix
Setup shared by both runs: a local Postgres, a fresh database per run, and a webhook receiver on 127.0.0.1:8099 that writes one line per alert (event, token, spend) to webhook.log and answers 200 after 200 ms, roughly what a hosted chat webhook takes. The model uses mock_response because both alerts fire from the auth and spend-tracking steps, not from the provider response
The alert from the spend-update path arrives as budget_crossed. That labeling is pre-existing and unchanged
Final Attestation
The tests check the right things, including the edge cases, and regressions in the respective real-world customer use-cases are not possible after this PR
budget_alerts now increments its cooldown key before sending. Only the first claim sends, and a raised send error deletes the claim
Concurrent budget checks send one alert for each event.
Acknowledged limits from Jayanth-reflex: Redis failures leave each worker deduping locally; cancelled sends keep their claim until expiry; failed sends leave other workers' local claims intact. The description states that these match the email path
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem this solves:
How it solves it:
User Flow
Before: a proxy admin with budget alerts on a webhook gets the same alert many times when traffic is concurrent
alerting: ["webhook"]and creates a key withsoft_budget: 5that has already spent $10soft_budget_crossedand 10 identicalbudget_crossedfor the same keyAfter: the same traffic produces one alert per budget event
alerting: ["webhook"]and creates a key withsoft_budget: 5that has already spent $10soft_budget_crossedand onebudget_crossedRelevant issues
Fixes #44919
Pre-Submission checklist
Please complete all items before asking a LiteLLM maintainer to review your PR
uv run pytest tests/unit/<your_test_file>.py -v. Leave the suites (make test-unit-*,make test-unit) to CI: it finishes in ~15 minutes where a laptop takes an hour or more@greptileaito re-request a review after pushing changes)Screenshots / Proof of Fix
Setup shared by both runs: a local Postgres, a fresh database per run, and a webhook receiver on 127.0.0.1:8099 that writes one line per alert (event, token, spend) to
webhook.logand answers 200 after 200 ms, roughly what a hosted chat webhook takes. The model usesmock_responsebecause both alerts fire from the auth and spend-tracking steps, not from the provider responseBefore (a3236ba)
Concurrent requests on a key over its soft budget
Send 10 concurrent requests:
for i in $(seq 10); do chat & done; wait; echoCount the alerts:
wc -l < webhook.log; sort webhook.log | uniq -cSend one more request, then count again:
chat; echo; wc -l < webhook.logWebhook down during the concurrent requests, then back up
With the receiver stopped, send 10 concurrent requests:
for i in $(seq 10); do chat & done; wait; echoCount the alerts:
wc -l < webhook.logStart the receiver, send one request, then count:
chat; echo; wc -l < webhook.log; sort webhook.log | uniq -cSend one more request, then count again:
chat; echo; wc -l < webhook.logAfter (a564b60)
Concurrent requests on a key over its soft budget
Send 10 concurrent requests:
for i in $(seq 10); do chat & done; wait; echoCount the alerts:
wc -l < webhook.log; sort webhook.log | uniq -cSend one more request, then count again:
chat; echo; wc -l < webhook.logWebhook down during the concurrent requests, then back up
With the receiver stopped, send 10 concurrent requests:
for i in $(seq 10); do chat & done; wait; echoCount the alerts:
wc -l < webhook.logStart the receiver, send one request, then count:
chat; echo; wc -l < webhook.log; sort webhook.log | uniq -cSend one more request, then count again:
chat; echo; wc -l < webhook.logType
🐛 Bug Fix
Caveats (if any)
Low
mock_response, so no provider call was madefailed_tracking_alerthas the same read-then-send shape and is left as is, since [Bug]: Concurrent budget checks deliver duplicate webhook alerts for the same entity and budget event #44919 is only about budget alertsbudget_crossed. That labeling is pre-existing and unchangedFinal Attestation