feat(auth): add retry with exponential backoff to refreshClaudeOAuthToken#18
Open
iceteaSA wants to merge 1 commit into
Open
feat(auth): add retry with exponential backoff to refreshClaudeOAuthToken#18iceteaSA wants to merge 1 commit into
iceteaSA wants to merge 1 commit into
Conversation
…oken Currently a single 5xx or transient network error (ECONNRESET, ECONNREFUSED, ETIMEDOUT) during token refresh kills the session. Adds optional maxRetries (default: 2) and baseDelayMs (default: 500) parameters with exponential backoff. 4xx errors and ClaudeOAuthRefreshError throw immediately without retry. Non-breaking: callers that don't pass retry options get the new resilient behavior by default.
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
Adds resilient retry logic to
refreshClaudeOAuthToken:maxRetries) with delays of 0ms, 500ms, 1000ms (configurable viabaseDelayMs)ECONNRESET,ECONNREFUSED,ETIMEDOUT,UND_ERR_CONNECT_TIMEOUT, and generic "fetch failed"ClaudeOAuthRefreshError) are not retriedMotivation
Currently a single transient error during token refresh (e.g., a Cloudflare 502 or a momentary network blip) causes the entire session to fail. This is especially impactful for long-running sessions where a brief infrastructure hiccup shouldn't require re-authentication.
Testing
All existing tests pass. The retry logic handles both
FallbackAccountManager.refreshAccountNow()(which calls this function) and the main account refresh path in the OpenCode plugin.