Skip to content

fix(s3_v2): backport #43022 to rc/1.104.0 - #43354

Merged
yuneng-berri merged 1 commit into
rc/1.104.0from
litellm_backport_rc_1_104_0_43022
Sep 26, 2026
Merged

yuneng-berri merged 1 commit into
rc/1.104.0from
litellm_backport_rc_1_104_0_43022

Conversation

@yuneng-berri

@yuneng-berri yuneng-berri commented Sep 26, 2026 •

Copy link
Copy Markdown
Contributor

TLDR

Backport of #43022 to rc/1.104.0: git cherry-pick -x e47b1f2a3f (the merged main commit), applied cleanly and patch-identical to the source. No version bump, since 1.104.0 has not been released

Problem this solves:

How it solves it:

  • Fresh events upload first, ahead of retries
  • Terminal S3 failures are dropped, and retries older than an hour are dropped by default
  • Adaptive upload concurrency is available as an opt-in

This replaces the revert in #43327, which will be closed

What is included

Known noise on this line

tests/integration/observability/test_s3_v2_upload_fanout.py::test_s3_v2_upstream_failure_events_land_alongside_successes fails on the rc tip before the pick in my local integration stack (Owned HTTP peer failed: JSONDecodeError), and fails the same way after it

Screenshots / Proof of Fix

The s3_v2 integration tests boot real proxies against a recording S3 sink, a scripted upstream, Postgres and Redis, so they are the end-to-end proof here. Shared setup: dedicated Postgres 16 and Redis 7 containers, the integration._support.upstream server, and the same env as .circleci/scripts/run_integration.sh

Before (7248fd8)

  1. pytest tests/integration/observability/test_s3_v2_flush_surfaces.py tests/integration/observability/test_s3_v2_upload_fanout.py -n 4
  2. 1 failed, 19 passed: the known-noise test above

After (0a5d1b7)

  1. Same command

  2. 1 failed, 36 passed: the same known-noise test, plus the 17 new cases fix(s3_v2): upload fresh events first, drop terminal failures and hour-old retries by default, opt-in adaptive concurrency #43022 adds, all green

  3. pytest tests/unit/integrations/test_s3_v2.py tests/unit/integrations/test_adaptive_concurrency.py tests/unit/integrations/test_s3.py tests/documentation_tests/test_env_keys.py tests/test_litellm/proxy/management_helpers/test_audit_log_callbacks.py: 292 passed

  4. litellm/integrations/s3.py, s3_v2.py, adaptive_concurrency.py and types/integrations/s3_v2.py are byte-identical to main

  5. Wider regression delta over every test file that references the s3 loggers plus all of tests/unit/integrations (6,280 tests): no new failure. The one post-pick-only red, test_update_config_general_settings_is_visible_to_the_next_read, passes 2 of 2 times in isolation at head, and base had two different flaky reds of its own

  6. gauntlet-mini (5 adversarial lenses plus reproduce-or-reject): SURVIVED. The blackbox lens drove flush_queue() against a fake S3 and confirmed fresh-first ordering, the retry-age boundary (kept at exactly the budget, dropped just past it), terminal drops only next to a landed sibling, AccessDenied and 404 never dropped, and exactly-once delivery on a healthy bucket. Mutating fresh-first ordering, the terminal check, the age budget and the limiter wakeup each fails the pick's own tests

Two behaviour notes carried from #43022, not introduced by this backport: in-flush retries now log one WARNING per flush (s3 logging: N in-call retries across M uploads this flush) instead of one per attempt, and a flush with a single upload (one event, or s3_batch_file_upload) has no sibling, so a terminal object there still retries like it does on the rc today

Type

🐛 Bug Fix

…r-old retries by default, opt-in adaptive concurrency (#43022)

* fix(s3_v2): drop terminal upload failures, bound retries per flush and enforce the queue cap at enqueue

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

* fix(s3_v2): keep retrying credential-rotation 403s, only AccessDenied-style errors are terminal

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

* test(env_keys): exclude DEFAULT_S3_MAX_FLUSH_ATTEMPTS as an internal tuning var

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

* fix(s3_v2): retry every 5xx, warn on first queue overflow, validate the flush budget

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

* fix(s3_v2): read the queue cap defensively so un-initialized loggers still enqueue

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

* fix(s3_v2): drop the getattr in _enqueue and tighten the retry tests

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

* fix(s3_v2): keep the constructor flush budget when the callback override is invalid

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

* feat(s3_v2): adapt per-object upload concurrency to sink latency and throttling

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

* refactor(s3_v2): tidy adaptive limiter

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

* perf(s3_v2): wake one waiter per released upload slot

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

* feat(s3_v2): make the enqueue queue cap configurable with s3_max_queue_size

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

* test(s3_v2): audit cells for cache hits, coded 403 and callback modes

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

* fix(s3_v2): retry bucket-wide failures by default, age-budget requeues and make terminal drops and adaptive concurrency opt-in

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

* refactor(s3_v2): suppress the missing-waiter ValueError explicitly in the adaptive limiter

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

* fix(s3_v2): count oldest events trimmed after a failed flush as callback failures

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

* style(s3_v2): move the mutable-ok marker onto the list literal it suppresses

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

* fix(s3_v2): report post-flush overflow drops once and grow adaptive concurrency above the floor before asserting back-off

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

* test(s3_v2): fail the SlowDown back-off test when the measured window sees no PUTs

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

* fix(s3_v2): restore base retry defaults, opt-in age budget, no enqueue cap, back off outside the limiter slot

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

* fix(s3_v2): hoist the default no-op upload slot to a module constant

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

* fix(s3_v2): drop unused mutable-ok suppressions on queue appends

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

* fix(s3_v2): keep the retry queue oldest-first and prioritise fresh events at upload time

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

* style(s3_v2): keep the mutable-ok marker on the queue list literal

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

* fix(s3_v2): build request bodies inside the upload slot and keep the sync retry set at base parity

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

* test(s3_v2): drop wall-clock sleeps from the unit tests

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

* fix(s3_v2): rebuild the request body inside the slot on every retry attempt

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

* test(s3_v2): anchor the backoff window on the first observed failure and tighten shard assertions

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

* fix(s3_v2): default the upload slot to the logger limiter so monkeypatched doubles keep working

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

* test(s3_v2): clear ambient AWS env credentials so the rotating profile signs the sync retry test

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

* test(s3_v2): shrink the linear send-batch perf test to 2k/8k elements

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

* test(s3_v2): fix stale batch sizes in the perf test assert message

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

* fix(s3_v2): keep async in-call retries on the base 403/500/503 set

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

* fix(s3_v2): hold the upload slot across retries, restore the bool upload contract, and fail safe on bool config

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

* fix(s3_v2): mark dropped uploads by element identity so a shared key cannot mask a retryable sibling

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

* fix(s3_v2): make the per-flush drop lookup constant time

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

* fix(s3_v2): take the upload slot in the caller like base, build the body once per attempt loop

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

* fix(s3_v2): match base retry, logging and hook behaviour unless the new options are opted in

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

* test(s3_v2): assert the wire key in the init-bypassed sync upload test

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

* test(s3_v2): assert the signed headers and wire key in the init-bypassed sync upload test

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

* fix(s3_v2): default the upload limiter at class level instead of reading it with getattr

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

* fix(s3_v2): drop the duplicate annotations that redeclare the class-level counters

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

* feat(s3_v2): drop terminal-failed uploads by default and bound retry age to one hour

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

* fix(s3_v2): fall back to the configured retry age on invalid values

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

* test(s3_v2): drive retry-age tests from a fixed clock

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

* test(s3_v2): audit cells for retry-age opt-out and 429 single-put parity

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

---------

Co-authored-by: yucheng <yucheng@berri.ai>
Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
(cherry picked from commit e47b1f2)
@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.

@greptile-apps

greptile-apps Bot commented Sep 26, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 4/5

[High risk] Adds adaptive concurrency control to S3 upload integration.

The PR should not merge until terminal-only failures stop being requeued indefinitely

Findings

  1. P1 Terminal uploads retry indefinitely ▶
  2. P2 Batch files bypass fresh-first ordering ▶

Summary

The PR adds S3 upload retry classification, a retry-age and queue policy, fresh-first scheduling, and opt-in adaptive concurrency, with unit and integration coverage

  • Terminal failures are still retried indefinitely when a flush has no successful uploads
  • Fresh-first scheduling does not take effect in batch-file mode

Reviews (1) · Last reviewed commit: "fix(s3_v2): upload fresh events first, d..."

Comment on lines +649 to +652
requeued: Final = (
tuple(element for element, _ in failed)
if bucket_wide
else tuple(

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.

P1 Terminal uploads retry indefinitely When every PUT fails, this branch requeues terminally rejected objects, so one permanently rejected log is uploaded on every flush.

if not failed:
self._flush_retries = 0
self._flush_dropped = {} # mutable-ok: per-flush drop marks read back by _upload_bounded
stale: Final = min(self._requeued_count, len(uploads)) if len(uploads) == len(batch) else 0

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.

P2 Batch files bypass fresh-first ordering Grouping changes the upload count and disables rotation, so failed files take upload slots before fresh logs.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

@yuneng-berri
yuneng-berri merged commit 822ccfc into rc/1.104.0 Sep 26, 2026
7 checks passed
@yuneng-berri
yuneng-berri deleted the litellm_backport_rc_1_104_0_43022 branch September 26, 2026 22:46
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