Skip to content

fix: handle invalid_grant as permanent auth error with improved resilience#69

Open
RaphaelManke wants to merge 1 commit intotickernelz:masterfrom
RaphaelManke:fix/invalid-grant-auth-resilience
Open

fix: handle invalid_grant as permanent auth error with improved resilience#69
RaphaelManke wants to merge 1 commit intotickernelz:masterfrom
RaphaelManke:fix/invalid-grant-auth-resilience

Conversation

@RaphaelManke
Copy link

Problem

When the Kiro server returns invalid_grant / Invalid grant provided during token refresh, the error was not recognized as a fatal auth failure. This caused the plugin to:

  • Re-throw the error instead of marking the account unhealthy
  • Retry the dead token up to 10 times before giving up
  • Silently swallow writeToKiroCli failures, causing stale tokens to persist

Changes

  • Add Invalid grant provided and invalid_grant to isPermanentError() so accounts fail fast
  • Catch Invalid grant provided in token-refresher error handler
  • Fix CLI sync skip condition to also verify token is not already expired (expires_at > Date.now())
  • Log writeToKiroCli failures instead of silently swallowing them

Root cause

invalid_grant is returned when a refresh token is revoked, expired server-side, or invalidated by a concurrent refresh (rotation race). The fix ensures these are treated as permanent failures requiring re-authentication rather than transient errors worth retrying.

Related to #43 #49

…ience

- Add 'Invalid grant provided' and 'invalid_grant' to isPermanentError()
  so accounts fail fast instead of retrying 10 times with a dead token
- Catch 'Invalid grant provided' message in token-refresher error handler
- Fix CLI sync skip condition to also check token is not already expired
  (prevents stale-but-healthy tokens from blocking fresher CLI tokens)
- Log writeToKiroCli failures instead of silently swallowing them

Fixes cases where refresh token rotation or server-side revocation caused
KiroTokenRefreshError: Refresh failed: Invalid grant provided
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant