test(e2e): poll key spend to a deadline in budget reset advances tests - #35572
Merged
yuneng-berri merged 1 commit intoAug 2, 2026
Merged
Conversation
A single read of key_info.spend races the batched spend writer: deltas earned before a reset flush to the DB up to ~60s later (proxy_batch_write_at) and land on the row after the reset zeroed it. The stage runs on Jul 30 and Aug 2 failed test_key_budget_reset_at_advances_after_window exactly this way, with spend back at the driven total while budget_reset_at had advanced and calls flowed again. Replace the single reads in rung 3 (spend zeroed after reset) and rung 4 (roomy window keeps spend) with _poll_key_spend, which re-reads to a 90s deadline covering one full flush-plus-reset cycle. A reset that never zeroes the row keeps spend pinned and still times out, so the regression guard keeps its teeth.
Contributor
Greptile SummaryThis test-only PR adds a reusable deadline-based key-spend poll to tolerate asynchronous spend-write convergence in two budget reset E2E assertions.
Confidence Score: 5/5The PR appears safe to merge because the bounded polling preserves the existing spend predicates while accommodating asynchronous database convergence. The helper repeatedly evaluates the original assertions against fresh key-info reads and still fails after a finite deadline when the expected spend state never appears.
|
| Filename | Overview |
|---|---|
| tests/e2e/quota_management/budgets/test_budget_reset_advances_e2e.py | Adds bounded polling around two asynchronous spend assertions without introducing a concrete changed-code defect. |
Reviews (1): Last reviewed commit: "test(e2e): poll key spend to a deadline ..." | Re-trigger Greptile
yuneng-berri
approved these changes
Aug 2, 2026
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
Merged
9 tasks
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
TLDR
Problem this solves:
How it solves it:
Relevant issues
Linear ticket
Pre-Submission checklist
Please complete all items before asking a LiteLLM maintainer to review your PR
@greptileaito re-request a review after pushing changes)Delays in PR merge?
If you're seeing a delay in your PR being merged, ping the LiteLLM Team on Slack (#pr-review).
Screenshots / Proof of Fix
Before (the flake this kills): stage e2e runs 2026-07-30 00:45 UTC and 2026-08-02 00:52 UTC (image at ba480a6) both failed
test_key_budget_reset_at_advances_after_windowwith the identical signature while every neighbouring assertion passed, proving the reset itself worked and only the read raced the flushAfter (at ebdd854): both tests against a live worktree proxy on localhost:4611 backed by a real provider (groq llama-3.3-70b-versatile, x-litellm-response-cost 2.282e-05 per call), with the proxy running the stage cadence that produces the race window (
PROXY_BATCH_WRITE_AT=60, budget rescheduler every 15-20s)Type
✅ Test
Changes
tests/e2e/quota_management/budgets/test_budget_reset_advances_e2e.pyonly. Adds_poll_key_spend, which re-readskey_info.spendevery 5s until a predicate holds or a 90s deadline expires; 90s covers one full flush-plus-reset cycle, so a late flush delays the pass a few iterations while a reset job that never zeroes the row keeps spend pinned at the driven total and still times out. Rung 3 swaps its singlespend < capread for the poll, rung 4 swaps its singlespend >= spend_at_blockread (the mirror timing of the same race), and both docstrings say why. No other budget test reads spend as a single post-convergence snapshot: the reseed test already waits out the flush explicitly and the user-budget test already pollsQA runbook
Environment notes: needs a DB-backed proxy whose budget rescheduler runs faster than the default 10 minutes (stage runs 15-20s) and a model named claude-haiku-4-5; locally I pointed that alias at groq since this machine's .env carries no Anthropic key
Final Attestation