Repository navigation
Conversation
…once On a 401 before expires_at, an OpenAI OAuth account was cooled down and kept the same token until the periodic refresher reached it. doOpenAIUpstream now refreshes the rejected token under the OAuthRefreshAPI locks and resends once. Concurrent 401s with the same token on one instance share the attempt. While another instance holds the refresh lock, the stored token is reread up to openAILockMaxAttempts times; after that, or when the lock backend errors, the existing 401 handling applies. A non-retryable refresh error blocks scheduling and sets the account to error, as the periodic refresher does. Not refreshed: 401 bodies already treated as permanent, deactivation, missing scopes, and a token that has not worked since it was minted if this path minted it or the account has been cooled down since.
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.
Fixes #5542
The refresh and resend sit in
doOpenAIUpstreamunder theOAuthRefreshAPIlocks, so every route that sends through it is covered.Concurrent 401s with the same token on one instance share one refresh attempt, so a failed refresh is not repeated by every request in the burst. If another instance holds the refresh lock, the request rereads the stored token up to five times with the backoff the token provider already uses for that case and then takes main's 401 path, so a stuck lock cannot stall it. Not refreshed, because a refresh does not fix them: 401 bodies main treats as permanent, deactivation, missing scopes, and a token that has not worked since it was minted if this path minted it or the account has been cooled down since.
#7826 and #8034 retry in
Forwardand passthrough and leave a failed refresh to main's 401 handling; #8034 also retries the WebSocket handshake once. #8856 retries inForward, passthrough and the account tests and sets the account to error on a non-retryable refresh error, as this PR does.