Skip to content
Prev Previous commit
fix(executor): clamp jitter within maxDelayMs to honour delay cap
  • Loading branch information
Rabba-Meghana committed Mar 25, 2026
commit d6e45a2b4796ae4b54893741d5b77354f28b7326
2 changes: 1 addition & 1 deletion apps/sim/executor/utils/retry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ function calculateBackoffDelay(attempt: number, initialDelayMs: number, maxDelay
const exponential = initialDelayMs * Math.pow(2, attempt)
const capped = Math.min(maxDelayMs, exponential)
const jitter = Math.random() * capped * 0.2
return Math.floor(capped + jitter)
return Math.floor(Math.min(capped + jitter, maxDelayMs))
}
Comment thread
cursor[bot] marked this conversation as resolved.
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Jitter eliminated when backoff delay reaches max cap

Low Severity

In calculateBackoffDelay, capped is already clamped to maxDelayMs, but then jitter is added to capped and the result is clamped again by Math.min(..., maxDelayMs). When exponential >= maxDelayMs, the jitter is always clamped back to zero, producing a deterministic maxDelayMs with no randomization. This defeats the purpose of jitter (preventing thundering herd) once the exponential component reaches the cap. The jitter needs to be subtracted from (or applied within) capped rather than added on top of it.

Fix in Cursor Fix in Web

function parseRetryAfterHeader(headers: Headers): number | null {
Expand Down