Skip to content

test: fix flaky spend-log cleanup budget, login lockout, and wedged Redis tests - #47108

Merged
mateo-berri merged 10 commits into
mainfrom
litellm_deflake_20261017
Oct 29, 2026
Merged

mateo-berri merged 10 commits into
mainfrom
litellm_deflake_20261017

Conversation

@devin-ai-integration

@devin-ai-integration devin-ai-integration Bot commented Oct 17, 2026 •

Copy link
Copy Markdown
Contributor

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:

  • Cleanup, lockout, and burst tests flipped between pass and fail at one SHA
  • Four cleanup budget tests raced the real clock against their budget
  • Six login lockout tests pinned Retry-After while the clock kept moving
  • A wedged Redis test's 0.75s burst p95 cap tracked the CI box's speed

How it solves it:

  • SpendLogCleanup takes an injected clock, the tests drive a manual one
  • Lockout tests set the throttle's clock, so Retry-After is exactly 77
  • The burst p95 is bounded by the proxy's 2s cap on its Redis waits

User Flow

Before: a contributor's PR goes red on tests it never touched, and a rerun at the same commit passes

  1. A contributor pushes a PR to BerriAI/litellm that changes none of these tests
  2. On a loaded runner one fails, like burst p95 0.832s against the 0.75s cap or Retry-After '76' == '77'
  3. They rerun the job at the same commit, it passes, and the red check told them nothing

After: the same tests pass on a slow runner and still fail when the code they guard breaks

  1. A contributor pushes a PR to BerriAI/litellm that changes none of these tests
  2. On a loaded runner they all pass, the burst at a p95 of 0.991s
  3. A PR that makes user updates wait on the stalled Redis still fails, burst p95 5.808s reached the 2.0s cap

Pre-Submission checklist

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
  • Every automated review on my PR's latest commit has finished, and I have addressed or replied to each of its findings before requesting a maintainer review

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

Last updated: c975dc6. The mutation checks ran on 15e9566 and 19fd23e. Changes since: a merge of main. Proof remains valid because git diff shows no change since then to the files each check mutated or the tests it ran. Verification: every other case below ran at c975dc6

The burst case runs pinned to one CPU core with taskset, like a loaded CI runner, with 2 proxy workers and DATABASE_URL and LITELLM_LICENSE set.

INTEGRATION_WORKERS=2 LITELLM_MODE=PRODUCTION PYTHON_DOTENV_DISABLED=1 LITELLM_PRISMA_COMMAND_TIMEOUT=600 \
  taskset -c 4 .venv/bin/python tests/integration/run.py management \
  tests/integration/management/test_user_updates_wedged_coordination_redis.py::test_user_budget_updates_return_promptly_while_coordination_redis_is_wedged
Case Before (bad98c4) After (c975dc6)
Burst p95, one core Fails at 0.832s Passes at 0.991s
Cleanup and lockout, forced stall 10 fail 10 pass
Live proxy, Redis stopped p95 0.857s p95 1.251s

Before (bad98c4)

Burst p95 on a one-core runner

  1. Run the command above at the merge base with taskset -c 4
  2. It fails on the fixed cap, like CI's burst p95 0.979s
E   AssertionError: burst p95 0.832s
E   assert 0.8324410259956494 < 0.75
======================== 1 failed in 658.01s (0:10:58) =========================

Cleanup and lockout with a forced stall

Steps and output
  1. Write scratch copies of the ten tests at the merge base with this script. It adds a time.sleep before 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 test
  2. Run them with the runner below, which maps the scratch names back to the real files
  3. All ten fail the way CI saw them fail, without needing a slow runner
import pathlib, sys

tree = pathlib.Path(sys.argv[1])

def block(text, name):
    start = text.index(name)
    nxt = text.find("\ndef test_", start + 1)
    nxt_async = text.find("\n@pytest.mark.asyncio", start + 1)
    ends = [i for i in (nxt, nxt_async) if i != -1]
    return start, (min(ends) if ends else len(text))

def stall(text, cases):
    for name, anchor, insert in cases:
        start, end = block(text, name)
        body = text[start:end]
        assert body.count(anchor) >= 1, (name, anchor)
        body = body.replace(anchor, insert + anchor, 1)
        text = text[:start] + body + text[end:]
    return text

cleanup = (tree / "tests/unit/proxy/test_spend_log_cleanup.py").read_text()
helper = '''

def _stall_once(mock_db, seconds):
    original = mock_db.execute_raw
    seen = []

    async def stalled(*args):
        if not seen:
            time.sleep(seconds)
        seen.append(args)
        return await original(*args)

    mock_db.execute_raw = AsyncMock(side_effect=stalled)
'''
anchor = "    cleaner = SpendLogCleanup("
cleanup = stall(cleanup, (
    ("async def test_cleanup_groups_share_budget_so_health_checks_still_get_a_delete", anchor, "    _stall_once(mock_db, 1.1)\n"),
    ("async def test_spend_logs_backlog_cannot_starve_tool_index_cleanup", anchor, "    _stall_once(mock_db, 1.1)\n"),
    ("async def test_run_budget_stops_the_loop_and_leaves_the_backlog_for_the_next_run", anchor, "    _stall_once(mock_db, 3.1)\n"),
    ("async def test_run_budget_is_shared_across_tables_not_granted_per_table", anchor, "    _stall_once(mock_db, 3.1)\n"),
)) + helper
(tree / "tests/unit/proxy/test_scratch_stall_cleanup.py").write_text(cleanup)

sleep4 = '    __import__("time").sleep(1.1)\n'
sleep8 = '        __import__("time").sleep(1.1)\n'
login = (tree / "tests/unit/proxy/proxy_server/test_routes_login_sso.py").read_text()
login = stall(login, (
    ("def test_a_refused_attempt_carries_retry_after", "    refused = client.post(", sleep4),
    ("def test_the_form_returns_a_human_readable_lockout_page", "    refused = client.post(", sleep4),
))
(tree / "tests/unit/proxy/proxy_server/test_scratch_stall_login.py").write_text(login)

utils = (tree / "tests/unit/proxy/auth/test_login_utils.py").read_text()
utils = stall(utils, (
    ("async def test_too_many_failures_for_one_username_block_that_pair_and_carry_retry_after",
     "    with pytest.raises(ProxyException) as blocked:\n        await _guess(throttle)\n    assert blocked", sleep4),
    ("async def test_a_correct_password_is_refused_while_its_pair_is_blocked",
     "    with pytest.raises(ProxyException) as refused:\n        await _db_login", sleep4),
    ("async def test_a_source_block_outranks_a_pair_block_in_the_retry_after", "    for name in (", sleep4),
    ("async def test_a_redis_outage_falls_back_to_this_workers_own_counter",
     "        with pytest.raises(ProxyException) as blocked:", sleep8),
))
(tree / "tests/unit/proxy/auth/test_scratch_stall_login_utils.py").write_text(utils)
print("written")
#!/bin/zsh
T=$1
cd $T
print -r -- "### $(git rev-parse --short HEAD)"
.venv/bin/python $S/stall/make_stalled_v2.py $T
C=tests/unit/proxy/test_scratch_stall_cleanup.py
L=tests/unit/proxy/proxy_server/test_scratch_stall_login.py
U=tests/unit/proxy/auth/test_scratch_stall_login_utils.py
.venv/bin/python -m pytest -p no:cacheprovider -q -rf \
  "$C::test_cleanup_groups_share_budget_so_health_checks_still_get_a_delete" \
  "$C::test_spend_logs_backlog_cannot_starve_tool_index_cleanup" \
  "$C::test_run_budget_stops_the_loop_and_leaves_the_backlog_for_the_next_run" \
  "$C::test_run_budget_is_shared_across_tables_not_granted_per_table" \
  "$L::test_a_refused_attempt_carries_retry_after" \
  "$L::test_the_form_returns_a_human_readable_lockout_page" \
  "$U::test_too_many_failures_for_one_username_block_that_pair_and_carry_retry_after" \
  "$U::test_a_correct_password_is_refused_while_its_pair_is_blocked" \
  "$U::test_a_source_block_outranks_a_pair_block_in_the_retry_after" \
  "$U::test_a_redis_outage_falls_back_to_this_workers_own_counter" 2>&1 \
  | grep -E "^E   +(AssertionError|assert)|^FAILED|passed|failed" \
  | sed 's/test_scratch_stall_cleanup/test_spend_log_cleanup/; s/test_scratch_stall_login_utils/test_login_utils/; s/test_scratch_stall_login/test_routes_login_sso/'
$ $S/stall/run_v2.sh <merge-base worktree>
### bad98c4b02
written
E       AssertionError: assert '89' == '90'
E       AssertionError: assert '299' == '300'
23:13:25 - LiteLLM Proxy:WARNING: login_throttle.py:412 - Redis failed while counting Admin UI sign-in attempts; using this worker's own counters until it recovers: redis is down
23:13:25 - LiteLLM Proxy:WARNING: login_throttle.py:412 - Redis failed while counting Admin UI sign-in attempts; using this worker's own counters until it recovers: redis is down
23:13:25 - LiteLLM Proxy:WARNING: login_throttle.py:412 - Redis failed while counting Admin UI sign-in attempts; using this worker's own counters until it recovers: redis is down
23:13:25 - LiteLLM Proxy:WARNING: login_throttle.py:412 - Redis failed while counting Admin UI sign-in attempts; using this worker's own counters until it recovers: redis is down
23:13:25 - LiteLLM Proxy:WARNING: login_throttle.py:412 - Redis failed while counting Admin UI sign-in attempts; using this worker's own counters until it recovers: redis is down
23:13:25 - LiteLLM Proxy:WARNING: login_throttle.py:412 - Redis failed while counting Admin UI sign-in attempts; using this worker's own counters until it recovers: redis is down
23:13:27 - LiteLLM Proxy:WARNING: login_throttle.py:412 - Redis failed while counting Admin UI sign-in attempts; using this worker's own counters until it recovers: redis is down
WARNING  LiteLLM Proxy:login_throttle.py:412 Redis failed while counting Admin UI sign-in attempts; using this worker's own counters until it recovers: redis is down
WARNING  LiteLLM Proxy:login_throttle.py:412 Redis failed while counting Admin UI sign-in attempts; using this worker's own counters until it recovers: redis is down
WARNING  LiteLLM Proxy:login_throttle.py:412 Redis failed while counting Admin UI sign-in attempts; using this worker's own counters until it recovers: redis is down
WARNING  LiteLLM Proxy:login_throttle.py:412 Redis failed while counting Admin UI sign-in attempts; using this worker's own counters until it recovers: redis is down
WARNING  LiteLLM Proxy:login_throttle.py:412 Redis failed while counting Admin UI sign-in attempts; using this worker's own counters until it recovers: redis is down
WARNING  LiteLLM Proxy:login_throttle.py:412 Redis failed while counting Admin UI sign-in attempts; using this worker's own counters until it recovers: redis is down
WARNING  LiteLLM Proxy:login_throttle.py:412 Redis failed while counting Admin UI sign-in attempts; using this worker's own counters until it recovers: redis is down
        _install_real_auth(monkeypatch, max_failed_login_attempts_per_source=2, failed_login_block_seconds=77)
E       AssertionError: assert '76' == '77'
23:13:28 - LiteLLM Proxy:ERROR: proxy_server.py:18712 - litellm.proxy.proxy_server.login_v2(): Exception occurred - Too many failed sign-in attempts. Try again later.
litellm.proxy._types.ProxyException: Too many failed sign-in attempts. Try again later.
ERROR    LiteLLM Proxy:proxy_server.py:18712 litellm.proxy.proxy_server.login_v2(): Exception occurred - Too many failed sign-in attempts. Try again later.
litellm.proxy._types.ProxyException: Too many failed sign-in attempts. Try again later.
E           AssertionError: admin
E           assert '119' == '120'
E       AssertionError: assert 'LiteLLM_HealthCheckTable' in {'LiteLLM_SpendLogs'}
E       AssertionError: budget was granted per table, not per run: 3.275312850018963s
E       assert 3.275312850018963 < 2.5
E       AssertionError: budgeted run overran its deadline: 3.204550712951459s
E       assert 3.204550712951459 < 3
E       AssertionError: tool index cleanup was starved by the spend-log backlog
E       assert 0 > 0
        _install_real_auth(monkeypatch, max_failed_login_attempts_per_source=2, failed_login_block_seconds=77)
E       AssertionError: assert 'Try again in about 77 seconds' in '<html><body><h1>Too many sign-in attempts</h1><p>Try again in about 76 seconds</p></body></html>'
E       AssertionError: assert '76' == '77'
FAILED tests/unit/proxy/auth/test_login_utils.py::test_a_correct_password_is_refused_while_its_pair_is_blocked
FAILED tests/unit/proxy/auth/test_login_utils.py::test_a_redis_outage_falls_back_to_this_workers_own_counter
FAILED tests/unit/proxy/proxy_server/test_routes_login_sso.py::test_a_refused_attempt_carries_retry_after
FAILED tests/unit/proxy/auth/test_login_utils.py::test_a_source_block_outranks_a_pair_block_in_the_retry_after
FAILED tests/unit/proxy/test_spend_log_cleanup.py::test_cleanup_groups_share_budget_so_health_checks_still_get_a_delete
FAILED tests/unit/proxy/test_spend_log_cleanup.py::test_run_budget_is_shared_across_tables_not_granted_per_table
FAILED tests/unit/proxy/test_spend_log_cleanup.py::test_run_budget_stops_the_loop_and_leaves_the_backlog_for_the_next_run
FAILED tests/unit/proxy/test_spend_log_cleanup.py::test_spend_logs_backlog_cannot_starve_tool_index_cleanup
FAILED tests/unit/proxy/proxy_server/test_routes_login_sso.py::test_the_form_returns_a_human_readable_lockout_page
FAILED tests/unit/proxy/auth/test_login_utils.py::test_too_many_failures_for_one_username_block_that_pair_and_carry_retry_after
10 failed in 21.24s

Live 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 ($L is the run's scratch directory)

redis-server --port 31174 --bind 127.0.0.1 --save '' --appendonly no
DATABASE_URL=<fresh database> LITELLM_MASTER_KEY=<key> REDIS_HOST=127.0.0.1 REDIS_PORT=31174 \
  COORDINATION_REDIS_SOCKET_TIMEOUT=5 PYTHON_DOTENV_DISABLED=1 LITELLM_MODE=PRODUCTION \
  .venv/bin/python litellm/proxy/proxy_cli.py --config tests/integration/coordination_redis_proxy_config.yaml \
  --host 127.0.0.1 --port 27976 --num_workers 2 --use_prisma_db_push
  1. 30 concurrent POST /user/update with Redis healthy return 200 with a p95 of 0.953s
  2. Stop Redis with kill -STOP, so redis-cli ping gets no answer
  3. POST /user/update with a new max_budget returns 200 in 0.029s
  4. POST /key/update with a new max_budget returns 200 in 5.060s, the 5s socket timeout
  5. 30 concurrent POST /user/update all return 200 with a p95 of 0.857s, over the old 0.75s cap
NOTICE:  drop cascades to 117 other objects
DETAIL:  drop cascades to type "JobStatus"
drop cascades to type "AccountingEventKind"
drop cascades to type "AccountingDeliveryState"
drop cascades to type "AccountingDeliveryTarget"
drop cascades to table "LiteLLM_BudgetTable"
drop cascades to table "LiteLLM_CredentialsTable"
drop cascades to table "LiteLLM_ProxyModelTable"
drop cascades to table "LiteLLM_AgentsTable"
drop cascades to table "LiteLLM_AgentIdentity"
drop cascades to table "LiteLLM_RetiredAgentIdentity"
drop cascades to table "LiteLLM_RetiredAgent"
drop cascades to table "LiteLLM_VerifiedSubject"
drop cascades to table "LiteLLM_OrganizationTable"
drop cascades to table "LiteLLM_ModelTable"
drop cascades to table "LiteLLM_TeamTable"
drop cascades to table "LiteLLM_ProjectTable"
drop cascades to table "LiteLLM_DeletedTeamTable"
drop cascades to table "LiteLLM_UserTable"
drop cascades to table "LiteLLM_ObjectPermissionTable"
drop cascades to table "LiteLLM_MCPServerTable"
drop cascades to table "LiteLLM_MCPToolsetTable"
drop cascades to table "LiteLLM_MCPUserCredentials"
drop cascades to table "LiteLLM_UserProviderCredentials"
drop cascades to table "LiteLLM_MCPUserEnvVars"
drop cascades to table "LiteLLM_MCPServerOAuthClient"
drop cascades to table "LiteLLM_SSOIdentityAssertion"
drop cascades to table "LiteLLM_VerificationToken"
drop cascades to table "LiteLLM_JWTKeyMapping"
drop cascades to table "LiteLLM_DeprecatedVerificationToken"
drop cascades to table "LiteLLM_DeletedVerificationToken"
drop cascades to table "LiteLLM_EndUserTable"
drop cascades to table "LiteLLM_ModelAccessGroupBudgetTable"
drop cascades to table "LiteLLM_TagTable"
drop cascades to table "LiteLLM_Config"
drop cascades to table "LiteLLM_SpendLogs"
drop cascades to table "LiteLLM_BudgetWindowSpend"
drop cascades to table "LiteLLM_ErrorLogs"
drop cascades to table "LiteLLM_UserNotifications"
drop cascades to table "LiteLLM_TeamMembership"
drop cascades to table "LiteLLM_OrganizationMembership"
drop cascades to table "LiteLLM_InvitationLink"
drop cascades to table "LiteLLM_AuditLog"
drop cascades to table "LiteLLM_DailyUserSpend"
drop cascades to table "LiteLLM_DailyGlobalSpend"
drop cascades to table "LiteLLM_DailyOrganizationSpend"
drop cascades to table "LiteLLM_DailyEndUserSpend"
drop cascades to table "LiteLLM_DailyAgentSpend"
drop cascades to table "LiteLLM_DailyTeamSpend"
drop cascades to table "LiteLLM_DailyTagSpend"
drop cascades to table "LiteLLM_ProxyWorkerHeartbeat"
drop cascades to table "LiteLLM_CronJob"
drop cascades to table "LiteLLM_ManagedFileTable"
drop cascades to table "LiteLLM_ManagedObjectTable"
drop cascades to table "LiteLLM_ManagedFileContentTable"
drop cascades to table "LiteLLM_ManagedVectorStoreTable"
drop cascades to table "LiteLLM_ManagedVectorStoresTable"
drop cascades to table "LiteLLM_GuardrailsTable"
drop cascades to table "LiteLLM_DailyGuardrailMetrics"
drop cascades to table "LiteLLM_DailyGuardrailUsageUnits"
drop cascades to table "LiteLLM_DailyPolicyMetrics"
drop cascades to table "LiteLLM_SpendLogGuardrailIndex"
drop cascades to table "LiteLLM_SpendLogToolIndex"
drop cascades to table "LiteLLM_DailyToolSpend"
drop cascades to table "LiteLLM_DailyModelUsage"
drop cascades to table "LiteLLM_DailyGatewayRequests"
drop cascades to table "LiteLLM_DailyGatewayFailedRequests"
drop cascades to table "LiteLLM_DailyRequestErrors"
drop cascades to table "LiteLLM_PromptTable"
drop cascades to table "LiteLLM_HealthCheckTable"
drop cascades to table "LiteLLM_SearchToolsTable"
drop cascades to table "LiteLLM_SSOConfig"
drop cascades to table "LiteLLM_ManagedVectorStoreIndexTable"
drop cascades to table "LiteLLM_CacheConfig"
drop cascades to table "LiteLLM_UISettings"
drop cascades to table "LiteLLM_ConfigOverrides"
drop cascades to table "LiteLLM_SkillsTable"
drop cascades to table "LiteLLM_PolicyTable"
drop cascades to table "LiteLLM_PolicyAttachmentTable"
drop cascades to table "LiteLLM_ToolTable"
drop cascades to table "LiteLLM_AccessGroupTable"
drop cascades to table "LiteLLM_ClaudeCodePluginTable"
drop cascades to table "LiteLLM_MemoryTable"
drop cascades to table "LiteLLM_AdaptiveRouterState"
drop cascades to table "LiteLLM_AdaptiveRouterSession"
drop cascades to table "LiteLLM_AutoRouterBaselineComparison"
drop cascades to table "LiteLLM_AutoRouterBaselineObservation"
drop cascades to table "LiteLLM_AutoRouterSession"
drop cascades to table "LiteLLM_AutoRouterUserSession"
drop cascades to table "LiteLLM_AutoRouterDailySpend"
drop cascades to table "LiteLLM_ShadowEvalJob"
drop cascades to table "LiteLLM_ShadowEvalAttempt"
drop cascades to table "LiteLLM_ShadowEvalFunnel"
drop cascades to table "LiteLLM_WorkflowRun"
drop cascades to table "LiteLLM_WorkflowEvent"
drop cascades to table "LiteLLM_WorkflowMessage"
drop cascades to table "LiteLLM_BackgroundInteractionSettlement"
drop cascades to table "LiteLLM_Lens"
drop cascades to table "LiteLLM_LensRun"
drop cascades to table "LiteLLM_LensReview"
drop cascades to table "LiteLLM_LensWorker"
and 17 other objects (see server log for list)
$ curl -s -X POST http://localhost:27976/user/new -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H 'Content-Type: application/json' -d '{"user_id": "qa-wedged-96091cf8", "max_budget": 10.0, "auto_create_key": false}' -o /dev/null -w '%{http_code}\n'
200
$ curl -s -X POST http://localhost:27976/key/generate -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H 'Content-Type: application/json' -d '{"user_id": "qa-wedged-96091cf8", "max_budget": 5.0}' | python3 -c 'import json,sys; print(json.load(sys.stdin)["key"][:6] + "...")'
sk-6MM...
# Redis healthy
$ curl -s -X POST http://localhost:27976/user/update -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H 'Content-Type: application/json' -d '{"user_id": "qa-wedged-96091cf8", "max_budget": 11.0}' -o /dev/null -w '%{http_code} %{time_total}s\n'
200 0.044446s
$ redis-cli -p 31174 ping
PONG
# Control burst with Redis healthy
$ for i in $(seq 1 30); do curl -s -X POST http://localhost:27976/user/update -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H 'Content-Type: application/json' -d '{"user_id": "qa-wedged-96091cf8", "max_budget": '$((100 + i))'}' -o /dev/null -w '%{http_code} %{time_total}\n' & done | sort -k2 -n > $L/burst_healthy.txt; wait; cut -d' ' -f1 $L/burst_healthy.txt | sort | uniq -c; echo "p95 $(sed -n 28p $L/burst_healthy.txt | cut -d' ' -f2)s max $(tail -1 $L/burst_healthy.txt | cut -d' ' -f2)s"
     30 200
p95 0.952996s max 0.973828s
# Wedge the coordination Redis
$ kill -STOP 529239
$ timeout 3 redis-cli -p 31174 ping || echo 'no answer after 3s'
no answer after 3s
$ curl -s -X POST http://localhost:27976/user/update -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H 'Content-Type: application/json' -d '{"user_id": "qa-wedged-96091cf8", "max_budget": 98.0}' -o /dev/null -w '%{http_code} %{time_total}s\n'
200 0.029278s
$ curl -s -X POST http://localhost:27976/key/update -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H 'Content-Type: application/json' -d '{"key": "'$VIRTUAL_KEY'", "max_budget": 6.0}' -o /dev/null -w '%{http_code} %{time_total}s\n'
200 5.060118s
$ for i in $(seq 1 30); do curl -s -X POST http://localhost:27976/user/update -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H 'Content-Type: application/json' -d '{"user_id": "qa-wedged-96091cf8", "max_budget": '$((200 + i))'}' -o /dev/null -w '%{http_code} %{time_total}\n' & done | sort -k2 -n > $L/burst.txt; wait; cut -d' ' -f1 $L/burst.txt | sort | uniq -c; echo "p95 $(sed -n 28p $L/burst.txt | cut -d' ' -f2)s max $(tail -1 $L/burst.txt | cut -d' ' -f2)s"
     30 200
p95 0.856966s max 0.898780s
# Unwedge
$ kill -CONT 529239
$ redis-cli -p 31174 ping
PONG

After (c975dc6)

Burst p95 on a one-core runner

  1. Run the command above at the tip with taskset -c 5
  2. It passes with a c1_burst_p95 of 0.991s, under the 2s bound
[gw0] [100%] PASSED tests/integration/management/test_user_updates_wedged_coordination_redis.py::test_user_budget_updates_return_promptly_while_coordination_redis_is_wedged
======================== 1 passed in 662.94s (0:11:02) =========================
$ grep -o "'c1_burst_p95': [0-9.]*" results/junit.xml
'c1_burst_p95': 0.9905479070730507
The burst check still fails when updates wait on Redis
  1. At 19fd23e, make each user update wait up to the 2s eviction cap for its publish (_ = await asyncio.wait((task,), timeout=_BULK_EVICTION_WAIT_SECONDS) for await asyncio.sleep(0) in auth_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 since
E   AssertionError: burst p95 5.808s reached the 2.0s shortest wait the proxy puts on Redis, so burst updates waited on the wedged Redis
E   assert 5.808320871088654 < 2.0
======================== 1 failed in 464.29s (0:07:44) =========================

Live 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 ($L is the run's scratch directory)

redis-server --port 27580 --bind 127.0.0.1 --save '' --appendonly no
DATABASE_URL=<fresh database> LITELLM_MASTER_KEY=<key> REDIS_HOST=127.0.0.1 REDIS_PORT=27580 \
  COORDINATION_REDIS_SOCKET_TIMEOUT=5 PYTHON_DOTENV_DISABLED=1 LITELLM_MODE=PRODUCTION \
  .venv/bin/python litellm/proxy/proxy_cli.py --config tests/integration/coordination_redis_proxy_config.yaml \
  --host 127.0.0.1 --port 28014 --num_workers 2 --use_prisma_db_push
  1. 30 concurrent POST /user/update with Redis healthy return 200 with a p95 of 0.773s
  2. Stop Redis with kill -STOP, so redis-cli ping gets no answer
  3. POST /user/update with a new max_budget returns 200 in 0.058s
  4. POST /key/update with a new max_budget returns 200 in 5.139s, the 5s socket timeout
  5. 30 concurrent POST /user/update all return 200 with a p95 of 1.251s, under the 2s bound
$ curl -s -X POST http://localhost:28014/user/new -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H 'Content-Type: application/json' -d '{"user_id": "qa-wedged-58f25b99", "max_budget": 10.0, "auto_create_key": false}' -o /dev/null -w '%{http_code}\n'
200
$ curl -s -X POST http://localhost:28014/key/generate -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H 'Content-Type: application/json' -d '{"user_id": "qa-wedged-58f25b99", "max_budget": 5.0}' | python3 -c 'import json,sys; print(json.load(sys.stdin)["key"][:6] + "...")'
sk-qip...
# Redis healthy
$ curl -s -X POST http://localhost:28014/user/update -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H 'Content-Type: application/json' -d '{"user_id": "qa-wedged-58f25b99", "max_budget": 11.0}' -o /dev/null -w '%{http_code} %{time_total}s\n'
200 0.041884s
$ redis-cli -p 27580 ping
PONG
# Control burst with Redis healthy
$ for i in $(seq 1 30); do curl -s -X POST http://localhost:28014/user/update -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H 'Content-Type: application/json' -d '{"user_id": "qa-wedged-58f25b99", "max_budget": '$((100 + i))'}' -o /dev/null -w '%{http_code} %{time_total}\n' & done | sort -k2 -n > $L/burst_healthy.txt; wait; cut -d' ' -f1 $L/burst_healthy.txt | sort | uniq -c; echo "p95 $(sed -n 28p $L/burst_healthy.txt | cut -d' ' -f2)s max $(tail -1 $L/burst_healthy.txt | cut -d' ' -f2)s"
     30 200
p95 0.772512s max 0.802095s
# Wedge the coordination Redis
$ kill -STOP 532701
$ timeout 3 redis-cli -p 27580 ping || echo 'no answer after 3s'
no answer after 3s
$ curl -s -X POST http://localhost:28014/user/update -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H 'Content-Type: application/json' -d '{"user_id": "qa-wedged-58f25b99", "max_budget": 98.0}' -o /dev/null -w '%{http_code} %{time_total}s\n'
200 0.057566s
$ curl -s -X POST http://localhost:28014/key/update -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H 'Content-Type: application/json' -d '{"key": "'$VIRTUAL_KEY'", "max_budget": 6.0}' -o /dev/null -w '%{http_code} %{time_total}s\n'
200 5.138537s
$ for i in $(seq 1 30); do curl -s -X POST http://localhost:28014/user/update -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H 'Content-Type: application/json' -d '{"user_id": "qa-wedged-58f25b99", "max_budget": '$((200 + i))'}' -o /dev/null -w '%{http_code} %{time_total}\n' & done | sort -k2 -n > $L/burst.txt; wait; cut -d' ' -f1 $L/burst.txt | sort | uniq -c; echo "p95 $(sed -n 28p $L/burst.txt | cut -d' ' -f2)s max $(tail -1 $L/burst.txt | cut -d' ' -f2)s"
     30 200
p95 1.251452s max 1.286130s
# Unwedge
$ kill -CONT 532701
$ redis-cli -p 27580 ping
PONG

Cleanup and lockout with a forced stall

Steps and output
  1. Run the same scratch copies at the tip
  2. All ten pass, since each test drives its own clock
$ $S/stall/run_v2.sh <tip worktree>
### c975dc60bd
written
10 passed in 26.29s
  1. At 15e9566 each test still caught its bug, and the files below are unchanged since. Rounding the time left to the nearest second or truncating it fails all four test_login_utils.py lockout 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
$ M=$S/stall/mutate_r4.py; U=tests/unit/proxy/auth/test_login_utils.py; C=tests/unit/proxy/test_spend_log_cleanup.py
$ python $M litellm/proxy/auth/login_throttle.py "max(math.ceil(expires_at - time.time()), 0)" "max(round(expires_at - time.time()), 0)"
$ pytest -q $U::<the four lockout tests>
E       AssertionError: assert '89' == '90'
E       AssertionError: assert '299' == '300'
E           AssertionError: admin
E           assert '119' == '120'
E       AssertionError: assert '76' == '77'
4 failed in 4.48s
$ git checkout -- litellm/proxy/auth/login_throttle.py
$ python $M litellm/proxy/auth/login_throttle.py "max(math.ceil(expires_at - time.time()), 0)" "max(int(expires_at - time.time()), 0)"
$ pytest -q $U::<the four lockout tests>
E       AssertionError: assert '89' == '90'
E       AssertionError: assert '299' == '300'
E           AssertionError: admin
E           assert '119' == '120'
E       AssertionError: assert '76' == '77'
4 failed in 4.08s
$ git checkout -- litellm/proxy/auth/login_throttle.py
# the batch loop never checks the run deadline: `if self._clock() >= deadline:` -> `if False:`
$ pytest -q $C::test_run_budget_stops_the_loop_and_leaves_the_backlog_for_the_next_run $C::test_run_budget_is_shared_across_tables_not_granted_per_table
E       AssertionError: budget was granted per table, not per run: 25.000000000000085s
E       assert 25.000000000000085 < 1.15
E       AssertionError: assert 'batch_cap_reached' == 'budget_exhausted'
2 failed in 33.20s
$ git checkout -- litellm/proxy/db/db_transaction_queue/spend_log_cleanup.py
# every cleanup group gets a fresh 1s budget: `_group_deadline` returns `now + 1.0`
$ pytest -q $C::test_run_budget_stops_the_loop_and_leaves_the_backlog_for_the_next_run $C::test_run_budget_is_shared_across_tables_not_granted_per_table
E       AssertionError: budget was granted per table, not per run: 3.3000000000000016s
E       assert 3.3000000000000016 < 1.15
1 failed, 1 passed in 7.41s
$ git checkout -- litellm/proxy/db/db_transaction_queue/spend_log_cleanup.py
$ pytest -q $U::<the four lockout tests> $C::<the two run budget tests>
6 passed in 4.84s
  1. At 19fd23e the same kind of check covered the other four tests. Rounding fails the SSO lockout test on '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 fails splitting the budget must not extend the run: 1.5000000000000002s
Details 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_TIMEOUT in coordination_redis_proxy_config.yaml is 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. With COORDINATION_REDIS_SOCKET_TIMEOUT unset the client keeps its 5s default, and the three SAML cells that also load coordination_redis_proxy_config.yaml passed. The same test also failed with a connection reset after kill() in CircleCI, which #47148 already fixed on main by making kill() wait until the worker's last thread exits

tests/unit/proxy/test_spend_log_cleanup.py::test_cleanup_groups_share_budget_so_health_checks_still_get_a_delete failed on attempt 1 and passed on attempt 2 of run 38975567409 with assert 'LiteLLM_HealthCheckTable' in {'LiteLLM_SpendLogs'}. The test ran the cleanup against the real time.monotonic with 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 keyword clock defaulting to time.monotonic, every deadline read goes through it, and _group_deadline takes now explicitly. 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_cleanup raced 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 construct SpendLogCleanup() with no arguments, so they keep time.monotonic

tests/unit/proxy/proxy_server/test_routes_login_sso.py::test_the_form_returns_a_human_readable_lockout_page failed on attempt 1 and passed on attempt 2 of run 38958839882, where the page said Try again in about 76 seconds against 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 sibling test_a_refused_attempt_carries_retry_after pinned 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 in tests/unit/proxy/auth/test_login_utils.py read 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:

  • An SSO database-outage test failed at both base and tip
    • This PR leaves it alone, it never loads the changed config
  • A load spike pushed one live burst to 2.37s
    • This PR leaves it alone, a rerun gave 0.857s

Type

✅ Test

Caveats (if any)

Low

  • The burst bound follows the proxy's private _BULK_EVICTION_WAIT_SECONDS
    • A PR lowering it under about 1s would see this test flake in its own CI
  • A slowdown under 2s that is not a Redis wait still passes the burst bound
    • The single-call 0.75s caps still catch it on a lone call
  • The lockout tests monkeypatch the module's time instead of injecting a clock
  • osv-scan is red here and on main, from lockfile advisories

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

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@devin-ai-integration

devin-ai-integration Bot commented Oct 17, 2026 •

Copy link
Copy Markdown
Contributor Author

I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".

  • Disable automatic comment, CI, and merge conflict monitoring

@CLAassistant

CLAassistant commented Oct 17, 2026 •

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution.
1 out of 2 committers have signed the CLA.

✅ mateo-berri
❌ devin-ai-integration[bot]
You have signed the CLA already but the status is still pending? Let us recheck it.

@codspeed

codspeed Bot commented Oct 17, 2026 •

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

1 warning

⚠️ 1 benchmark is dominated by system calls

System calls cannot be simulated consistently and are left out of the measure. The reported value understates the real cost. Switch to the Walltime instrument to measure them.

Learn more about system calls

See affected benchmarks

✅ 38 untouched benchmarks


Comparing litellm_deflake_20261017 (c975dc6) with main (3f5e42d)

Open in CodSpeed

@codecov

codecov Bot commented Oct 17, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 91.30435% with 2 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
...proxy/db/db_transaction_queue/spend_log_cleanup.py 91.30% 2 Missing ⚠️

📢 Thoughts on this report? Let us know!

@BrickerP BrickerP left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.
@mateo-berri

Copy link
Copy Markdown
Contributor

@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

@mateo-berri

Copy link
Copy Markdown
Contributor

@litereview code-review

@litereview

litereview Bot commented Oct 17, 2026 •

Copy link
Copy Markdown

⚠️ code-review

5/5 · Ready for human review

Scope: full · Full PR review.

Completed · Some checks not run.

No correctness findings.

Checks and execution details
  • Passed · Real testing evidence (required): Not applicable: no LLM translation changes in the scoped paths. The PR touches litellm/proxy/db/db_transaction_queue/spend_log_cleanup.py and files under tests/. It changes nothing under litellm/llms/** or litellm/litellm_core_utils/prompt_templates/**.

  • Passed · Compatibility requirements (required): No supported behavior breaks.

  • SpendLogCleanup.__init__ gains an optional keyword-only clock that defaults to time.monotonic. Both production callers (proxy_server.py:8180, proxy_server.py:11427) call SpendLogCleanup() with no arguments, so their behavior is unchanged.

  • The private static method _group_deadline now takes now. All six call sites in the module pass self._clock(), and nothing outside the module calls it.

  • The test YAML adds socket_timeout: os.environ/COORDINATION_REDIS_SOCKET_TIMEOUT. When that variable is unset, the client keeps its 5s default. The earlier review verified this through exclude_none.

No ! marker is needed.

  • Passed · Changed behavior and result consistency (required): Production path: every time.monotonic() read in spend_log_cleanup.py now goes through self._clock(). I traced the run deadline, the group shares, the batch loop, the exception classification, _finish_table, the partition branch and the run summary. grep finds no direct time. calls left apart from the default argument. The partition branch calls _group_deadline(deadline, groups_remaining=2, now=self._clock()), which matches the new signature.

Tests:

  • The cleanup test advances a manual clock by 0.1s per execute_raw call. The spend-log group therefore uses up its half share without depending on wall time.
  • The lockout tests set login_throttle.time to 1000.0 and then 1000.6. login_throttle.py:371 returns ceil(expires_at - time.time()), which is ceil(76.4) = 77, so a floor or nearest-second rounding would fail.
  • The integration tests open fresh post-kill clients with GATEWAY_LIMITS (keepalive_expiry=2). The burst p95 bound is min(_BULK_EVICTION_WAIT_SECONDS, 5.0), and the PR description now discloses it.

Standards: I read tests/AGENTS.md, tests/unit/AGENTS.md and tests/integration/AGENTS.md, and the diff violates none of them.

  • Passed · Unit tests for changed files (optional): .venv/bin/python -m pytest -q tests/unit/proxy/test_spend_log_cleanup.py tests/unit/proxy/proxy_server/test_routes_login_sso.py reported 116 passed in 14.52s.
  • Not run · Wedged Redis / worker-kill integration tests (optional): These tests need Postgres, Redis and a multi-worker proxy, and each run takes 7 to 20 minutes. I relied on the author's recorded runs and on code inspection. Only test files changed here.

View review · Reviewed d8e30572776f

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)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Low · Wedged Redis burst cap relaxed from 0.75s to 5s while the PR says it is unchanged

  1. 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".
  2. The diff replaces assert timings["c1_burst_p95"] &lt; _HANDLER_BUDGET_SECONDS (0.75s) with assert_cut_short(..., injected_delay=_COORDINATION_SOCKET_TIMEOUT_SECONDS). That helper only asserts p95 &lt; 5.0.
  3. The PR also pins socket_timeout in coordination_redis_proxy_config.yaml to make 5s the comparison point.
  4. 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 &lt; 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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The description now covers the burst fix, bounding the p95 by the 5s socket timeout the test sets, with before and after runs

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:

  1. 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.
  2. 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.
  3. 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.
  4. 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 &lt; 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

@mateo-berri mateo-berri changed the title test: fix flaky spend-log cleanup budget, login lockout, and post-kill wedged Redis tests test: fix flaky spend-log cleanup budget, login lockout, and wedged Redis tests Oct 17, 2026
@mateo-berri

Copy link
Copy Markdown
Contributor

@litereview code-review

@mateo-berri

Copy link
Copy Markdown
Contributor

@greptileai

@greptile-apps

greptile-apps Bot commented Oct 17, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge, with no new actionable issue found

Summary

This PR replaces timing races with controlled clocks and ties the wedged-Redis burst check to the proxy's Redis wait limits

  • Spend-log cleanup tests use a clock they can advance.
  • Login lockout tests keep their remaining-time checks fixed.
  • Wedged-Redis burst checks use the proxy’s Redis wait limit.

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
@mateo-berri

Copy link
Copy Markdown
Contributor

@litereview code-review

@mateo-berri

Copy link
Copy Markdown
Contributor

@greptileai

…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.
@mateo-berri

Copy link
Copy Markdown
Contributor

@litereview code-review

@mateo-berri

Copy link
Copy Markdown
Contributor

@greptileai

… 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.
@mateo-berri

Copy link
Copy Markdown
Contributor

@litereview code-review

@mateo-berri

Copy link
Copy Markdown
Contributor

@greptileai

# Conflicts:
#	litellm/proxy/db/db_transaction_queue/spend_log_cleanup.py
#	tests/unit/proxy/proxy_server/test_routes_login_sso.py
@mateo-berri

Copy link
Copy Markdown
Contributor

@greptileai

…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.
@mateo-berri

Copy link
Copy Markdown
Contributor

@greptileai

@mateo-berri

Copy link
Copy Markdown
Contributor

@greptileai

…drive the run budget tests with the manual clock
@mateo-berri

Copy link
Copy Markdown
Contributor

@greptileai

@mateo-berri

Copy link
Copy Markdown
Contributor

@greptileai

@mateo-berri

Copy link
Copy Markdown
Contributor

bugbot run

@cursor cursor Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@mateo-berri mateo-berri left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@mateo-berri
mateo-berri merged commit e85cb40 into main Oct 29, 2026
95 of 96 checks passed
@mateo-berri
mateo-berri deleted the litellm_deflake_20261017 branch October 29, 2026 10:46
DeoLeung pushed a commit to aiyou178/litellm that referenced this pull request Nov 5, 2026
…#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
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.

3 participants