From e1bd1d239facd486fd894ee49a8f8b522c97d833 Mon Sep 17 00:00:00 2001 From: Sehoon Shon Date: Tue, 3 Feb 2026 12:47:13 -0500 Subject: [PATCH] Set default max attempts to 3 and use the common variable (#18209) --- packages/core/src/core/geminiChat.ts | 8 ++++++-- packages/core/src/utils/retry.ts | 3 ++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/packages/core/src/core/geminiChat.ts b/packages/core/src/core/geminiChat.ts index a9cf192418..49c1ebf169 100644 --- a/packages/core/src/core/geminiChat.ts +++ b/packages/core/src/core/geminiChat.ts @@ -18,7 +18,11 @@ import type { } from '@google/genai'; import { toParts } from '../code_assist/converter.js'; import { createUserContent, FinishReason } from '@google/genai'; -import { retryWithBackoff, isRetryableError } from '../utils/retry.js'; +import { + retryWithBackoff, + isRetryableError, + DEFAULT_MAX_ATTEMPTS, +} from '../utils/retry.js'; import type { ValidationRequiredError } from '../utils/googleQuotaErrors.js'; import type { Config } from '../config/config.js'; import { @@ -621,7 +625,7 @@ export class GeminiChat { onRetry: (attempt, error, delayMs) => { coreEvents.emitRetryAttempt({ attempt, - maxAttempts: availabilityMaxAttempts ?? 10, + maxAttempts: availabilityMaxAttempts ?? DEFAULT_MAX_ATTEMPTS, delayMs, error: error instanceof Error ? error.message : String(error), model: lastModelToUse, diff --git a/packages/core/src/utils/retry.ts b/packages/core/src/utils/retry.ts index a0a8d48c80..f78bef5bd1 100644 --- a/packages/core/src/utils/retry.ts +++ b/packages/core/src/utils/retry.ts @@ -18,6 +18,7 @@ import { getErrorStatus, ModelNotFoundError } from './httpErrors.js'; import type { RetryAvailabilityContext } from '../availability/modelPolicy.js'; export type { RetryAvailabilityContext }; +export const DEFAULT_MAX_ATTEMPTS = 3; export interface RetryOptions { maxAttempts: number; @@ -40,7 +41,7 @@ export interface RetryOptions { } const DEFAULT_RETRY_OPTIONS: RetryOptions = { - maxAttempts: 3, + maxAttempts: DEFAULT_MAX_ATTEMPTS, initialDelayMs: 5000, maxDelayMs: 30000, // 30 seconds shouldRetryOnError: isRetryableError,