From 2c5f95616242cb8a52e354477650b904edbee733 Mon Sep 17 00:00:00 2001 From: Matt Rubens Date: Sun, 30 Mar 2025 13:39:59 -0400 Subject: [PATCH] Parse the retry out of the gemini 429 response (#2118) --- src/core/Cline.ts | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/core/Cline.ts b/src/core/Cline.ts index 27f8e62356..294c423c87 100644 --- a/src/core/Cline.ts +++ b/src/core/Cline.ts @@ -1230,7 +1230,21 @@ export class Cline extends EventEmitter { } const baseDelay = requestDelaySeconds || 5 - const exponentialDelay = Math.ceil(baseDelay * Math.pow(2, retryAttempt)) + let exponentialDelay = Math.ceil(baseDelay * Math.pow(2, retryAttempt)) + + // If the error is a 429, and the error details contain a retry delay, use that delay instead of exponential backoff + if (error.status === 429) { + const geminiRetryDetails = error.errorDetails?.find( + (detail: any) => detail["@type"] === "type.googleapis.com/google.rpc.RetryInfo", + ) + if (geminiRetryDetails) { + const match = geminiRetryDetails?.retryDelay?.match(/^(\d+)s$/) + if (match) { + exponentialDelay = Number(match[1]) + 1 + } + } + } + // Wait for the greater of the exponential delay or the rate limit delay const finalDelay = Math.max(exponentialDelay, rateLimitDelay)