Skip to content

test: de-flake langfuse callbacks-in-db e2e test - #32167

Merged
yuneng-berri merged 2 commits into
litellm_internal_stagingfrom
litellm_/suspicious-jennings-5b6ef7
Jul 5, 2026
Merged

yuneng-berri merged 2 commits into
litellm_internal_stagingfrom
litellm_/suspicious-jennings-5b6ef7

Conversation

@yuneng-berri

Copy link
Copy Markdown
Contributor

Relevant issues

Linear ticket

Pre-Submission checklist

Please complete all items before asking a LiteLLM maintainer to review your PR

  • I have added meaningful tests
  • My PR passes all CI/CD checks (e.g., lint, format, unit tests)
  • My PR's scope is as isolated as possible; it only solves 1 specific problem
  • I have requested a Greptile review by commenting @greptileai and received a Confidence Score of at least 4/5 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

The failure this addresses is proxy_store_model_in_db_tests dying on test_e2e_langfuse_callbacks_in_db with openai.APIConnectionError: Connection error while opening a connection to the proxy, one recent example being this run. The captured stdout shows /config/update returning 200, then twenty seconds later the single chat request cannot open a TCP connection, so the whole job stops there under pytest -x

This is a CI-timing fix rather than a request/response behavior change, so the proof is the job itself. Before, a momentary window where the single-process proxy is not accepting connections fails the one blind request outright. After, the request waits on /health/liveliness and retries transient connection errors, and the container can restart if it crashed, so that window no longer sinks the run. The most direct validation is re-running proxy_store_model_in_db_tests and watching it stay green

Type

🐛 Bug Fix

✅ Test

Changes

tests/store_model_in_db_tests/test_callbacks_in_db.py gets four reliability changes. The chat request is now gated behind a /health/liveliness poll so it never fires while the worker is mid-cycle, and it retries on openai.APIConnectionError only, which means a real HTTP error or a failed Langfuse assertion still fails the test rather than being masked. The previously leaked aiohttp.ClientSession is wrapped in async with, clearing the Unclosed client session warning. Requests target 127.0.0.1:4000 instead of the 0.0.0.0 bind address

.circleci/config.yml gives the my-app proxy container --restart on-failure. The proxy runs as a single process with no supervisor, so an intermittent crash previously left port 4000 dead for the rest of the job; with the restart policy the container comes back and the readiness poll rides out the gap

The Langfuse assertion path is unchanged, so the test still verifies that the callback actually logs the request

The test posted /config/update, slept a fixed 20s, then fired a single chat request with no readiness check or retry. When the single-process proxy was momentarily not accepting connections in that window, the request failed with a bare openai.APIConnectionError and took the whole job down, since the suite runs against one shared container with pytest -x

Gate the chat request behind a /health/liveliness poll, retry it on connection errors only so real HTTP errors and the Langfuse assertion still fail the test, close the previously leaked aiohttp session, and target 127.0.0.1 instead of the 0.0.0.0 bind address. In CI, give the proxy container --restart on-failure so an intermittent crash recovers instead of leaving the port dead for the rest of the run
@yuneng-berri
yuneng-berri requested a review from a team July 5, 2026 02:16
@greptile-apps

greptile-apps Bot commented Jul 5, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR de-flakes the test_e2e_langfuse_callbacks_in_db CI test by addressing a timing window where the single-process proxy container was not accepting connections when the test fired its one chat request.

  • Test hardening: adds a /health/liveliness readiness poll before the chat request, retries APIConnectionError up to 10 times (2 s apart), fixes a leaked aiohttp.ClientSession by switching to async with, changes the bind address from 0.0.0.0 to 127.0.0.1, and extends the Langfuse flush wait from 11 s to 20 s. The core Langfuse assertion (check_langfuse_request) is unchanged.
  • CI hardening: adds --restart on-failure to the proxy Docker container in .circleci/config.yml, so a transient container crash no longer leaves port 4000 permanently dead for the rest of the job.

Confidence Score: 5/5

Safe to merge — changes are scoped entirely to a CI test file and the CircleCI config; no production code is touched.

Both changes target the flaky test window: the Docker restart policy prevents a dead port from blocking the job, and the readiness poll plus connection-error retry loop in the test ensure the request is only sent when the proxy is up and can survive a momentary blip. The core Langfuse assertion is preserved verbatim, so the test still validates the actual callback behaviour. The aiohttp.ClientSession leak fix and address change from 0.0.0.0 to 127.0.0.1 are straightforward correctness improvements with no side effects.

No files require special attention; both changed files are self-contained and the modifications are well-scoped.

Important Files Changed

Filename Overview
tests/store_model_in_db_tests/test_callbacks_in_db.py Reliability improvements: adds proxy readiness polling, connection-error-only retry logic, fixes leaked aiohttp session, changes bind address from 0.0.0.0 to 127.0.0.1, and extends Langfuse flush sleep; core assertions are unchanged
.circleci/config.yml Adds --restart on-failure to the proxy Docker container so an intermittent crash no longer leaves port 4000 permanently dead for the rest of the job

Reviews (1): Last reviewed commit: "Merge remote-tracking branch 'origin/lit..." | Re-trigger Greptile

@codecov

codecov Bot commented Jul 5, 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 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; thanks!

@yuneng-berri
yuneng-berri enabled auto-merge July 5, 2026 02:50
@yuneng-berri
yuneng-berri merged commit 2e076b1 into litellm_internal_staging Jul 5, 2026
74 checks passed
@yuneng-berri
yuneng-berri deleted the litellm_/suspicious-jennings-5b6ef7 branch July 5, 2026 02:54
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