-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Parse the retry out of the gemini 429 response #2118
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -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 | ||||||
| if (error.status === 429) { | ||||||
| const geminiRetryDetails = error.errorDetails?.find( | ||||||
| (detail: any) => detail["@type"] === "type.googleapis.com/google.rpc.RetryInfo", | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instead of using |
||||||
| ) | ||||||
| if (geminiRetryDetails) { | ||||||
| const match = geminiRetryDetails?.retryDelay?.match(/^(\d+)s$/) | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider refining the regex to capture fractional seconds too (e.g.
Suggested change
|
||||||
| 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) | ||||||
|
|
||||||
|
|
||||||
There was a problem hiding this comment.
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.