fix: expand recoverable error codes in token refresh handler#73
Open
Zeeeen0 wants to merge 1 commit intotickernelz:masterfrom
Open
fix: expand recoverable error codes in token refresh handler#73Zeeeen0 wants to merge 1 commit intotickernelz:masterfrom
Zeeeen0 wants to merge 1 commit intotickernelz:masterfrom
Conversation
Add OIDC standard error codes (invalid_client, invalid_grant, unauthorized_client) and expired keyword matching to the recoverable error list in handleRefreshError. Previously these errors caused an immediate throw, bypassing unhealthy marking and account rotation, which could lead to max iteration loops or instant request failure.
|
Can this PR fix the issue of the opencode process being interrupted? |
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.
Problem
When
refreshAccessToken()fails with OIDC standard error codes likeinvalid_client,invalid_grant, orunauthorized_client, thehandleRefreshError()method does not recognize them as recoverable. This causes an immediatethrowthat exits the request loop entirely, instead of marking the account as unhealthy and allowing account rotation or retry.Observed error log:
The
invalid_clientcode is not in the recoverable list, so it falls through to an unrecoverable throw — even though the error message clearly indicates an expired/auth-related issue that should be handled gracefully.This can manifest as:
Root Cause
The recoverable error list in
handleRefreshError()only included:ExpiredTokenExceptionInvalidTokenExceptionHTTP_401HTTP_403Invalid refresh token provided(message match)Any error code outside this list falls through to an unrecoverable
throw, even when the error is clearly auth-related and should trigger unhealthy marking + account rotation.Fix
Expand the recoverable error list with:
invalid_client— OIDC standard, returned when client credentials are rejected or expiredinvalid_grant— OIDC standard, returned when refresh token is expired/revokedunauthorized_client— OIDC standard, returned when client lacks permissionerror.message.toLowerCase().includes('expired')— catch-all for any expiry-related messageerror.code?.toLowerCase().includes('expired')— catch-all for any expiry-related error codeThese errors now correctly trigger
markUnhealthy()→shouldContinue: true, allowing the request loop to attempt account rotation or kiro-cli sync recovery.Changes
src/core/auth/token-refresher.ts: Added 5 new conditions to the recoverable error check inhandleRefreshError()