Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion src/core/Cline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1221,7 +1221,21 @@ export class Cline extends EventEmitter<ClineEvents> {
}

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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For improved clarity and testability, consider extracting the gemini 429 retry delay parsing logic into a helper function. This would isolate the parsing logic and allow for dedicated unit tests.

if (error.status === 429) {
const geminiRetryDetails = error.errorDetails?.find(
(detail: any) => detail["@type"] === "type.googleapis.com/google.rpc.RetryInfo",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of using any for the details in the gemini retry info, consider defining a proper interface. This promotes type safety and makes the code easier to maintain.

)
if (geminiRetryDetails) {
const match = geminiRetryDetails?.retryDelay?.match(/^(\d+)s$/)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider refining the regex to capture fractional seconds too (e.g. /^(\\d+(?:\\.\\d+)?)s$/). Currently it only matches integer seconds and might miss delays like '1.5s'.

Suggested change
const match = geminiRetryDetails?.retryDelay?.match(/^(\d+)s$/)
const match = geminiRetryDetails?.retryDelay?.match(/^(\d+(?:\.\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)

Expand Down