Repository navigation
fix(responses): retry a bridged stream failing before its first chunk - #45076
Draft
Aasif-Simpplr wants to merge 1 commit into
Draft
Aasif-Simpplr wants to merge 1 commit into
Aasif-Simpplr wants to merge 1 commit into
Conversation
The completion bridge returned a deferred provider stream (Vertex AI, Gemini) unopened, so an error on its opening request, e.g. a 503, raised on the first iteration after the Router had already returned. No retry or fallback ran for it. Open the stream in async_response_api_handler, matching what BerriAI#44276 does for chat completions in Router._acompletion.
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
Contributor
6 tasks done
This branch has not been 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:
/v1/responsesstreams to Vertex AI or Gemini are never retriedresponse.failednum_retriesand fallbacks never run for itHow it solves it:
Router._acompletionIntentional product change: when every attempt fails before the first chunk, the client gets an HTTP 503 error instead of a 200 stream carrying
response.failed, matching providers whose streams are not deferredUser Flow
Before: a developer streaming
/v1/responsesfrom a Vertex AI Gemini model gets a failed response on one transient 503router_settings.num_retries: 2for avertex_ai/gemini-3.8-flashdeployment"stream": trueUNAVAILABLEresponse.failed, and Vertex AI saw only that one requestAfter: the same request is retried and streams the answer
router_settings.num_retries: 2for avertex_ai/gemini-3.8-flashdeployment"stream": trueUNAVAILABLEPre-Submission checklist
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@greptileaito re-request a review after pushing changes)Screenshots / Proof of Fix
Real Vertex AI calls (
vertex_ai/gemini-3.8-flash, locationglobal) through a local proxy. The deployment'sapi_basepoints at a small forwarder on127.0.0.1:8099that answers the first NstreamGenerateContentrequests with Google's own 503 body and forwards every other request unchanged tohttps://aiplatform.googleapis.com.Before (736ff14)
One 503 before the first chunk
stream request #1: injected 503, and no second requestEvery attempt fails before the first chunk
response.failedevent as abovestream request #1: injected 503, and no second requestAfter (18d09d2)
One 503 before the first chunk
stream request #1: injected 503, thenstream request #2: forwarded to https://aiplatform.googleapis.comEvery attempt fails before the first chunk
stream request #1,#2,#3: injected 503Type
🐛 Bug Fix
Caveats (if any)
Medium
litellm.responsesstream path is untouchedLow
response.failedeventFinal Attestation