Skip to content

test: fix flaky team delete, refusal sink, loop-blocking, Moyai tamper and model-cost leak tests - #47135

Merged
mateo-berri merged 6 commits into
mainfrom
litellm_deflake_team_delete_and_refusal_sink
Oct 20, 2026
Merged

mateo-berri merged 6 commits into
mainfrom
litellm_deflake_team_delete_and_refusal_sink

Conversation

@devin-ai-integration

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

Copy link
Copy Markdown
Contributor

TLDR

Problem this solves:

  • Two integration tests flaked on CircleCI pipeline 91295, and four timing-based unit tests flaked in this PR's own CI
  • The large team delete test got a 503 no_db_connection while warming keys
  • The unauthenticated refusal test asserted an empty sink and raced the sink flush

How it solves it:

  • Key warmup and post-delete checks now use 2 threads, the management proxy's DB pool limit, instead of 16
  • The refusal test waits for the stranger key's auth failure event and asserts exactly one, with status failure
  • The 401 and no-upstream assertions, and the all-2,500-keys status assertions, are unchanged
  • Four unit tests that broke the required unit passed check on this PR now prove event-loop progress with thread events instead of wall-clock timing, flip a real signature byte instead of the last base64 chars, and copy litellm.model_cost before registering overrides

The proxy logs auth rejections through the failure hook on purpose, so the old empty-sink check only passed when it ran before the one-second flush. The test is renamed to match what it now checks

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

Screenshots / Proof of Fix

Test-only change, so the proof is the integration rig itself, which runs a real proxy with real Postgres. Each changed test passed 3 runs in a row locally on this branch: the refusal test in 88s, 79s and 78s, and the team delete test in 227s, 232s and 234s

CircleCI failures this fixes: jobs 2261488 (team delete, 503 no_db_connection) and 2261466 (refusal, sink event for the stranger key)

Link to Devin session: https://app.devin.ai/sessions/a19d7fd2407a46ab98d7a4218eccd904
Open in Devin Desktop: https://app.devin.ai/desktop/session/a19d7fd2407a46ab98d7a4218eccd904?variant=devin


Note

Low Risk
Changes are limited to test assertions and harness concurrency; no production code paths are modified.

Overview
This PR stabilizes several flaky tests without changing production behavior.

The large team-delete integration test now warms and checks thousands of keys with 2 concurrent threads (aligned with the proxy DB pool) instead of 16, avoiding 503 no_db_connection during warmup. The unauthenticated refusal integration test waits for one sink failure event for the invalid key (status failure) instead of asserting an empty sink, matching intentional auth-failure logging and removing a race with the flush.

Event-loop non-blocking checks in Vertex Gemini count-tokens and proxy token-counter unit tests no longer rely on wall-clock sleeps; they use threading events to prove the loop progressed while a download or vault lookup was pending. The Moyai exchange tamper test flips a byte in the decoded HMAC rather than editing trailing base64. A model-cost unit test copies litellm.model_cost via monkeypatch before register_model so overrides do not leak across tests in the same process.

Reviewed by Cursor Bugbot for commit 652fc03. Bugbot is set up for automated code reviews on this repo. Configure here.

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

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

@codecov

codecov Bot commented Oct 17, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@devin-ai-integration devin-ai-integration Bot left a comment •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Note

Newer findings are available below. Devin Review posted a newer report on this PR, in addition to the findings presented here.

🔍 Devin Review: 2 flags

Not posted on this PR by your GitHub settings — view them in Devin Review. (Configure)

Devin Review

…istic

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

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 sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@devin-ai-integration devin-ai-integration Bot changed the title test(integration): stabilize auth and team delete checks test: fix flaky team delete, refusal sink, loop-blocking and Moyai tamper tests Oct 18, 2026
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@devin-ai-integration devin-ai-integration Bot changed the title test: fix flaky team delete, refusal sink, loop-blocking and Moyai tamper tests test: fix flaky team delete, refusal sink, loop-blocking, Moyai tamper and model-cost leak tests Oct 20, 2026
devin-ai-integration[bot]

This comment was marked as resolved.

…r starts

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

Copy link
Copy Markdown
Contributor Author

bugbot run

1 similar comment
@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 652fc03. Configure here.

@mateo-berri

Copy link
Copy Markdown
Contributor

@litereview all

@litereview

litereview Bot commented Oct 20, 2026

Copy link
Copy Markdown

Review not started

This review command is unavailable for this repository or caller. Check the agent or group names and the permissions in People and Repositories.

@mateo-berri

Copy link
Copy Markdown
Contributor

@litereview full

@litereview

litereview Bot commented Oct 20, 2026

Copy link
Copy Markdown

⚠️ full

Scope: full · Full PR review.

Completed · Some checks not run.

Verdict: no actionable defects

This PR changes tests only. No production module is modified, so no production code depends on anything that changed. The blast-radius walk therefore covered the test harnesses these tests depend on.

What changed and what I checked

  • test_utils.py model_cost leak: register_model writes through _builtin_cost_map(), which returns the live litellm.model_cost (litellm/utils.py:3410). It also updates entries in place with cost_map.update(...) (utils.py:3427). Under the old code, saved_model_cost was the same object that got mutated, so the finally block restored an already-mutated dict. The new monkeypatch.setattr(litellm, "model_cost", dict(saved_model_cost)) points those writes at a copy, which fixes the leak. Restoring from finally and from monkeypatch does not conflict.
  • Event-loop tests in Vertex count-tokens and the proxy token counter:
    • Both now use a thread-event handshake. A helper task sets loop_ran only after the blocking call has started. The handler or vault then records that the loop made progress while it was still waiting.
    • If the code under test ran the download or lookup on the loop thread, the wait would time out after 5 s and the probe event would stay unset, so the test would fail. These tests are not test theater.
    • The added assert on lookup_started.wait closes a case where a failed wait was ignored.
  • Moyai tamper test: the old version edited the last base64 characters. Now one bit in the first byte of the decoded HMAC is flipped and the signature is re-encoded, so the signature always changes and padding or ignored-bit cases can no longer hide the edit.
  • Refusal sink test: await_key (tests/integration/_support/anthropic_refusal.py:451) polls until it finds at least one event. The test then asserts exactly one event with status failure. The 401 and no-upstream (_targets(rig.wire) == ()) assertions are unchanged. This matches the PR's stated intent that auth rejections are logged through the failure hook.
  • Team delete thread count: going from 16 workers to 2 only changes how fast the harness runs. The assertions are the same.

Compatibility

There is no backward-incompatible change, so the test: title without a breaking-change marker is correct.

Checks and execution details
  • Passed · Changed unit tests on PR head (optional): I ran pytest tests/unit/proxy/test_moyai_endpoints.py tests/unit/llms/vertex_ai/count_tokens/test_context.py tests/unit/proxy/test_proxy_token_counter.py::test_region_lookup_for_a_shipped_count_model_leaves_the_event_loop_free -k 'tamper or event_loop': 4 passed. I also ran pytest tests/unit/test_utils.py -k replays_register_model_overrides: 6 passed.
  • Not run · Integration rig (team delete, refusal sink) (optional): Not run. These need the full proxy, Postgres, and sink rig, and each run takes several minutes. I reviewed both changes by reading await_key and _statuses.
  • Not run · Live base-vs-head proxy A/B (optional): Not needed: the diff changes tests only, so no runtime behavior can differ between base and head.

View review · Reviewed 652fc03cb6aa

@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 7e8be61 into main Oct 20, 2026
90 checks passed
@mateo-berri
mateo-berri deleted the litellm_deflake_team_delete_and_refusal_sink branch October 20, 2026 18:01
yuneng-berri added a commit that referenced this pull request Nov 4, 2026
…ng on 1.108

Brings over the test_utils.py isolation fix from #47135. The replay test registered openai/gpt-4o with supports_function_calling false into the shared cost map, so a later function calling test on the same worker failed depending on xdist ordering
yuneng-berri added a commit that referenced this pull request Nov 4, 2026
…ng on 1.108

Brings over the test_utils.py isolation fix from #47135. The replay test registered openai/gpt-4o with supports_function_calling false into the shared cost map, so a later function calling test on the same worker failed depending on xdist ordering
DeoLeung pushed a commit to aiyou178/litellm that referenced this pull request Nov 5, 2026
…7135 to rc/1.108.0

Takes only the max_workers change in test_team_delete_large_membership.py from 7e8be61. The 16-thread key warmup slowed the /team/delete that follows it to 5.4-11.6s locally against the client's 15s timeout, and 2 threads brings it to 4.1-5.4s
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