fix: guard retry fields against Infinity/NaN
Use Number.isFinite() to sanitize maxRetries, retryDelayMs, and retryBackoff before entering the retry loop. Prevents unbounded retries from Infinity or broken loop bounds from NaN.
This commit is contained in:
parent
42f3717115
commit
d9b20c0cf6
|
|
@ -128,9 +128,10 @@ export async function executeWithRetry(
|
||||||
onRetry?: (data: { attempt: number; maxAttempts: number; error: string; nextDelayMs: number }) => void,
|
onRetry?: (data: { attempt: number; maxAttempts: number; error: string; nextDelayMs: number }) => void,
|
||||||
delayFn: (ms: number) => Promise<void> = sleep,
|
delayFn: (ms: number) => Promise<void> = sleep,
|
||||||
): Promise<AgentRunResult> {
|
): Promise<AgentRunResult> {
|
||||||
const maxAttempts = Math.max(0, task.maxRetries ?? 0) + 1
|
const rawRetries = Number.isFinite(task.maxRetries) ? task.maxRetries! : 0
|
||||||
const baseDelay = Math.max(0, task.retryDelayMs ?? 1000)
|
const maxAttempts = Math.max(0, rawRetries) + 1
|
||||||
const backoff = Math.max(1, task.retryBackoff ?? 2)
|
const baseDelay = Math.max(0, Number.isFinite(task.retryDelayMs) ? task.retryDelayMs! : 1000)
|
||||||
|
const backoff = Math.max(1, Number.isFinite(task.retryBackoff) ? task.retryBackoff! : 2)
|
||||||
|
|
||||||
let lastError: string = ''
|
let lastError: string = ''
|
||||||
// Accumulate token usage across all attempts so billing/observability
|
// Accumulate token usage across all attempts so billing/observability
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue