Repository navigation
test: deflake the JEV classifier select and two router tests that inherited leaked state - #44840
Conversation
Base UI exposes its select option asynchronously, and the helper waits for the option and its positioner to become clickable before selection Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Collect earlier tests' garbage before warning capture so their unawaited coroutines cannot be attributed to the target's warning assertion Filter success-event callbacks by the request's litellm_call_id so queued logging work cannot replace the current request's captured messages 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)".
|
|
|
|
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 d97bba1. Configure here.
|
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
TLDR
Problem this solves:
How it solves it:
chooseSelectOptionhelperUser Flow
Before: a contributor's unrelated PR or a main push goes red on a UI or unit shard and has to be re-run
ui-unit-tests,enterprise-routingormisc-dirsfails on one of the tests belowAfter: the same commit passes on the first attempt
Flake evidence (run date 2026-10-06)
src/components/add_model/JevClassifierConfig.integration.test.tsx > JEV classifier editor > preserves bespoke, custom tiers and context through save, reload and probe(2 flakes)Failed on attempt 1 and passed on attempt 2 at the same SHA, both on main:
https://github.com/BerriAI/litellm/actions/runs/37388637599 (c561372) and https://github.com/BerriAI/litellm/actions/runs/37405618290 (4a963a6)
Mechanism: async interaction race. The test does
await userEvent.click(trigger)and then calls the synchronousscreen.getByRole("option", ...). The Base UI select popup opens and joins the accessibility tree asynchronously, so on a loaded runner the query runs while the trigger still hasaria-expanded="false". Locally the file failed 1 run in 10 at the merge base, that time on thelayacase with optionmultilingual, so every non-Jev case of theit.eachis exposedFix: use
chooseSelectOptionfromtests/test-utils.tsx, which the dashboard already uses for this race (a5f9410, eb53639). It awaits the click, finds the option withfindByRole, waits for the positioner to stop blocking pointer events, and then clickstests/unit/router_utils/pre_call_checks/test_prompt_caching_deployment_check.py::test_affinity_key_matches_the_messages_auto_caching_actually_sends(1 flake)Failed on attempt 2 and passed on attempt 3 at the same SHA: https://github.com/BerriAI/litellm/actions/runs/37369495882 (da14262, job 111985880102)
CI failure: the capture returned
[{'role': 'user', 'content': 'Hello!'}], which is not a message this test sends, and the test log showsLoggingWorker: event loop changed; carried 4 pending ... onto the new loopMechanism: shared module-level state between tests.
GLOBAL_LOGGING_WORKERmoves the success-logging tasks an earlier test left queued onto the next test's event loop. They run after this test has installed_SentMessagesCaptureinlitellm.callbacks, so the capture records another test's request, and_eventuallyreturns whichever event lands first. Repro: a scratch test that leaves oneacompletionlogging task queued, followed by a capture-installing test, makes the capture receive both the foreignHello!event and its own event on every runFix:
_SentMessagesCapture(litellm_call_id)only records success events whoselitellm_call_idmatches. Both tests that use it now pass a freshuuid4aslitellm_call_idtolitellm.acompletion.test_pin_matches_when_the_success_event_truncated_an_image_payloadhas the same exposure and gets the same changetests/unit/test_router/test_router.py::test_router_embedding_path_rejects_past_max_parallel_requests_without_orphan_coroutines(1 flake)Failed on attempt 1 and passed on attempt 2 at the same SHA, on main: https://github.com/BerriAI/litellm/actions/runs/37438745150 (18c3118, job 112187131162)
CI failure:
coroutine 'BaseRoutingStrategy.periodic_sync_in_memory_spend_with_redis' was never awaited, together withTask was destroyed but it is pending! task: <Task pending name='Task-325' ...>. This test creates no budget limiter, and the low task number points to a task an earlier test in the worker had createdMechanism: GC state shared across tests. The test calls
gc.collect()inside itswarnings.catch_warnings(record=True)window. A full collection also reaps unreachable old-generation garbage left by earlier tests, so their never-awaited coroutines get attributed to this test. Repro: a scratch test that leaves an unawaited coroutine in old-generation cyclic garbage, run just before this test, makes it fail on every run withcoroutine '_orphan' was never awaitedFix: call
gc.collect()once before the recording window opens. The collection inside the window and the assertion stay as they were, so coroutines this test orphans are still caughtMutation checks
Every fixed test still fails when the behavior it covers is broken. Each mutation was reverted afterwards
Unable to find role="option" and name "bespokelabs/Bespoke-Nimble-9B-wrong"messages_with_default_injectionsreturn the messages unchanged fails atassert routing_key is not Nonedep-2assert len(rejected) == 2(0 == 2)Flakes seen but not fixed in this PR
tests/unit/test_secret_redaction.py::test_redact_string_stays_sub_quadratic_on_a_long_adversarial_url, attempt 1 of https://github.com/BerriAI/litellm/actions/runs/37378002491:cost grew 18.8x for 4x the URL lengthagainst a ceiling of 11. This is a wall-clock ratio, and locally it already sits near 7x, so the ceiling has little headroom. It needs an operation-count measure rather than a tweak, so it is left for a humantests/unit/proxy/batches_endpoints/test_litellm_executed_batches.py::test_batch_expires_at_the_completion_window_and_keeps_what_finished, attempt 1 of https://github.com/BerriAI/litellm/actions/runs/37414003000:completed=0instead of 1. The 0.2scompletion_window_secondsdeadline is real wall-clock time, so on a loaded runner the first row can be cut off. The right fix is to inject a clock intoLiteLLMExecutedBatchRunner, a production change left for a follow-upNot flakes in the window
Real breakage:
documentationfails on main and on this PR becauseDEFER_PYDANTIC_BUILDinlitellm/constants.pyhas no docs entry (https://github.com/BerriAI/litellm/actions/runs/37448756259). It is not a required check and is left for a separate fix. Several PR-branch failures (component allowlist, seed tracing fixtures) failed on every attempt in files those PRs changed. Infra: 12 runner shutdowns and 4 job timeouts. None of these were touchedOther open deflake PRs
#43437, #42936 and #41219 each carry a human approval, so they are left untouched under the human-reviewed exception, and this PR is the new rolling PR
Pre-Submission checklist
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
There is no proxy or Admin UI surface for these changes, so the proof is the flake reproduction itself, run with the same triggers at the merge base and at the tip. The ordered repros use an uncommitted scratch test that leaves behind exactly the leftovers seen in CI
Before (18c3118)
JEV select race
npx vitest run --project integration src/components/add_model/JevClassifierConfig.integration.test.tsx10 times inui/litellm-dashboardUnable to find an accessible element with the role "option" and name "multilingual", with the trigger ataria-expanded="false"Leaked logging task
acompletionlogging task queued, then a capture-installing test[{'content': 'Hello!', ...}]from the earlier test before its own eventLeaked garbage
coroutine '_orphan' was never awaitedAfter (d97bba1)
JEV select race
Leaked logging task
Leaked garbage
Type
✅ Test
Caveats (if any)
Low
Final Attestation
Link to Devin session: https://app.devin.ai/sessions/a981af76fc76402dab98ee4ae041776d
Open in Devin Desktop: https://app.devin.ai/desktop/session/a981af76fc76402dab98ee4ae041776d?variant=devin
Note
Low Risk
Test-only changes with no impact on runtime behavior, auth, or data handling.
Overview
Stabilizes three CI flakes by isolating each test from async races and leftover state from other tests in the same worker. No production code or assertion changes.
The JEV classifier integration test now picks classifier models via
chooseSelectOption, which waits for the select popup before clicking an option, instead of queryingrole="option"immediately after opening the trigger.Prompt-caching tests give
_SentMessagesCapturealitellm_call_idand only record success events for that id; both capture tests pass a fresh UUID throughlitellm.acompletionso leaked logging tasks from earlier tests cannot populate the capture first.The max-parallel embedding router test runs
gc.collect()once before the warnings capture window so garbage from prior tests is not attributed as orphan coroutines during this test’s assertion.Reviewed by Cursor Bugbot for commit d97bba1. Bugbot is set up for automated code reviews on this repo. Configure here.