Repository navigation
fix(google-vertex): retry transient pre-stream failures and stale ADC - #91222
damianFelixPago wants to merge 1 commit into
Conversation
Vertex streaming requests currently fail the whole turn on transient
pre-stream HTTP errors (429/503) and on 401s caused by a stale cached
ADC token. This adds:
- Bounded exponential-backoff retry (with jitter) for 429/503 responses
received before any SSE chunk is parsed, honoring Retry-After when
present. Once an SSE chunk has arrived, errors are not retried so we
never replay a partially-streamed turn.
- A single retry on 401 UNAUTHENTICATED for Vertex ADC: clear the cached
token, re-resolve headers, and retry once.
All behavior is Vertex-only and tunable via
OPENCLAW_GOOGLE_VERTEX_STREAM_{MAX_RETRIES,RETRY_BASE_DELAY_MS,RETRY_MAX_DELAY_MS}.
Diagnostics use the google-vertex/transport subsystem logger.
|
Thanks for the contribution. This PR still needs the requested real-behavior proof, and the branch has been idle since that ask. Close this stale external PR: its June head is dirty against substantially changed Google transport code, it has no inspectable real-behavior proof after the dated proof request, and the proposed retry path has unresolved availability and auth-override defects. So I’m closing this for now to keep the review queue honest. Please reopen or open a fresh PR with real-behavior proof (a live run, logs, or a reproducible validation transcript) and it will be reviewed again. Review detailsBest possible solution: If this reliability behavior remains needed, create a fresh current-main repair that ports only bounded pre-stream recovery, restricts 401 refresh to effective ADC authorization, and proves both flows with redacted real Vertex evidence. Do we have a high-confidence way to reproduce the issue? Yes, from source: current main sends one Vertex pre-stream request and immediately fails non-OK responses, while ADC headers are resolved once with no 401 recovery path. Is this the best way to solve the issue? No. The branch is incompatible with current transport ownership and its retry/auth logic is unsafe; a narrow port over current main is the maintainable route. Security review: Security review cleared: The diff changes only Google plugin transport, ADC cache handling, and tests; no dependency, workflow, secret, or supply-chain concern was found. AGENTS.md: found and applied where relevant. What I checked:
Likely related people:
Codex review notes: model internal, reasoning high; reviewed against 75ef5aebecb8. |
|
This pull request has been automatically marked as stale due to inactivity. |
|
ClawSweeper applied the proposed close for this PR.
|
Summary
Vertex streaming requests currently fail the entire turn on two transient,
recoverable conditions:
429/503from the Vertex endpoint (rate limiting /backend unavailability), surfaced as a hard error before any SSE chunk is
read.
401 UNAUTHENTICATEDcaused by a stale cached ADC token — the cachecan outlive the upstream credential, which currently forces a restart to
recover.
This PR adds narrowly-scoped, Vertex-only recovery for both:
429/503: exponential backoff with jitter,honoring
Retry-After(delta-seconds or HTTP-date) when present. Retries onlyhappen before the first SSE chunk is parsed — once streaming has started we
never retry, so a partially-streamed turn is never replayed.
401ADC retry: on a Vertex401 UNAUTHENTICATEDwhile using ADC,clear the cached token, re-resolve request headers, and retry exactly once.
Non-Vertex Google (Generative Language API / API-key) behavior is unchanged.
Why
Vertex deployments periodically see
429/503and post-rotation401s. Todayeach one aborts a turn that would have succeeded on an immediate retry — the
single largest source of avoidable turn failures we observe against Vertex.
Configuration (all optional, Vertex-only)
OPENCLAW_GOOGLE_VERTEX_STREAM_MAX_RETRIES2OPENCLAW_GOOGLE_VERTEX_STREAM_RETRY_BASE_DELAY_MS250OPENCLAW_GOOGLE_VERTEX_STREAM_RETRY_MAX_DELAY_MS2000Defaults give ~2 quick retries;
MAX_RETRIES=0fully disables the newpre-stream retry path.
Implementation notes
fetchGooglePreStreamResponse()wraps the pre-stream POST and is the onlyplace the retry loop lives; both the non-Gemini-3 and Gemini-3 first-response
paths route through it, so retry semantics are identical.
Retry-Afterparsing supports both integer seconds and HTTP-date.options.signal).clearGoogleVertexAdcTokenCache()is exported fromvertex-adc.tsfor the401 path; the existing test-only
resetGoogleVertexAuthorizedUserTokenCacheForTest()is kept as a thin alias for back-compat.
createSubsystemLogger("google-vertex/transport")(
.debug, gated byOPENCLAW_LOG_LEVEL) — no new stdout/stderr noise.Relationship to #61443
#61443 ("configurable retry for LLM provider API calls") adds a generic
provider-retry framework at the agent/provider layer (
src/infra/retry.ts,src/agents/provider-retry.ts) and wires it intoopenai-transport-stream.ts.This change is complementary, not a duplicate:
(
extensions/google/transport-stream.ts), where the Vertex pre-stream requestis issued and parsed.
cached token and re-resolve headers before retrying. A generic status-based
retry would replay the same stale token and fail again.
If preferred, the 429/503 portion can later be expressed in terms of #61443's
framework once it lands; the 401-ADC portion stays Vertex-specific regardless.
Test plan
extensions/google/transport-stream.test.ts— 66/66 pass on latestmain.New cases:
503→429→success and returns the recovered stream;still surfaces, partial content preserved);
401 UNAUTHENTICATED, clears the ADC cache, re-fetches the token, andretries once with the fresh
Authorizationheader.Additionally validated against live
gemini-3.1-pro-previewVertex traffic in aproduction deployment: real
streamGenerateContentrequests flow through the newpre-stream wrapper and complete normally, confirming the path is non-breaking on
real traffic.