1. 08 Apr, 2026 1 commit
    • haruka's avatar
      fix: resolve refresh token race condition causing false invalid_grant errors · ef8a7c0a
      haruka authored and 陈曦's avatar 陈曦 committed
      
      
      When multiple goroutines/workers concurrently refresh the same OAuth token,
      the first succeeds but invalidates the old refresh_token (rotation). Subsequent
      attempts using the stale token get invalid_grant, which was incorrectly treated
      as non-retryable, permanently marking the account as ERROR.
      
      Three complementary fixes:
      1. Race-aware recovery: after invalid_grant, re-read DB to check if another
         worker already refreshed (refresh_token changed) — return success instead
         of error
      2. In-process mutex (sync.Map of per-account locks): prevents concurrent
         refreshes within the same process, complementing the Redis distributed lock
      3. Increase default lock TTL from 30s to 60s to reduce TTL-expiry races
      Co-Authored-By: default avatarClaude Opus 4.6 (1M context) <noreply@anthropic.com>
      ef8a7c0a
  2. 22 Mar, 2026 1 commit
  3. 15 Mar, 2026 1 commit
    • erio's avatar
      feat: unified OAuth token refresh API with distributed locking · 1fc9dd7b
      erio authored
      Introduce OAuthRefreshAPI as the single entry point for all OAuth token
      refresh operations, eliminating the race condition where background
      refresh and inline refresh could simultaneously use the same
      refresh_token (fixes #1035).
      
      Key changes:
      - Add OAuthRefreshExecutor interface extending TokenRefresher with CacheKey
      - Add OAuthRefreshAPI.RefreshIfNeeded with lock → DB re-read → double-check flow
      - Add ProviderRefreshPolicy / BackgroundRefreshPolicy strategy types
      - Simplify all 4 TokenProviders to delegate to OAuthRefreshAPI
      - Rewrite TokenRefreshService.refreshWithRetry to use unified API path
      - Add MergeCredentials and BuildClaudeAccountCredentials helpers
      - Add 40 unit tests covering all new and modified code paths
      1fc9dd7b