Skip to content

Commit 46623e5

Browse files
committed
Parse the retry out of the gemini 429 response
1 parent 592494f commit 46623e5

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

src/core/Cline.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1221,7 +1221,21 @@ export class Cline extends EventEmitter<ClineEvents> {
12211221
}
12221222

12231223
const baseDelay = requestDelaySeconds || 5
1224-
const exponentialDelay = Math.ceil(baseDelay * Math.pow(2, retryAttempt))
1224+
let exponentialDelay = Math.ceil(baseDelay * Math.pow(2, retryAttempt))
1225+
1226+
// If the error is a 429, and the error details contain a retry delay, use that delay instead of exponential backoff
1227+
if (error.status === 429) {
1228+
const geminiRetryDetails = error.errorDetails?.find(
1229+
(detail: any) => detail["@type"] === "type.googleapis.com/google.rpc.RetryInfo",
1230+
)
1231+
if (geminiRetryDetails) {
1232+
const match = geminiRetryDetails?.retryDelay?.match(/^(\d+)s$/)
1233+
if (match) {
1234+
exponentialDelay = Number(match[1]) + 1
1235+
}
1236+
}
1237+
}
1238+
12251239
// Wait for the greater of the exponential delay or the rate limit delay
12261240
const finalDelay = Math.max(exponentialDelay, rateLimitDelay)
12271241

0 commit comments

Comments
 (0)