Repository navigation
fix(s3_v2): bound concurrent S3 uploads per flush and add opt-in JSONL batch files - #41258
Conversation
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
|
|
|
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
ab47e11 to
e8b0f97
Compare
There was a problem hiding this comment.
Devin Review found 3 potential issues.
2 flags not posted on this PR by your GitHub settings — view them in Devin Review. (Configure)
1 similar comment
|
Admin UI evidence at 38c941c: proxy booted from this branch with |
…L batch files Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
…ntegration coverage Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
…onfig value is null Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
…ety in batch file mode Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
…s with sink faults Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
…local counters Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
d8f318b to
4b48743
Compare
|
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 4b48743. Configure here.
TLDR
Problem this solves:
s3_v2fires one unbounded PUT task per queued log on every flush503 SlowDownon 11 to 18 percent of them (real bucket run below)How it solves it:
async_send_batchawaits uploads through anasyncio.Semaphoresizeds3_max_concurrent_uploads(default 16)s3_batch_file_upload: truewrites each flush as one NDJSON.jsonlobject per key prefix (team and API key prefixes kept)s3_v2is also the cold storage logger, since spend log lookups need per request objects"false","0","abc", negatives and empty strings ins3_callback_paramsresolve safely instead of enabling batching or hanging the flushUser Flow
Before: a proxy admin logging to S3 with
s3_v2sees bursts of 503s in the proxy log and missing objects in the bucketlitellm_settings.callbacks: ["s3_v2"]with their bucket ins3_callback_paramsand fire 64 concurrent requests at POST https://litellm-domain/v1/chat/completions, all return 200S3 upload returned 503, retrying in 1s (attempt 1/3)andattempt 2/3, and any entry throttled a third time ends inError uploading to s3: ... 503 Slow Downs3://bucket/path/2026-09-23/shows fewer objects than requests served (79,993 of 80,000 in the real bucket run); the missing ones are gone for goodAfter: the same setup uploads at a bounded rate and every request ends up in the bucket
s3_max_concurrent_uploads)async_send_batch raised; preserving 32 events in queue for retryand the same objects are uploaded on the next flush once S3 recoverss3://bucket/path/2026-09-23/shows exactly one object per requests3_batch_file_upload: true; the same listing now shows onebatch_<HH-MM-SS>_<id>.jsonlfile per flush with one request payload per line, and withs3_use_team_prefix: truethe file sits underpath/<team_alias>/2026-09-23/like the per request objects didRelevant issues
Affected release
Linear ticket
Resolves LIT-7800
Pre-Submission checklist
Please complete all items before asking a LiteLLM maintainer to review your PR
uv run pytest tests/test_litellm/<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)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
Setup for every run: a real proxy started from the tree under test (
litellm --config config.yaml, import path checked withpython -c "import litellm; print(litellm.__file__)"), modelopenai/gpt-5-miniwith a real OpenAI key,callbacks: ["s3_v2"],DEFAULT_S3_FLUSH_INTERVAL_SECONDS=5. The burst is 64 concurrent curls:Concurrency is measured with
s3_endpoint_urlpointed at a local HTTP server that accepts the signed PUTs, holds each one for 0.5s and prints the peak number of in flight PUTs. Object creation is verified against the real bucketlitellm-e2e-suite-logswithaws s3 ls --recursive.Before (e26a645)
Upload fan out, 64 requests
HTTP 200 count: 64sink: peak=25 total=64queued=512 delivered=512 peak=81S3 throttling for 25s (endpoint answers
503 SlowDownfor the first 25s, then 200)HTTP 200 count: 32Error uploading to s3: ... 503(3 retries per entry, all inside the window), then nothingtotal=0accepted PUTs, all 32 logs lostAfter (4b48743; all six live legs re-ran at this head, verdict PASS 6/6, F1 sink peak 9 within the bound of 16)
Upload fan out, 64 requests, default settings
HTTP 200 count: 64sink: peak=16 total=64, keysfinal/f1-default/<date>/time-*.jsonqueued=512 delivered=512 peak=16Real bucket, default settings
HTTP 200 count: 64aws s3 ls --recursive s3://litellm-e2e-suite-logs/lit7800-qa/final-4b48743/ | wc -l->64Error uploading to s3linesS3 throttling for 25s, batch mode, same fault shape as Before
HTTP 200 count: 8across two flushesS3BatchUploadError: 1 of 1 S3 uploads failedthen2 of 2, withpreserving 4 events in queue for retrytwices3_batch_file_upload: truewiths3_use_team_prefix: true, base vs headfinal/f2/alpha/<date>/time-*.jsonfinal/f2/alpha/<date>/batch_09-01-33_d669164e....jsonl lines=5andbatch_09-01-38_9c5a5b09....jsonl lines=3, samealphaparent as basefinal/f2/<date>/batch_09-02-*_a2d0bb3c....jsonl lines=4at the path rootcold_storage_custom_logger: s3_v2with the batch flag onfinal/f4/<date>/time-09-04-45-465090_chatcmpl-ERDC9P9CZukmzxqck7ZYaQPHIj7vg.jsons3 logging: s3_batch_file_upload is ignored because s3_v2 is the cold storage logger; per-request objects are required for spend log lookupsGET /spend/logs/ui/chatcmpl-ERDC9P9CZukmzxqck7ZYaQPHIj7vgreturns populatedmessagesandresponsehttp://127.0.0.1:24810/ui/?page=logslists the 8 requests and the Request ID drawer shows request and response payloads (screenshots in the PR comment thread)Real AWS
503 SlowDown, base vs head, no fault injectionEight processes, each an
S3Loggerfrom the tree under test with 10,000 smalls3BatchLoggingElements appended tolog_queueand oneflush_queue()call, all started in the same second against fresh prefixes underlit7800-qa/flood503/<run>/p1..p8in the real bucket (the shape of eight uvicorn workers ticking at once). httpx event hooks count status codes and in flight PUTs; objects are counted afterwards withaws s3 ls --recursive. One unfixed process alone never got throttled (512, 2,000 and 5,000 entries at 480 to 1,104 PUT/s, peak 291 to 316 in flight, all 200). Eight at once didqueued=10000 codes={200: 10000, 503: 1429..1783} peak_inflight=321..393 wall=21s put_rate=~575/s, about 4,500 PUT/s aggregate into one not yet partitioned prefix. AWS body:<Code>SlowDown</Code><Message>Please reduce your request rate.</Message>11087 x "returned 503, retrying in 1s (attempt 1/3)",1926 x "attempt 2/3", then7 x "Error uploading to s3"for entries that got 503 three times in a row. Bucket listing:79993of80000objects, the 7 keys never land and nothing requeues themqueued=10000 codes={200: 10000, 503: 4..13} peak_inflight=16 wall=60s put_rate=~168/sper process, 68 503s total across eight processes, every one recovered on the first retry,80000of80000objects,left_in_queue=0after a single flush round165 / 333 / 611 PUT/s, so the PUT round trip from the test box to us-east-1 is about 97ms and one worker at the default drains a full 512 queue in about 3sUntouched neighbours
callbacks: ["s3"](the legacy logger) on base and head: 8 PUTs each, identical header key set,Content-Type: application/jsons3_v2per request PUT headers on base and head: identical key set, Content-Type, Content-Disposition and Content-Languagestore_audit_logs: truewith batch mode: one.jsonlcarrying 2 audit lines and 1 request lineAudit matrix (tests/integration, base e26a645 vs head 4b48743, head runs 9 and 10 both 20 passed with identical 20 collected and 20 passed, zero skips)
Every cell boots a real proxy from the leg under test with real Postgres and Redis; the provider and the S3 endpoint are local wire servers
test_s3_v2_mixed_surface_burst_bounds_puts_one_object_per_response_idtest_s3_v2_mixed_surface_batch_writes_ndjson_lines_per_response_idtest_s3_v2_sink_outage_mid_mixed_burst_recovers_every_response_idtest_s3_v2_upstream_failure_events_land_alongside_successess3_max_concurrent_uploads"abc",0,""fall back to 16test_s3_v2_invalid_or_empty_bound_falls_back_to_sixteen[...]test_s3_v2_sink_rejection_requeues_and_delivers_every_id_oncetest_s3_v2_batch_retry_resends_identical_key_and_bodytest_s3_v2_unknown_model_rejection_keeps_other_requests_loggingtest_s3_v2_batch_flag_ignored_when_s3_v2_is_cold_storage_loggertest_s3_v2_identical_requests_land_distinct_objectstest_s3_v2_two_workers_bound_and_deliver_every_idtest_s3_v2_slow_sink_never_duplicates_or_stalls_readinesstest_s3_v2_worker_kill_mid_burst_keeps_surviving_deliveriestest_s3_v2_sigterm_mid_burst_loses_only_inflight_without_duplicatesThe original four cells (default bound, configured bound with env backed
false, batch mode, team prefix) are red on base and green on head in the same runs. The sink outage and unknown model cells are green on base as well: they are isolation invariants rather than fix discriminators, and 30 rejected attempts are absorbed by the per upload retries the base already has, while the 10s 403 window in the rejection cell outlasts them and shows the base dropping the eventsMutation checks on the unit tests, each killed by the mapped tests in
tests/test_litellm/integrations/test_s3_v2.py: dropping thebound < 1check, replacing the boolean resolver withbool(), dropping the failed event requeue, not raising on failed uploads, removing the semaphore, joining batch lines with commas, writing.jsoninstead of.jsonl, grouping every key under the root, requeueing raw elements instead of built batch files, removing the cold storage checkType
🐛 Bug Fix
🆕 New Feature
Caveats (if any)
Medium
cold_storage_custom_logger: s3_v2the batch flag is ignored and a warning is logged on every flush, so an admin who wants both gets per request objectsLow
Audit log entries keep their own
audit_logs/...prefix, so in batch mode they land in their own.jsonlfile next to the request log batchThe cold storage check runs at flush time rather than at startup because
general_settingsmay be applied after the callback is builtThe bound is per worker; with N uvicorn workers the process wide peak is N x
s3_max_concurrent_uploadsA flush now holds the flush lock for the duration of the uploads, so a very slow S3 endpoint delays the next periodic flush rather than piling up tasks
DEFAULT_S3_MAX_CONCURRENT_UPLOADSis parsed withint()at import like its neighbours, so a non numeric value fails at startupIn per request mode only the elements whose PUT failed are re-sent; in batch mode the built file is re-sent under its original key
QA runbook
tests/integration/observability/test_s3_v2_upload_fanout.py::test_s3_v2_flush_bounds_concurrent_puts_to_the_default_of_sixteen - 64 concurrent chat requests produce 64 per request objects with at most 16 PUTs in flight
callbacks: ["s3_v2"]ands3_endpoint_urlpointing at a local server that delays each PUT by 0.5s and counts in flight requests<path>/<date>/*.jsonand a peak in flight count of at most 16tests/integration/observability/test_s3_v2_upload_fanout.py::test_s3_v2_honors_configured_bound_and_env_backed_false_batch_flag -
s3_max_concurrent_uploads: 4ands3_batch_file_upload: "false"give a peak of 4 and per request objectss3_callback_params.jsonobjects and a peak in flight count of at most 4tests/integration/observability/test_s3_v2_upload_fanout.py::test_s3_v2_batch_file_upload_writes_one_jsonl_object_per_flush -
s3_batch_file_upload: truewrites NDJSON batch filess3_batch_file_upload: true<path>/<date>/batch_HH-MM-SS_<32 hex>.jsonl,Content-Type: application/x-ndjson, and 64 JSON lines in total whoseidfields match the 64 responsestests/integration/observability/test_s3_v2_upload_fanout.py::test_s3_v2_batch_file_upload_keeps_team_alias_prefix - batch files land under the team alias prefix
s3_batch_file_upload: trueands3_use_team_prefix: true, create a team with aliasalphaand a key on it.jsonlkey to match<path>/alpha/<date>/batch_HH-MM-SS_<32 hex>.jsonland the 64 lines to match the responsestests/integration/observability/test_s3_v2_flush_surfaces.py and the audit cells in test_s3_v2_upload_fanout.py - the matrix above: chat, messages and responses surfaces, invalid bounds, sink 403/500/503 faults, cold storage guard, two workers, worker kill and proxy SIGTERM
uv run --no-sync pytest tests/integration/observability/test_s3_v2_flush_surfaces.py tests/integration/observability/test_s3_v2_upload_fanout.pyagainst the rig twice, expect 20 passed both times with no skipsFinal Attestation
Link to Devin session: https://app.devin.ai/sessions/cf92245d91a5424faa91369ee0d975d6
Open in Devin Desktop: https://app.devin.ai/desktop/session/cf92245d91a5424faa91369ee0d975d6?variant=devin
Requested by: @yucheng-berri