set cap for max time to wait between retries (#4135)

Co-authored-by: GitHub Action <action@github.com>
This commit is contained in:
Aiden Cline
2025-11-09 09:46:58 -08:00
committed by GitHub
parent d9ffe07391
commit f7cc46cd9f
4 changed files with 201 additions and 38 deletions

View File

@@ -267,15 +267,24 @@ export namespace SessionCompaction {
max: maxRetries,
})
if (result.shouldRetry) {
const start = Date.now()
for (let retry = 1; retry < maxRetries; retry++) {
const lastRetryPart = result.parts.findLast((p): p is MessageV2.RetryPart => p.type === "retry")
if (lastRetryPart) {
const delayMs = SessionRetry.getRetryDelayInMs(lastRetryPart.error, retry)
const delayMs = SessionRetry.getBoundedDelay({
error: lastRetryPart.error,
attempt: retry,
startTime: start,
})
if (!delayMs) {
break
}
log.info("retrying with backoff", {
attempt: retry,
delayMs,
elapsed: Date.now() - start,
})
const stop = await SessionRetry.sleep(delayMs, signal)