Skip to content

fix(google-vertex): retry transient pre-stream failures and stale ADC - #91222

Closed
damianFelixPago wants to merge 1 commit into
openclaw:mainfrom
damianFelixPago:fix/google-vertex-transport-reliability
Closed

damianFelixPago wants to merge 1 commit into
openclaw:mainfrom
damianFelixPago:fix/google-vertex-transport-reliability

Conversation

@damianFelixPago

Copy link
Copy Markdown
Contributor

Summary

Vertex streaming requests currently fail the entire turn on two transient,
recoverable conditions:

  1. Pre-stream 429 / 503 from the Vertex endpoint (rate limiting /
    backend unavailability), surfaced as a hard error before any SSE chunk is
    read.
  2. 401 UNAUTHENTICATED caused by a stale cached ADC token — the cache
    can outlive the upstream credential, which currently forces a restart to
    recover.

This PR adds narrowly-scoped, Vertex-only recovery for both:

  • Bounded retry for pre-stream 429/503: exponential backoff with jitter,
    honoring Retry-After (delta-seconds or HTTP-date) when present. Retries only
    happen before the first SSE chunk is parsed — once streaming has started we
    never retry, so a partially-streamed turn is never replayed.
  • Single 401 ADC retry: on a Vertex 401 UNAUTHENTICATED while 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/503 and post-rotation 401s. Today
each 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)

Env var Default Meaning
OPENCLAW_GOOGLE_VERTEX_STREAM_MAX_RETRIES 2 Max pre-stream retries for 429/503
OPENCLAW_GOOGLE_VERTEX_STREAM_RETRY_BASE_DELAY_MS 250 Backoff base
OPENCLAW_GOOGLE_VERTEX_STREAM_RETRY_MAX_DELAY_MS 2000 Backoff ceiling

Defaults give ~2 quick retries; MAX_RETRIES=0 fully disables the new
pre-stream retry path.

Implementation notes

  • New fetchGooglePreStreamResponse() wraps the pre-stream POST and is the only
    place the retry loop lives; both the non-Gemini-3 and Gemini-3 first-response
    paths route through it, so retry semantics are identical.
  • Retry-After parsing supports both integer seconds and HTTP-date.
  • The retry sleep is abort-aware (honors options.signal).
  • A clearGoogleVertexAdcTokenCache() is exported from vertex-adc.ts for the
    401 path; the existing test-only resetGoogleVertexAuthorizedUserTokenCacheForTest()
    is kept as a thin alias for back-compat.
  • Diagnostics go through createSubsystemLogger("google-vertex/transport")
    (.debug, gated by OPENCLAW_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 into openai-transport-stream.ts.
This change is complementary, not a duplicate:

  • It does not reach the Google extension's own SSE transport
    (extensions/google/transport-stream.ts), where the Vertex pre-stream request
    is issued and parsed.
  • The 401 stale-ADC recovery here is auth-cache-specific: it must clear the
    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 latest main.
New cases:

  • retries pre-stream 503→429→success and returns the recovered stream;
  • does not retry once an SSE chunk has arrived (malformed-JSON mid-stream
    still surfaces, partial content preserved);
  • on 401 UNAUTHENTICATED, clears the ADC cache, re-fetches the token, and
    retries once with the fresh Authorization header.
pnpm exec vitest run extensions/google/transport-stream.test.ts
# Test Files 1 passed (1) / Tests 66 passed (66)

Additionally validated against live gemini-3.1-pro-preview Vertex traffic in a
production deployment: real streamGenerateContent requests flow through the new
pre-stream wrapper and complete normally, confirming the path is non-breaking on
real traffic.

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.
@openclaw-barnacle openclaw-barnacle Bot added extensions: google size: M triage: needs-real-behavior-proof Candidate: external PR needs after-fix proof from a real setup. labels Jun 7, 2026
@clawsweeper

clawsweeper Bot commented Jun 7, 2026 •

Copy link
Copy Markdown
Contributor

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 details

Best 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:

  • Vincent Koc: Current-main blame covers the central ADC and streaming ownership boundary after the post-PR Google transport work. (role: recent area contributor; confidence: high; commits: 8f2850d83e90; files: extensions/google/transport-stream.ts, extensions/google/vertex-adc.ts)
  • Alix-007: Authored the merged Vertex ADC timeout repair that now owns refresh deadlines and cache recovery behavior. (role: adjacent ADC hardening contributor; confidence: high; commits: e5259fa8bb4c; files: extensions/google/vertex-adc.ts, extensions/google/transport-stream.test.ts)
  • damianFelixPago: The author also appears in the merged history for the original production ADC support path, beyond this proposed branch. (role: original Vertex ADC contributor; confidence: medium; commits: f09b4ebe314e; files: extensions/google/vertex-adc.ts)

Codex review notes: model internal, reasoning high; reviewed against 75ef5aebecb8.

@clawsweeper clawsweeper Bot added the rating: 🌊 off-meta tidepool PR readiness rating does not apply to this item. label Jun 7, 2026
@clawsweeper clawsweeper Bot added rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. and removed rating: 🌊 off-meta tidepool PR readiness rating does not apply to this item. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Jun 14, 2026
@openclaw-barnacle

Copy link
Copy Markdown

This pull request has been automatically marked as stale due to inactivity.
Please add updates or it will be closed.

@openclaw-barnacle openclaw-barnacle Bot added stale Marked as stale due to inactivity triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. and removed stale Marked as stale due to inactivity labels Jul 21, 2026
@clawsweeper

clawsweeper Bot commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

ClawSweeper applied the proposed close for this PR.

@clawsweeper clawsweeper Bot closed this Aug 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

extensions: google merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P2 Normal backlog priority with limited blast radius. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. size: M status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. triage: needs-real-behavior-proof Candidate: external PR needs after-fix proof from a real setup.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant