Skip to content

Commit 460cd40

Browse files
committed
fix(codex): log account on token refresh failure
1 parent 5753d1a commit 460cd40

4 files changed

Lines changed: 6 additions & 6 deletions

File tree

cmd/fetch_codex_models/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ func ensureAccessToken(ctx context.Context, store *sdkauth.FileTokenStore, auth
195195
}
196196

197197
svc := codexauth.NewCodexAuthWithProxyURL(nil, auth.ProxyURL)
198-
tokenData, errRefresh := svc.RefreshTokensWithRetry(ctx, refreshToken, 3)
198+
tokenData, errRefresh := svc.RefreshTokensWithRetry(ctx, refreshToken, 3, auth.ID)
199199
if errRefresh != nil {
200200
return "", false, errRefresh
201201
}

internal/auth/codex/openai_auth.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ func (o *CodexAuth) CreateTokenStorage(bundle *CodexAuthBundle) *CodexTokenStora
274274
// RefreshTokensWithRetry refreshes tokens with a built-in retry mechanism.
275275
// It attempts to refresh the tokens up to a specified maximum number of retries,
276276
// with an exponential backoff strategy to handle transient network errors.
277-
func (o *CodexAuth) RefreshTokensWithRetry(ctx context.Context, refreshToken string, maxRetries int) (*CodexTokenData, error) {
277+
func (o *CodexAuth) RefreshTokensWithRetry(ctx context.Context, refreshToken string, maxRetries int, authID string) (*CodexTokenData, error) {
278278
var lastErr error
279279

280280
for attempt := 0; attempt < maxRetries; attempt++ {
@@ -292,12 +292,12 @@ func (o *CodexAuth) RefreshTokensWithRetry(ctx context.Context, refreshToken str
292292
return tokenData, nil
293293
}
294294
if isNonRetryableRefreshErr(err) {
295-
log.Warnf("Token refresh attempt %d failed with non-retryable error: %v", attempt+1, err)
295+
log.Warnf("Token refresh attempt %d for auth %s failed with non-retryable error: %v", attempt+1, authID, err)
296296
return nil, err
297297
}
298298

299299
lastErr = err
300-
log.Warnf("Token refresh attempt %d failed: %v", attempt+1, err)
300+
log.Warnf("Token refresh attempt %d for auth %s failed: %v", attempt+1, authID, err)
301301
}
302302

303303
return nil, fmt.Errorf("token refresh failed after %d attempts: %w", maxRetries, lastErr)

internal/auth/codex/openai_auth_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ func TestRefreshTokensWithRetry_NonRetryableOnlyAttemptsOnce(t *testing.T) {
3333
},
3434
}
3535

36-
_, err := auth.RefreshTokensWithRetry(context.Background(), "dummy_refresh_token", 3)
36+
_, err := auth.RefreshTokensWithRetry(context.Background(), "dummy_refresh_token", 3, "test-auth")
3737
if err == nil {
3838
t.Fatalf("expected error for non-retryable refresh failure")
3939
}

internal/runtime/executor/codex_executor.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1386,7 +1386,7 @@ func (e *CodexExecutor) Refresh(ctx context.Context, auth *cliproxyauth.Auth) (*
13861386
return auth, nil
13871387
}
13881388
svc := codexauth.NewCodexAuthWithProxyURL(e.cfg, auth.ProxyURL)
1389-
td, err := svc.RefreshTokensWithRetry(ctx, refreshToken, 3)
1389+
td, err := svc.RefreshTokensWithRetry(ctx, refreshToken, 3, auth.ID)
13901390
if err != nil {
13911391
return nil, err
13921392
}

0 commit comments

Comments
 (0)