Skip to content

fix(proxy): backport the /v1/messages retry spend log fix and team delete test fix to rc/1.108.0 - #49553

Merged
yuneng-berri merged 2 commits into
rc/1.108.0from
litellm_chore_8c713d
Nov 2, 2026
Merged

yuneng-berri merged 2 commits into
rc/1.108.0from
litellm_chore_8c713d

Conversation

@yuneng-berri

Copy link
Copy Markdown
Contributor

TLDR

Problem this solves:

  • rc/1.108.0 logs a retried /v1/messages stream's spend under the failed attempt
  • Two rc integration tests fail because of that bug and a tight test timeout

How it solves it:

Intentional product change: when the router retries a /v1/messages stream that hit an overloaded error before any content, the failed attempt now logs as a failure and the spend row moves to the retry the caller actually got. Failure callbacks, Prometheus failure metrics and router cooldown counting now see that failed attempt, same as main since Oct 16

User Flow

Before: a developer whose /v1/messages stream is retried after an overloaded error sees the wrong request in their logs

  1. They send POST https://litellm-domain/v1/messages with "stream": true to a model group with two deployments
  2. The first deployment starts the message and then sends an overloaded error, so the gateway retries on the same group
  3. They get the full answer, with a message id like msg_..._a2
  4. https://litellm-domain/ui/?page=logs shows one successful request under the first attempt's id msg_..._a1, with that attempt's token counts, and nothing for the answer they got

After: the logs match what the developer received

  1. They send the same POST https://litellm-domain/v1/messages with "stream": true
  2. The first deployment starts the message and then sends an overloaded error, so the gateway retries on the same group
  3. They get the full answer, with a message id like msg_..._a2
  4. https://litellm-domain/ui/?page=logs shows the successful request under msg_..._a2 with its own token counts, and the first attempt as a failure

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

There is no live provider run behind this PR, because a real Anthropic upstream can't be made to send an overloaded error mid-stream on demand. The proof is the integration harness, which boots a real proxy with Postgres and Redis in front of a scripted upstream, run one node at a time against native Postgres 17 and Redis 8

Before (8f3af1b)

Pre-content retry spend row

  1. tests/integration/run.py providers --workers 2 on test_anthropic_messages_pre_content_retry_wire.py
  2. 29 of 35 passed in one run. All 6 error frame cases of test_stream_failing_before_content_is_retried_on_the_same_group_and_completes (529, 429 and 500 after message_start, each with deployment and request budgets) failed with State did not converge: [], meaning no spend row ever appeared under the retry's message id

Large team delete

  1. tests/integration/run.py management --workers 2 on test_team_delete_large_membership.py, 5 runs with a timer around /team/delete
  2. 1 of 5 runs failed with a ReadTimeout against the client's 15s limit, and the delete took 5.4s to 11.6s

After (1321862)

Pre-content retry spend row

  1. Same command
  2. 108 of 108 passed over 3 runs of 36 nodes, including fix(proxy): keep a retried /v1/messages stream's spend log by logging the superseded attempt as a failure #45136's new test_stream_error_frame_after_content_is_not_retried_and_keeps_its_spend_row

Large team delete

  1. Same command, 4 runs
  2. 4 of 4 passed, and the delete took 4.3s to 4.8s
  3. test_team_update_adds_model_on_peer_for_inference_routes in replica mode also passed 6 of 6, so the router change in fix(proxy): keep a retried /v1/messages stream's spend log by logging the superseded attempt as a failure #45136 didn't disturb it

The picked unit tests pass on rc, 6243 mapped tests pass with the same 12 failures as rc's tip (venv gaps such as semantic_router), and both picks match the original commits apart from the declared litellm_logging.py conflict, where only attempt_scoped_copy is taken

A gauntlet-mini review with five lenses plus a verifier drove Router.aanthropic_messages against a fake upstream at this branch and at rc's tip. It found one regression, listed under Caveats, and every claim of #45136 held in about 20 scenarios

Type

🐛 Bug Fix
✅ Test

Caveats (if any)

Medium

Low

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

devin-ai-integration Bot and others added 2 commits October 31, 2026 18:02
… the superseded attempt as a failure (#45136)

* fix(proxy): keep a retried /v1/messages stream's spend log by logging the superseded attempt as a failure

A /v1/messages stream the router retries before any content shares one logging object across both attempts. The superseded attempt's end-of-stream logging ran as a success (a usage-only or placeholder result) and claimed the request's one-shot success log, so the recovered stream's spend row was either missing or written under the superseded attempt's message id. The passthrough logging path now logs an Anthropic stream whose frames carry an `event: error` as a failure with whatever usage the provider reported, the way a dropped stream already does, and the router closes the superseded stream before it opens the retry so that logging is queued first.

* fix(proxy): log a provider error frame through an attempt-scoped logging copy

The error-frame failure stashed the superseded attempt's usage on the logging
object the retry shares, so the retry's success log carried the failed
attempt's token counts. The failure now logs through a copy of the logging
object with its own model_call_details, and the helper moves into the
Anthropic passthrough logging handler so the proxy streaming handler only
routes by endpoint type.

* fix(proxy): scope the error-frame failure log to streams closed at the frame

A stream that ran to its end at the provider's error frame kept logging
through the success route before this PR, and the attempt-scoped failure
log is now taken only for a stream the router closed at that frame, with
the copy made at the close so the retry's deployment never reaches it

* chore: drop duplicate litellm import and mark the stream_ended rebind

* fix(proxy): log only router-superseded attempts as error-frame failures

A client that hangs up at a forwarded error frame closed the stream the same way the router closes a superseded attempt, so a non-retried stream lost its spend. The router now closes a superseded attempt through aclose_superseded_attempt, and only that close routes the attempt to the failure log

* test: type the _settle helper's recorded events

---------

Co-authored-by: mateo-berri <277851410+mateo-berri@users.noreply.github.com>
(cherry picked from commit 8bb8ac7)
… rc/1.108.0

Takes only the max_workers change in test_team_delete_large_membership.py from 7e8be61. The 16-thread key warmup slowed the /team/delete that follows it to 5.4-11.6s locally against the client's 15s timeout, and 2 threads brings it to 4.1-5.4s
@yuneng-berri
yuneng-berri merged commit 61fe5be into rc/1.108.0 Nov 2, 2026
16 of 19 checks passed
@yuneng-berri
yuneng-berri deleted the litellm_chore_8c713d branch November 2, 2026 17:23

This branch was previously deployed

1 inactive deployment
integration-license — 13218620 Deployed Nov 1, 2026 by yuneng-berri via integration providers #44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants