Repository navigation
Conversation
jflowers
force-pushed
the
opsx/gateway-token-refresh-fix
branch
from
April 29, 2026 19:34
3fd81e7 to
b5d5d46
Compare
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.
Summary
ACCESS_TOKEN_TYPE_UNSUPPORTED(401) errors after ~60 minutestokenExpiry/credExpiryfields) with safety margins and atomic stale-token invalidation on refresh failurePrepareRequestwithsync.Mutex.TryLock()deduplication and 5-second subprocess timeout.uf/gateway.log(0600 permissions) instead of discarding them;uf gateway statusshows the log pathRoot Cause
When the background token refresh failed (e.g., gcloud ADC credentials expired), the gateway continued forwarding the stale, expired token to Vertex AI.
PrepareRequestonly checked for an empty token, not an expired one. Combined with detached mode discarding all child process output, refresh failures were completely silent.How to Test
Automated tests
Manual testing — Vertex AI (requires GCP project with Claude access)
Manual testing — expired token error message
Manual testing — log file behavior
Manual testing — Bedrock (requires AWS account with Bedrock access)
Changes
internal/gateway/provider.govertexTokenLifetime,proactiveRefreshWindow,bedrockCredLifetime),tryProactiveRefresh()with goroutine+channel timeout, atomic token clearing on refresh failureinternal/gateway/gateway.godetach()with 0600 permissions, parent fd cleanup, log path in status outputinternal/gateway/gateway_test.goAGENTS.mdopenspec/changes/gateway-token-refresh-fix/Test Results
All 19 packages pass with
-race -count=1. 14 new test functions:TestVertexPrepareRequest_StaleTokenRegression(TC-006 regression test)TestVertexPrepareRequest_ValidTokenTestVertexPrepareRequest_ProactiveRefreshTestVertexPrepareRequest_ProactiveRefreshFailsTestVertexPrepareRequest_ProactiveRefreshTimeoutTestVertexRefreshFailure_ClearsTokenTestVertexPrepareRequest_ConcurrentProactiveRefresh(WaitGroup barrier + atomic counter)TestBedrockPrepareRequest_ExpiredCredentialsTestBedrockRefreshFailure_ClearsCredentialsTestBedrockPrepareRequest_ProactiveRefreshTestBedrockPrepareRequest_ProactiveRefreshFailsTestDetach_CreatesLogFileTestStatus_ShowsLogPathTestStart_ForegroundNoLogFileReview Council
Spec review: 5/5 APPROVE (2nd pass after fixing HIGH findings)
Code review: 5/5 APPROVE (2nd pass after implementing missing timeout)