Skip to content

test: fix two flaky callback probe and spend-cleanup tests - #46898

Open
devin-ai-integration[bot] wants to merge 3 commits into
mainfrom
litellm_deflake_20261016
Open

devin-ai-integration[bot] wants to merge 3 commits into
mainfrom
litellm_deflake_20261016

Conversation

@devin-ai-integration

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

Copy link
Copy Markdown
Contributor

TLDR

Problem this solves:

  • Two tests flipped pass and fail at the same SHA in CI
  • One integration test probe caught other tests' late callbacks
  • One unit test compared a cutoff against a clock read after the call

How it solves it:

  • Callback probe records only the call ids the test owns
  • Cutoff is bounded by clocks read right before and after the call

CI evidence

Run of 2026-10-16

tests/integration/sdk/test_anthropic_messages_bridge_mid_stream_failure_sdk.py::test_sdk_native_messages_stream_delivers_one_success_callback_with_usage failed 8 times and passed 14 in the window, flipping at e0fe9626 (CircleCI job 2261242 failed, rerun job 2261294 passed) and failing again at ecbea933 in job 2261441. The mechanism is shared module-level state. _CallbackProbe sits in the global litellm.callbacks and recorded every success event in the process, so late success callbacks from earlier sdk-shard tests (a databricks completion and two other chat calls in job 2261242) landed in it and len(successes) == 1 saw 3. Running the whole sdk group locally at origin/main reproduced it 3 out of 3. The probe now takes the litellm_call_ids it owns and ignores the rest. The bridge test in the same file now uses one probe for both of its calls, since LoggingCallbackManager dedupes custom loggers by a key that ignores private fields, so a second probe instance is never registered

tests/unit/proxy/test_spend_log_cleanup.py::test_cleanup_old_spend_logs_retention_period_cutoff failed on attempt 1 and passed on attempt 2 of run 38843643564 and run 38839048391, with assert 1.29 < 1. The mechanism is wall-clock dependence. The expected cutoff came from a datetime.now() read after cleanup finished, with a 1 second tolerance, so a slow runner broke it. The test now reads the clock right before and right after cleanup_old_spend_logs and asserts the cutoff sits between those two reads minus 24 hours

Each regression test was checked against a mutation of the behavior it covers (a duplicated success callback, a duplicated failure callback, retention parsed as 86000 seconds) and failed every time, then the mutation was reverted

Dropped

The worker-kill fix for test_worker_killed_mid_stream_leaves_the_sibling_billing_each_stream_once was dropped after merging main, since #46855 already landed a fix for it

Open deflake PRs left alone

#41219, #42936 and #43437 each have a human approval, so this run left them untouched and opened this PR instead

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

Type

✅ Test

Caveats (if any)

Low

  • Test-only change, no production code touched

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

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

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

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

devin-ai-integration Bot commented Oct 16, 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

@greptile-apps

greptile-apps Bot commented Oct 16, 2026

Copy link
Copy Markdown
Contributor

Automatic reviews are disabled for this repository.

@devin-ai-integration

Copy link
Copy Markdown
Contributor Author

@litereview code-review

@codecov

codecov Bot commented Oct 16, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@mateo-berri

Copy link
Copy Markdown
Contributor

#46855 merged a fix for test_worker_killed_mid_stream_leaves_the_sibling_billing_each_stream_once, so please drop that hunk and keep the other two fixes

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

# Conflicts:
#	tests/integration/streaming/test_google_genai_stream_usage_settings_wire.py
@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: fix three flaky callback, worker-kill and spend-cleanup tests test: fix two flaky callback probe and spend-cleanup tests Oct 17, 2026
@devin-ai-integration

Copy link
Copy Markdown
Contributor Author

Dropped the worker-kill hunk after merging main, since #46855 covers it. The callback probe and spend cleanup fixes are unchanged

This branch has not been deployed

No deployments
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