Repository navigation
test: fix flaky spend-log cleanup budget, login lockout, and wedged Redis tests - #47108
Conversation
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
|
I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".
|
|
|
Merging this PR will not alter performance1 warning
Comparing |
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
BrickerP
left a comment
There was a problem hiding this comment.
Reviewed head eebf022.
Lockout deflake: prefer the file's existing freeze over a wall-clock range
test_a_refused_attempt_carries_retry_after and test_the_form_returns_a_human_readable_lockout_page now assert ceil(77 - elapsed) <= retry_after <= 77 with time.time() around the attempts. That stops the 76-vs-77 flake, but the same file already pins Retry-After exactly by freezing login_throttle.time (see the block-is-hard test around the SimpleNamespace(time=lambda: frozen_now) pattern).
Impact: these two tests still depend on wall-clock progress during three HTTP posts, while a sibling covers the same header deterministically. Reusing that freeze would keep retry-after == "77" / Try again in about 77 seconds and match the rest of the suite; the spend-log clock= injection and the post-kill fresh httpx.Client (same shape as #47080) look right.
The remaining wedged-Redis burst p95 flake called out in the PR body is fine to leave for a follow-up.
…eout the test sets The burst p95 under a fixed 0.75s cap tracked how fast the box ran the 30 concurrent writes, so a loaded runner failed it at unchanged code. A handler that waits on the wedged publish takes at least the coordination Redis socket timeout, so the test now sets that timeout and asserts the p95 stays under it.
|
@BrickerP a frozen clock leaves exactly 77 s, so rounding down also gives 77. A round-down mutation passed frozen copies but failed the range |
|
@litereview code-review |
|
| if i % 5 in (0, 1, 4) and status == 200 | ||
| ) | ||
| timings["c1_burst_p95"] = elapsed_sorted[int(len(elapsed_sorted) * 0.95) - 1] | ||
| assert_cut_short(timings["c1_burst_p95"], injected_delay=_COORDINATION_SOCKET_TIMEOUT_SECONDS) |
There was a problem hiding this comment.
Low · Wedged Redis burst cap relaxed from 0.75s to 5s while the PR says it is unchanged
- The PR description lists the burst p95 failure under Not fixed in this PR. Its caveats also say the test "still has its fixed burst p95 cap".
- The diff replaces
assert timings["c1_burst_p95"] < _HANDLER_BUDGET_SECONDS(0.75s) withassert_cut_short(..., injected_delay=_COORDINATION_SOCKET_TIMEOUT_SECONDS). That helper only assertsp95 < 5.0. - The PR also pins
socket_timeoutincoordination_redis_proxy_config.yamlto make 5s the comparison point. - The test now passes a burst whose p95 is anywhere between 0.75s and 5s. A partial regression that stalls handlers on the wedged Redis for 1 to 4 seconds would previously fail. Now it passes, and the PR text does not tell reviewers about the weaker oracle.
Update the PR description to disclose this third deflake and why 5s is an acceptable oracle. Otherwise, drop the hunk and keep the deferral the description promises.
Evidence
Diff: timings["c1_burst_p95"] = ...; assert_cut_short(timings["c1_burst_p95"], injected_delay=_COORDINATION_SOCKET_TIMEOUT_SECONDS) with _COORDINATION_SOCKET_TIMEOUT_SECONDS: Final = 5.0
tests/integration/_support/timing.py: def assert_cut_short(elapsed, *, injected_delay): assert elapsed < injected_delay
PR body: "The same wedged Redis test also failed once on its fixed 0.75s burst p95 cap ... is left for a follow-up" and caveat "Wedged Redis test still has its fixed burst p95 cap"
Other handler assertions (s1..s8, c1_survivor) still use _HANDLER_BUDGET_SECONDS = 0.75s. Only the burst p95 changed.
Side check: tests/integration/authorization/test_sso_blank_identity.py also uses the YAML but does not set COORDINATION_REDIS_SOCKET_TIMEOUT. _resolve_coordination_redis_env_refs resolves it to None, and model_dump(exclude_none=True) drops it (verified locally: {'host': 'x'}). That path falls back to the default REDIS_SOCKET_TIMEOUT of 5.0, so it does not break.
Latest summary by code-review · View this review · Reviewed a20c89dc2a39
There was a problem hiding this comment.
The description now covers the burst fix, bounding the p95 by the 5s socket timeout the test sets, with before and after runs
There was a problem hiding this comment.
Finding withdrawn
Thanks for updating the description. You're right that it now resolves this finding.
The finding was about the description, not the code. The PR loosened the c1_burst_p95 oracle from 0.75s to 5s, but the description said the burst cap was unchanged and left for a follow-up. The fix I asked for was to disclose the change and explain why 5s is an acceptable bound, or drop the hunk.
The current description does that:
- It lists the burst cap as one of the fixes and says the p95 is now bounded by the 5s Redis socket timeout the test sets.
- It explains the choice of 5s. An update that waited on the wedged publish takes at least the socket timeout. It also explains why the author rejected a control burst and a larger fixed cap.
- It includes runs with and without the injected regression. A throttled run passes at a 0.941s p95. A forced wait on the publish fails at 15.08s.
- A Low caveat states the weaker oracle: "Burst bound is now 5s, so a 2s burst slowdown passes". It also notes that the single-call 0.75s caps around the burst still catch a slow handler.
The code at a20c89dc2a39 is still what the finding described. The 5s bound is now a disclosed trade-off that reviewers can weigh.
Evidence
Current PR body TLDR: "The same test's 0.75s burst p95 cap tracked the CI box's speed" / "The burst p95 is bounded by the 5s Redis socket timeout the test sets"
Current PR body caveat: "Burst bound is now 5s, so a 2s burst slowdown passes / The single-call 0.75s caps around it still catch a slow handler"
PR body proof: before run fails assert 0.8352554169832729 < 0.75. After run passes with c1_burst_p95 0.941s. With await task injected, the test fails with returned after 15.08s, no sooner than the 5.0s injected delay
tests/integration/management/test_user_updates_wedged_coordination_redis.py:31 sets _COORDINATION_SOCKET_TIMEOUT_SECONDS: Final = 5.0. Line 107 passes it as COORDINATION_REDIS_SOCKET_TIMEOUT. Line 248 calls assert_cut_short(timings["c1_burst_p95"], injected_delay=_COORDINATION_SOCKET_TIMEOUT_SECONDS)
tests/integration/coordination_redis_proxy_config.yaml:12 sets socket_timeout: os.environ/COORDINATION_REDIS_SOCKET_TIMEOUT
Other handler assertions at lines 144-345 still use _HANDLER_BUDGET_SECONDS = 0.75s
GitHub does not allow this App to resolve this thread. A repository maintainer must do it manually.
Reviewed a20c89dc2a39 · View follow-up
|
@litereview code-review |
[Medium impact] The PR appears safe to merge, with no new actionable issue found SummaryThis PR replaces timing races with controlled clocks and ties the wedged-Redis burst check to the proxy's Redis wait limits
Reviews (9) · Last reviewed commit: "Merge remote-tracking branch 'origin/mai..." · Reviewed by Greptile |
…roxy's 2s wait cap The lockout tests now set the login throttle's clock instead of reading the real one, so Retry-After is pinned at 77 and a round-down fails on every run The wedged Redis burst p95 is now bounded by the 2s cap the proxy puts on its own Redis waits, so a burst wait capped under the 5s socket timeout still fails the test The fresh post-kill clients keep the harness's 2s keep-alive expiry, here and in the two tests #47080 changed
|
@litereview code-review |
…y the imported eviction cap The refused attempt now runs with 76.4s left on the 77s block, where ceil gives 77 but round and int give 76, so both lockout tests fail if Retry-After stops rounding up. The burst bound imports _BULK_EVICTION_WAIT_SECONDS instead of copying its 2s value, so lowering the cap moves the bound with it.
|
@litereview code-review |
… and the socket timeout Any wait the proxy puts on the stopped Redis lasts at least the shorter of the two, so the bound now follows whichever one a later change lowers.
|
@litereview code-review |
# Conflicts: # litellm/proxy/db/db_transaction_queue/spend_log_cleanup.py # tests/unit/proxy/proxy_server/test_routes_login_sso.py
…p the post-kill block as on main The post-kill reset is already fixed on main by making kill() wait for the worker's last thread, so the fresh-client and keep-alive edits go back to main's version. The tool index cleanup test now advances the injected clock instead of timing the real one, and the lockout clock helper gets a type hint.
…drive the run budget tests with the manual clock
|
bugbot run |
There was a problem hiding this comment.
✅ Bugbot reviewed your changes and found no new issues!
Comment @cursor review or bugbot run to trigger another review on this PR
Reviewed by Cursor Bugbot for commit c975dc6. Configure here.
…#47108 to rc/1.108.0 Takes only BerriAI#47108's (e85cb40) changes to coordination_redis_proxy_config.yaml and test_user_updates_wedged_coordination_redis.py. They set the coordination Redis socket timeout and define the shortest Redis wait bound that BerriAI#49554's /customer/update fix uses
This stops CI tests from failing at random on slow runners, and each one still catches the bug it guards. The spend log cleanup and login lockout tests now drive their own clock instead of racing the real one. The stalled Redis burst check is now bounded by the shortest wait the proxy puts on Redis, not a fixed 0.75 seconds
Details
TLDR
Problem this solves:
How it solves it:
SpendLogCleanuptakes an injectedclock, the tests drive a manual oneUser Flow
Before: a contributor's PR goes red on tests it never touched, and a rerun at the same commit passes
burst p95 0.832sagainst the 0.75s cap or Retry-After'76' == '77'After: the same tests pass on a slow runner and still fail when the code they guard breaks
burst p95 5.808s reached the 2.0scapPre-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 moreDelays 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
Last updated: c975dc6. The mutation checks ran on 15e9566 and 19fd23e. Changes since: a merge of main. Proof remains valid because
git diffshows no change since then to the files each check mutated or the tests it ran. Verification: every other case below ran at c975dc6The burst case runs pinned to one CPU core with
taskset, like a loaded CI runner, with 2 proxy workers andDATABASE_URLandLITELLM_LICENSEset.Before (bad98c4)
Burst p95 on a one-core runner
taskset -c 4burst p95 0.979sCleanup and lockout with a forced stall
Steps and output
time.sleepbefore the refused sign-in (1.1s) and before the first cleanup delete batch (1.1s, or 3.1s for the two run budget tests, whose wall-time bounds a 1.1s stall still passes), the way a loaded runner stalls a testLive proxy with the coordination Redis stopped
Steps and output
A proxy at this commit with 2 workers,
tests/integration/coordination_redis_proxy_config.yaml, a fresh database and its own Redis, started like this ($Lis the run's scratch directory)kill -STOP, soredis-cli pinggets no answermax_budgetreturns 200 in 0.029smax_budgetreturns 200 in 5.060s, the 5s socket timeoutAfter (c975dc6)
Burst p95 on a one-core runner
taskset -c 5c1_burst_p95of 0.991s, under the 2s boundThe burst check still fails when updates wait on Redis
_ = await asyncio.wait((task,), timeout=_BULK_EVICTION_WAIT_SECONDS)forawait asyncio.sleep(0)inauth_cache_invalidation_pubsub.py), and skip the single-call asserts in a scratch copy. The burst check fails, and the change was reverted. The mutated file and the test are unchanged sinceLive proxy with the coordination Redis stopped
Steps and output
A proxy at this commit with 2 workers,
tests/integration/coordination_redis_proxy_config.yaml, a fresh database and its own Redis, started like this ($Lis the run's scratch directory)kill -STOP, soredis-cli pinggets no answermax_budgetreturns 200 in 0.058smax_budgetreturns 200 in 5.139s, the 5s socket timeoutCleanup and lockout with a forced stall
Steps and output
test_login_utils.pylockout tests. Dropping the batch loop's deadline check fails both run budget tests, and giving each cleanup group a fresh budget fails the shared budget test. Each change was reverted'76' == '77', giving the first cleanup group the whole budget leaves the health check table without a delete and starves the tool index, and giving the tool index its own full budget failssplitting the budget must not extend the run: 1.5000000000000002sDetails on the burst bound and the cleanup and lockout fixes
The burst sends 30 concurrent user updates to the surviving worker while the coordination Redis is stopped with SIGSTOP. A request that waits on that Redis takes at least 2s, since the proxy caps its eviction waits at 2s and the socket timeout the test now sets through
COORDINATION_REDIS_SOCKET_TIMEOUTincoordination_redis_proxy_config.yamlis 5s. In the live proxy case /key/update, which waits on Redis, took about 5.1s while a single user update took under 0.06s. So the burst p95 must stay under the shorter of the two, which the test computes from the imported_BULK_EVICTION_WAIT_SECONDS. That is about twice the slowest healthy burst seen, 1.005s in a Before run at 6063187. The 2s bound was picked over two other options. A 5s bound would pass a wait capped at 2s. A control burst on the same worker would not run on the same number of workers, because the replacement worker boots during the kill block. WithCOORDINATION_REDIS_SOCKET_TIMEOUTunset the client keeps its 5s default, and the three SAML cells that also loadcoordination_redis_proxy_config.yamlpassed. The same test also failed with a connection reset afterkill()in CircleCI, which #47148 already fixed on main by makingkill()wait until the worker's last thread exitstests/unit/proxy/test_spend_log_cleanup.py::test_cleanup_groups_share_budget_so_health_checks_still_get_a_deletefailed on attempt 1 and passed on attempt 2 of run 38975567409 withassert 'LiteLLM_HealthCheckTable' in {'LiteLLM_SpendLogs'}. The test ran the cleanup against the realtime.monotonicwith a 1s run budget, so a loaded runner spent the whole budget before the health check group got its turn.SpendLogCleanup.__init__now takes a keywordclockdefaulting totime.monotonic, every deadline read goes through it, and_group_deadlinetakesnowexplicitly. The test advances a manual clock by 0.1s per delete batch, so the spend log group always runs out of its half share and the health check group always gets a delete.test_spend_logs_backlog_cannot_starve_tool_index_cleanupraced the same real clock with a 2.5s wall-time check, and now uses the same manual clock and checks the run stays inside its budget. The two run budget tests checked wall time against 3s and 2.5s, and now check that the manual clock stops under 1.15s. Production callers constructSpendLogCleanup()with no arguments, so they keeptime.monotonictests/unit/proxy/proxy_server/test_routes_login_sso.py::test_the_form_returns_a_human_readable_lockout_pagefailed on attempt 1 and passed on attempt 2 of run 38958839882, where the page saidTry again in about 76 secondsagainst an expected 77 after a 1.07s test call. Retry-After is the ceiling of the time left on the block, so it correctly drops to 76 once more than a second passes after the block is installed. The siblingtest_a_refused_attempt_carries_retry_afterpinned the same value the same way. Both now set the throttle's clock to 1000.0 while the block goes in and to 1000.6 before the refused attempt, so the 77s block has 76.4s left. Rounding up gives 77, while rounding to the nearest second or truncating gives 76. The form test also checks that the page shows 77, and the frozen clock in the database-user lockout test now goes through the same helper. The four Retry-After checks intests/unit/proxy/auth/test_login_utils.pyread the same real clock and now set it the same way#46898 has human review, so it only got the hunk drop its reviewer asked for. #41219, #42936 and #43437 each have a human approval and were left untouched
Observed during the run:
Type
✅ Test
Caveats (if any)
Low
_BULK_EVICTION_WAIT_SECONDStimeinstead of injecting a clockosv-scanis red here and on main, from lockfile advisoriesFinal Attestation