diff --git a/cmd/fetch_codex_models/main.go b/cmd/fetch_codex_models/main.go index 50bb7dcb19..5eb88bc71a 100644 --- a/cmd/fetch_codex_models/main.go +++ b/cmd/fetch_codex_models/main.go @@ -195,7 +195,7 @@ func ensureAccessToken(ctx context.Context, store *sdkauth.FileTokenStore, auth } svc := codexauth.NewCodexAuthWithProxyURL(nil, auth.ProxyURL) - tokenData, errRefresh := svc.RefreshTokensWithRetry(ctx, refreshToken, 3) + tokenData, errRefresh := svc.RefreshTokensWithRetry(ctx, refreshToken, 3, auth.ID) if errRefresh != nil { return "", false, errRefresh } diff --git a/internal/auth/codex/openai_auth.go b/internal/auth/codex/openai_auth.go index 681747caf5..a7f2ccbd33 100644 --- a/internal/auth/codex/openai_auth.go +++ b/internal/auth/codex/openai_auth.go @@ -274,7 +274,7 @@ func (o *CodexAuth) CreateTokenStorage(bundle *CodexAuthBundle) *CodexTokenStora // RefreshTokensWithRetry refreshes tokens with a built-in retry mechanism. // It attempts to refresh the tokens up to a specified maximum number of retries, // with an exponential backoff strategy to handle transient network errors. -func (o *CodexAuth) RefreshTokensWithRetry(ctx context.Context, refreshToken string, maxRetries int) (*CodexTokenData, error) { +func (o *CodexAuth) RefreshTokensWithRetry(ctx context.Context, refreshToken string, maxRetries int, authID string) (*CodexTokenData, error) { var lastErr error for attempt := 0; attempt < maxRetries; attempt++ { @@ -292,12 +292,12 @@ func (o *CodexAuth) RefreshTokensWithRetry(ctx context.Context, refreshToken str return tokenData, nil } if isNonRetryableRefreshErr(err) { - log.Warnf("Token refresh attempt %d failed with non-retryable error: %v", attempt+1, err) + log.Warnf("Token refresh attempt %d for auth %s failed with non-retryable error: %v", attempt+1, authID, err) return nil, err } lastErr = err - log.Warnf("Token refresh attempt %d failed: %v", attempt+1, err) + log.Warnf("Token refresh attempt %d for auth %s failed: %v", attempt+1, authID, err) } return nil, fmt.Errorf("token refresh failed after %d attempts: %w", maxRetries, lastErr) diff --git a/internal/auth/codex/openai_auth_test.go b/internal/auth/codex/openai_auth_test.go index e7d939b0a3..5a4634d141 100644 --- a/internal/auth/codex/openai_auth_test.go +++ b/internal/auth/codex/openai_auth_test.go @@ -33,7 +33,7 @@ func TestRefreshTokensWithRetry_NonRetryableOnlyAttemptsOnce(t *testing.T) { }, } - _, err := auth.RefreshTokensWithRetry(context.Background(), "dummy_refresh_token", 3) + _, err := auth.RefreshTokensWithRetry(context.Background(), "dummy_refresh_token", 3, "test-auth") if err == nil { t.Fatalf("expected error for non-retryable refresh failure") } diff --git a/internal/runtime/executor/codex_executor.go b/internal/runtime/executor/codex_executor.go index 73187963c7..6c7c236a55 100644 --- a/internal/runtime/executor/codex_executor.go +++ b/internal/runtime/executor/codex_executor.go @@ -1386,7 +1386,7 @@ func (e *CodexExecutor) Refresh(ctx context.Context, auth *cliproxyauth.Auth) (* return auth, nil } svc := codexauth.NewCodexAuthWithProxyURL(e.cfg, auth.ProxyURL) - td, err := svc.RefreshTokensWithRetry(ctx, refreshToken, 3) + td, err := svc.RefreshTokensWithRetry(ctx, refreshToken, 3, auth.ID) if err != nil { return nil, err }