fix: cap API retry exponential backoff at 10 minutes (#5171)

Co-authored-by: Daniel Riccio <ricciodaniel98@gmail.com>
This commit is contained in:
Murilo Pires 2025-06-30 11:56:34 -03:00 committed by GitHub
parent 904e956179
commit b9626a7eff
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -86,6 +86,9 @@ import { ApiMessage } from "../task-persistence/apiMessages"
import { getMessagesSinceLastSummary, summarizeConversation } from "../condense"
import { maybeRemoveImageBlocks } from "../../api/transform/image-cleaning"
// Constants
const MAX_EXPONENTIAL_BACKOFF_SECONDS = 600 // 10 minutes
export type ClineEvents = {
message: [{ action: "created" | "updated"; message: ClineMessage }]
taskStarted: []
@ -1799,7 +1802,10 @@ export class Task extends EventEmitter<ClineEvents> {
}
const baseDelay = requestDelaySeconds || 5
let exponentialDelay = Math.ceil(baseDelay * Math.pow(2, retryAttempt))
let exponentialDelay = Math.min(
Math.ceil(baseDelay * Math.pow(2, retryAttempt)),
MAX_EXPONENTIAL_BACKOFF_SECONDS,
)
// 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) {