Skip to content

test(e2e): warm the memory test up with two batches before the measured one - #47087

Merged
yuneng-berri merged 4 commits into
mainfrom
litellm_test_1bdbd2
Oct 17, 2026
Merged

yuneng-berri merged 4 commits into
mainfrom
litellm_test_1bdbd2

Conversation

@yuneng-berri

Copy link
Copy Markdown
Contributor

TLDR

Problem this solves:

  • The e2e memory test fails about 1 in 10 Buildkite runs
  • Its measured batch is often still warming up, with no leak
  • Passing runs log nothing, so the margin is invisible

How it solves it:

  • Two identical warmup batches, then batch 3 is measured
  • Same 48 MB budget, same settle and sampling logic
  • Every batch's settled growth per worker becomes an rss_batch_growth JUnit property

User Flow

Before: a release engineer cutting an rc sees the memory gate go red on a healthy build and has to rerun it

  1. They run the Buildkite litellm-e2e pipeline on the rc tip
  2. test_failing_requests_do_not_grow_rss_or_stored_request fails with "proxy RSS grew 64.9 MB over a second batch of 300 failing requests ... past the 48 MB budget"
  3. They rerun the build and it passes, with no way to tell a leak from noise

After: the same build passes on a healthy proxy and still goes red on a real leak

  1. They run the same pipeline on the rc tip
  2. The test passes, and the JUnit XML shows each batch's growth, e.g. batch 2 +47.4 MB and batch 3 +13.7 MB
  3. A build that really leaks still fails with "proxy RSS grew 62.2 MB over measured batch 3 of 300 failing requests ... after 2 identical warmup batches, past the 48 MB budget"

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

Every run used the published ghcr.io/berriai/litellm-database:v1.107.0-dev.3 image on a fresh stack of its own Postgres 16 and Redis 7, with one worker in a 2 GiB container. The proxy config copies the Buildkite e2e proxy config (spend logs storing prompts, json logs, audit logs, redis cache, prometheus, otel, arize_phoenix and s3_v2 pointed at a local sink). The failing deployments point at http://127.0.0.1:9/v1 exactly as the test registers them, so no request reaches a provider and the runs cost nothing. The proxy log stays local

docker run -d --name memdive-proxy --network memdive-net --memory 2g --cpus 2 -p 127.0.0.1:$PORT:4000 \
  --env-file proxy.env -v $PWD:/cfg:ro --tmpfs /tmp/litellm_prometheus_multiproc \
  ghcr.io/berriai/litellm-database:v1.107.0-dev.3 --config /cfg/config.yaml --port 4000
env -i PATH=/usr/bin:/bin HOME=$HOME LITELLM_PROXY_URL=http://127.0.0.1:$PORT LITELLM_MASTER_KEY=$LITELLM_MASTER_KEY \
  uv run pytest "tests/e2e/router/test_reliability_memory_e2e.py::TestReliabilityMemory::test_failing_requests_do_not_grow_rss_or_stored_request" \
  -p no:cacheprovider --reruns 0 -v --junitxml=after.xml

Before (e754857)

Same traffic, ten batches on one cold proxy

  1. Sent ten consecutive batches of the test's exact traffic (300 failing requests at concurrency 4, 81-message transcript, 2 retries plus a fallback) and read settled RSS the way the test does, as the lowest of 16 one-second /debug/memory/summary samples
  2. Growth per batch in MB was +88.2, +52.5, +6.8, +7.6, +21.8, -0.6, +2.3, -4.7, +13.3, -4.0. Batch 2 is the batch this test measures today, and it is past the 48 MB budget with nothing leaking
  3. With tracemalloc started after boot, the live Python heap after gc read 39.0, 40.1 and 40.0 MB after batches 0, 1 and 2, so the RSS step is allocator high-water, not live objects

Main's test on a fresh proxy

  1. Ran main's version of the test on a fresh stack
  2. 1 passed in 172.62s, with no growth on record, so this one run did not land over the line and leaves nothing to compare

After (134d9f0, test file identical at the tip 22d6943, which only merges main)

Three fresh proxies, healthy

  1. Ran the test once per fresh stack and read rss_batch_growth out of the JUnit XML

    after_1.xml b1:+69.2 b2:+40.4 b3:+20.5   1 passed in 284.41s   (at 2a4e45f716)
    after_2.xml b1:+91.4 b2:+44.2 b3:+11.5   1 passed in 255.56s
    after_3.xml b1:+68.2 b2:+47.4 b3:+13.7   1 passed in 241.79s
    
  2. Batch 2, the old measured batch, came within 0.6 to 7.6 MB of the 48 MB budget on every run. Batch 3, the new measured batch, stayed between 11.5 and 20.5 MB

Fresh proxy with a real per-request leak

  1. Added a local-only callback to the proxy config that keeps 200 KB of random bytes on every failure event, then ran the same test on a fresh stack
  2. leak.xml b1:+147.3 b2:+103.6 b3:+62.2
  3. The test failed with AssertionError: proxy RSS grew 62.2 MB over measured batch 3 of 300 failing requests (2 retries each plus a fallback) after 2 identical warmup batches, past the 48 MB budget: worker pid 1 ... settled at 933.0 MB warm and 995.2 MB after
  4. Removed the callback afterwards. It never touched the repo

Type

✅ Test

Caveats (if any)

Medium

  • The RSS budget is per worker, unchanged by this PR
    • On two workers, a leak needs about 330 KB per request to fail
    • The stored-request size check still guards smaller leaks
  • The run takes about 1.5 minutes longer, from one more batch and one more settle window

Low

  • A leak that saturates within the first 600 requests now passes, which is the intent
  • rss_batch_growth lands in the JUnit XML only. The Buildkite results JSON drops property names it does not know
  • The worker-set failure message still sorts worker keys, which raises on mixed named and unnamed hosts. Main has the same bug, and this PR leaves it alone
  • The local proof ran on arm64 Docker, while CI nodes are x86_64
  • The proof image is v1.107.0-dev.3, not the rc tip

QA runbook

  • tests/e2e/router/test_reliability_memory_e2e.py::TestReliabilityMemory::test_failing_requests_do_not_grow_rss_or_stored_request - 900 failing requests with retries and a fallback must not grow a warm proxy's RSS past 48 MB over the third batch of 300, and one failing request's stored spend-log body must stay under 64 KB
    • Boot a proxy with a database, store_prompts_in_spend_logs: true and STORE_MODEL_IN_DB=True. No provider key is needed because every call fails at the socket
    • POST /model/new twice for a group and twice for its fallback group, each openai/gpt-5.5 with api_base: http://127.0.0.1:9/v1 and cooldown_time: 0
    • Send one /chat/completions to the group with an 80-message transcript and router_settings_override: {"num_retries": 2, "fallbacks": [{"<group>": ["<fallback>"]}]}. Expect a 500 naming the fallback group, and a /spend/logs row whose proxy_server_request is under 64 KB
    • Read GET /debug/memory/summary with the master key until ram_usage_mb settles, then send three batches of 300 of the same request at concurrency 4, settling after each
    • Expect batch 3's settled growth at or under 48 MB, and three rss_batch_growth properties per worker in the JUnit XML
    • Add a callback that keeps 200 KB per failure event and rerun. Expect the test to fail naming measured batch 3 and the 48 MB budget
    • Sanity check: this test makes sense to add and is not hand-wavey (e.g., assert actual expected spend instead of just spend > 0) or potentially flaky

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

…ed one

On a cold worker the second batch of failing requests can still raise the
allocator's high-water mark by about 50 MB while the live Python heap stays
flat, so the 48 MB budget failed about 1 in 10 Buildkite runs without a leak.
The test now runs two warmup batches, measures the third against the same
budget, and records every batch's settled growth per worker as an
rss_batch_growth JUnit property for later calibration
A failure in a later batch no longer drops the growth already measured, and
the worker keys are no longer sorted, which raised on a mix of named and
unnamed hosts
@yuneng-berri

Copy link
Copy Markdown
Contributor Author

@litellm-stampbot

@yuneng-berri
yuneng-berri enabled auto-merge (squash) October 17, 2026 06:59
@litellm-stampbot

litellm-stampbot Bot commented Oct 17, 2026 •

Copy link
Copy Markdown

litellm-stampbot: risk low

Approved at 22d6943.

Rules (stampbot/risk_rules.yml):

  • low: no rule flagged it

Judge (gpt-6-luna): low, probability of high 0.00 (high at or above 0.75)

  • risk: low (probability of high 0.00)

Pushes do not re-run this check. Comment @litellm-stampbot again to re-check the new head.

@litellm-stampbot litellm-stampbot Bot added the risk:low Small, isolated, low-risk change label Oct 17, 2026

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

Low risk by rule and by judgement at 22d6943

@yuneng-berri
yuneng-berri merged commit 1fd7f81 into main Oct 17, 2026
87 of 88 checks passed
@yuneng-berri
yuneng-berri deleted the litellm_test_1bdbd2 branch October 17, 2026 07:09
@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!

yuneng-berri added a commit that referenced this pull request Oct 17, 2026
…in (#47090)

* fix(bedrock)!: block realtime replay after an input-first start and reject malformed Nova Sonic session settings (#46936)

* fix(bedrock): block realtime replay after input starts the session and reject non-string instructions and voice

* test(bedrock): name the malformed realtime setting test for its string cases

* fix(bedrock): replay the opening realtime message until Bedrock accepts the stream and refuse any fallback after commit

Also rejects a malformed modalities, input_sample_rate_hertz or tools setting with invalid_type, dropped under drop_params.

* fix(bedrock): replay a refused opening message on any fallback and reject OpenAI voices and non-string audio formats

* fix(realtime): read the client scope only when the websocket has one and reject any-case OpenAI and empty Bedrock voices

* test(bedrock): cover realtime replay, refusal and committed failure through a real proxy

Fix the scripted Bedrock peer's port import and the nested tool call cell's stale expected events, so the Nova Sonic integration file collects again

(cherry picked from commit 3ef0b35)

* test(integration): write worker configs beside test-supplied configs (#47066)

Under worker isolation the harness rewrote every proxy config into the owned proxy's directory, so modules a test placed next to its own config (custom_auth) no longer resolved and the proxy died at boot. The copy now lands next to a test-supplied config, while configs inside the checkout still go to the worker directory so nothing is written into the repo tree

(cherry picked from commit e754857)

* test(e2e): keep the prompt-caching affinity test on the live provider (#47072)

With E2E_PROVIDER_CACHE=1 the test's Anthropic deployment went through the
shared response cache. Each call's recording expires on its own, so a run
could replay the cache-writing call while a follow-up went live against a
cold provider cache, recording creation instead of a read. That recording
then replayed as a failure for 24 hours. Mark the test provider_live, as
PROVIDER_CACHE.md requires for prompt-caching tests

(cherry picked from commit 6b45a19)

* test(integration): send post-kill requests on a fresh connection in two worker-kill tests (#47080)

kill() returns once the killed worker's main thread is a zombie, but its other threads can
still be exiting and holding its sockets open. A keep-alive connection pooled to that worker
still looks healthy, so the next request goes out on it and the closing socket answers with
a reset. The old reap wait used to hide this. A new connection can only be accepted by a
live worker, so the surviving-worker assertions now run on a fresh client

(cherry picked from commit c32eea6)

* fix(caching): keep prompt cache usage on streamed cache hits (#47073)

* fix(caching): keep prompt cache usage on streamed cache hits

A stream=true request served from the response cache rebuilt its usage from
the prompt, completion and total counts only, so prompt_tokens_details and the
cache read and creation counts were dropped on the replayed stream. /v1/messages
clients routed to Bedrock Converse saw input_tokens equal to the whole prompt
and no cache tokens on a hit.

Both replays now build the usage through one helper that also restores
prompt_tokens_details and the integer cache read and creation counts, skipping
cached values that do not validate.

* fix(caching): coerce replayed token counts the way the live usage does

The replay accepted only exact ints for the token counts, so an integral float
or numeric string in a cached entry became 0 where the previous replay kept it.
Counts now go through pydantic int coercion and fall back only when they do not
validate.

(cherry picked from commit d346d76)

* fix(logging): keep the async request's logging payload when the sync success thread runs late (#47019)

* fix(logging): keep the async request's logging payload when sync callbacks run late

Treat the "cache" success callback as internal when deciding whether to start
the sync success thread for async requests. It has no branch in the sync
handler, so with `cache: true` that thread did nothing except rebuild and
overwrite model_call_details["standard_logging_object"].

When the sync handler does run for an async request (a real sync-only logger
is configured), it now builds its own payload and hands it only to its own
callbacks. The async handler keeps sole ownership of the shared payload, so
edits made by async logging hooks (for example the v3 rate limiter's mirrored
x-ratelimit headers that Prometheus reads) are no longer discarded. Sync
requests keep their existing behavior.

* fix(logging): keep sync cache hits logged and isolate the async-request payload build

The sync completion cache-hit path reused handle_sync_success_callbacks_for_async_calls,
so treating "cache" as internal silently dropped sync callbacks on sync cache hits. It now
submits the sync handler through its own method, as it effectively always did.

For async requests the sync handler builds its payload from a copy of the call details, so
message redaction cannot rewrite the shared standard_logging_object, and when it builds no
payload its callbacks keep the shared one instead of getting None.

* test(caching): lock sync cache-hit logging for completion, embedding and text_completion

* test(logging): keep sync hook edits off a caller-supplied payload for async requests

* fix(logging): give sync hooks a copy of the async payload when the thread builds none

* test(logging): check every legacy sync logger gets the thread's own payload

* test(logging): cover traceloop and supabase sync logging for async requests

(cherry picked from commit a4e0570)

* fix(cost): price exact cost-map names before price-free capability rules, and fix SCIM and MCP integration tests on CircleCI (#47037)

* fix(test-harness): preserve sibling auth modules in isolated worker configs

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

* test(integration): expect servers in MCP connect-flow descriptions

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

* test(integration): expect ptu_hours in daily activity metrics after #43043

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

* test(integration): kill every serving worker once the SCIM push blocks on the row lock

* fix(cost): price exact cost-map names before price-free capability rule matches

* test(streaming): price a priced alias stream at its deployment model and keep the unpriceable case unmapped

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

* fix(cost): price an explicit base_model under its own provider after candidate reordering

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

* fix(cost): retain priced generalized candidates and skip explicit-pricing lookups

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

* test(cost): assert custom pricing makes no remote model-info requests

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

* refactor(cost): keep the per-candidate pricing provider final

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

* fix(router): pin a Bedrock application profile prompt for the one-hour ttl its base model sends

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

* test(integration): assert the Nova Sonic tool-call argument delta carries the full arguments

* fix(cost): sort cost candidates from the static cost map and rules, without provider lookups

* test(integration): bill route-priced Bedrock chat streams and responses, and pin application profiles for an hour on messages and cache hits

---------

Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Co-authored-by: Yuneng Jiang <yuneng@berri.ai>
(cherry picked from commit 4a58784)

* test(e2e): warm the memory test up with two batches before the measured one (#47087)

* test(e2e): warm the memory test up with two batches before the measured one

On a cold worker the second batch of failing requests can still raise the
allocator's high-water mark by about 50 MB while the live Python heap stays
flat, so the 48 MB budget failed about 1 in 10 Buildkite runs without a leak.
The test now runs two warmup batches, measures the third against the same
budget, and records every batch's settled growth per worker as an
rss_batch_growth JUnit property for later calibration

* test(e2e): record each memory batch's growth as soon as it settles

A failure in a later batch no longer drops the growth already measured, and
the worker keys are no longer sorted, which raised on a mix of named and
unnamed hosts

* test(e2e): silence the xunit2 record_property warning on the memory test

(cherry picked from commit 1fd7f81)

* test: import pytest and Final for the backported #47073 test on rc

On main these imports came from an earlier commit that is not on rc/1.107.0, so the
picked test failed collection with NameError

---------

Co-authored-by: Mateo Wang <277851410+mateo-berri@users.noreply.github.com>
Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

risk:low Small, isolated, low-risk change

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants