feat(auth): add retry with exponential backoff to refreshClaudeOAuthToken#18
feat(auth): add retry with exponential backoff to refreshClaudeOAuthToken#18iceteaSA 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.
|
@cubic-dev-ai review this |
@ualtinok I have started the AI code review. It will take a few minutes to complete. |
|
Thanks for putting this together — the transient retry behavior is useful. I reworked it slightly on main in 0131669 so the shared OAuth helper retries transient network/5xx failures, while the OpenCode main-account path disables the helper retry and keeps its existing outer retry/backoff/file-lock layer single-sourced. That avoids multiplying refresh attempts against Anthropic's OAuth endpoint while still covering fallback/Pi/helper callers.\n\nClosing this PR as superseded by the reworked implementation on main. Appreciate the contribution! |
|
Closed as superseded by the reworked implementation merged on main in 0131669. Thanks again! |
Awesome! I saw you made a more robust mechanism for refreshes. Already rebased onto my Frankenstein's Fork |
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.