Repository navigation
fix(proxy): backport the /v1/messages retry spend log fix and team delete test fix to rc/1.108.0 - #49553
Merged
Conversation
… 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
had a problem deploying
to
integration-license
November 1, 2026 03:15 — with
GitHub Actions
Failure
yuneng-berri
temporarily deployed
to
integration-license
November 1, 2026 03:15 — with
GitHub Actions
Inactive
yuneng-berri
temporarily deployed
to
integration-license
November 1, 2026 03:15 — with
GitHub Actions
Inactive
yuneng-berri
temporarily deployed
to
integration-license
November 1, 2026 03:15 — with
GitHub Actions
Inactive
yuneng-berri
temporarily deployed
to
integration-license
November 1, 2026 03:15 — with
GitHub Actions
Inactive
yuneng-berri
temporarily deployed
to
integration-license
November 1, 2026 03:15 — with
GitHub Actions
Inactive
yuneng-berri
had a problem deploying
to
integration-license
November 1, 2026 03:15 — with
GitHub Actions
Failure
yuneng-berri
temporarily deployed
to
integration-license
November 1, 2026 03:15 — with
GitHub Actions
Inactive
yuneng-berri
had a problem deploying
to
integration-license
November 1, 2026 03:15 — with
GitHub Actions
Failure
yuneng-berri
temporarily deployed
to
integration-license
November 1, 2026 03:15 — with
GitHub Actions
Inactive
yuneng-berri
temporarily deployed
to
integration-license
November 1, 2026 03:15 — with
GitHub Actions
Inactive
yuneng-berri
temporarily deployed
to
integration-license
November 1, 2026 03:15 — with
GitHub Actions
Inactive
kerry-berri
approved these changes
Nov 2, 2026
This branch was previously deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
TLDR
Problem this solves:
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
"stream": trueto a model group with two deploymentsmsg_..._a2msg_..._a1, with that attempt's token counts, and nothing for the answer they gotAfter: the logs match what the developer received
"stream": truemsg_..._a2msg_..._a2with its own token counts, and the first attempt as a failurePre-Submission checklist
Please complete all items before asking a LiteLLM maintainer to review your PR
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 moreDelays 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
tests/integration/run.py providers --workers 2ontest_anthropic_messages_pre_content_retry_wire.pytest_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 withState did not converge: [], meaning no spend row ever appeared under the retry's message idLarge team delete
tests/integration/run.py management --workers 2ontest_team_delete_large_membership.py, 5 runs with a timer around/team/deleteAfter (1321862)
Pre-content retry spend row
test_stream_error_frame_after_content_is_not_retried_and_keeps_its_spend_rowLarge team delete
test_team_update_adds_model_on_peer_for_inference_routesin 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 itThe 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 declaredlitellm_logging.pyconflict, where onlyattempt_scoped_copyis takenA gauntlet-mini review with five lenses plus a verifier drove
Router.aanthropic_messagesagainst 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 scenariosType
🐛 Bug Fix
✅ Test
Caveats (if any)
Medium
allowed_failsset, a deployment that recovers by retry can be cooled downLow
Final Attestation