mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-04-22 11:04:42 -07:00
fix(core): increase default retry attempts and add quota error backoff (#19949)
This commit is contained in:
@@ -18,7 +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 const DEFAULT_MAX_ATTEMPTS = 10;
|
||||
|
||||
export interface RetryOptions {
|
||||
maxAttempts: number;
|
||||
@@ -302,13 +302,18 @@ export async function retryWithBackoff<T>(
|
||||
classifiedError instanceof RetryableQuotaError &&
|
||||
classifiedError.retryDelayMs !== undefined
|
||||
) {
|
||||
currentDelay = Math.max(currentDelay, classifiedError.retryDelayMs);
|
||||
// Positive jitter up to +20% while respecting server minimum delay
|
||||
const jitter = currentDelay * 0.2 * Math.random();
|
||||
const delayWithJitter = currentDelay + jitter;
|
||||
debugLogger.warn(
|
||||
`Attempt ${attempt} failed: ${classifiedError.message}. Retrying after ${classifiedError.retryDelayMs}ms...`,
|
||||
`Attempt ${attempt} failed: ${classifiedError.message}. Retrying after ${Math.round(delayWithJitter)}ms...`,
|
||||
);
|
||||
if (onRetry) {
|
||||
onRetry(attempt, error, classifiedError.retryDelayMs);
|
||||
onRetry(attempt, error, delayWithJitter);
|
||||
}
|
||||
await delay(classifiedError.retryDelayMs, signal);
|
||||
await delay(delayWithJitter, signal);
|
||||
currentDelay = Math.min(maxDelayMs, currentDelay * 2);
|
||||
continue;
|
||||
} else {
|
||||
const errorStatus = getErrorStatus(error);
|
||||
|
||||
Reference in New Issue
Block a user