Skip to content

Retry once with a forced credential refresh on upstream 401 - #30

Merged
bbrowning merged 1 commit into
mainfrom
fix-gcloud-token-refresh-retry
Aug 13, 2026
Merged

Retry once with a forced credential refresh on upstream 401#30
bbrowning merged 1 commit into
mainfrom
fix-gcloud-token-refresh-retry

Conversation

@bbrowning

Copy link
Copy Markdown
Owner

Vertex AI requests can fail with Google's own 401 ("invalid authentication credentials") even though GCloudInjector.Inject considered its cached OAuth token locally valid — most likely because a long-running proxy process's cached token can look unexpired by wall clock while genuinely being expired server-side after a host suspend/resume cycle. Previously the only fix was a full paude stop + start, which restarts the proxy process and forces a fresh token.

GCloudInjector gains ForceRefresh(), which discards the cached credentials and rebuilds them from the original ADC source so the next token fetch is a real network exchange rather than a reused token. Store gains MatchInjector() so callers can look up which injector would handle a request. The proxy's response pipeline now buffers request bodies for any request handled by a Refresher injector and, on an upstream 401, calls ForceRefresh and retries the request exactly once with the newly fetched token before giving up. This is root-cause-agnostic: whatever caused the local validity check to disagree with the server, trusting the server's rejection and retrying with a guaranteed-fresh credential recovers without requiring a full process restart.

Vertex AI requests can fail with Google's own 401 ("invalid
authentication credentials") even though GCloudInjector.Inject
considered its cached OAuth token locally valid — most likely because
a long-running proxy process's cached token can look unexpired by
wall clock while genuinely being expired server-side after a host
suspend/resume cycle. Previously the only fix was a full `paude stop`
+ `start`, which restarts the proxy process and forces a fresh token.

GCloudInjector gains ForceRefresh(), which discards the cached
credentials and rebuilds them from the original ADC source so the
next token fetch is a real network exchange rather than a reused
token. Store gains MatchInjector() so callers can look up which
injector would handle a request. The proxy's response pipeline now
buffers request bodies for any request handled by a Refresher
injector and, on an upstream 401, calls ForceRefresh and retries the
request exactly once with the newly fetched token before giving up.
This is root-cause-agnostic: whatever caused the local validity
check to disagree with the server, trusting the server's rejection
and retrying with a guaranteed-fresh credential recovers without
requiring a full process restart.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@bbrowning
bbrowning merged commit 43f9bbc into main Aug 13, 2026
6 checks passed
@bbrowning
bbrowning deleted the fix-gcloud-token-refresh-retry branch August 13, 2026 22:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant