Skip to content

fix(appkit): add jitter to RetryInterceptor exponential backoff#269

Merged
MarioCadenas merged 2 commits intomainfrom
fix/no-jitter-in-retry-backoff
Apr 13, 2026
Merged

fix(appkit): add jitter to RetryInterceptor exponential backoff#269
MarioCadenas merged 2 commits intomainfrom
fix/no-jitter-in-retry-backoff

Conversation

@MarioCadenas
Copy link
Copy Markdown
Collaborator

@MarioCadenas MarioCadenas commented Apr 13, 2026

Summary

The RetryInterceptor used pure exponential backoff (initialDelay * 2^attempt), causing all concurrent retries after a simultaneous failure to fire at identical intervals — a thundering herd problem. This PR adds full jitter by default: each retry delay is randomized between 50% and 100% of the computed backoff value, spreading retries over time.

Changes

  • Added jitter?: boolean field to RetryConfig (defaults to true)
  • Updated RetryInterceptor.calculateDelay() to apply random jitter: capped * (0.5 + Math.random() * 0.5)
  • Existing tests updated to set jitter: false where exact timing is asserted
  • New tests: jitter enabled by default, boundary behavior at Math.random() = 0 (50%) and Math.random() = 1 (100%)

Test plan

  • Existing tests pass (backoff + maxDelay tests now use jitter: false)
  • New tests cover jitter default-on, boundary values, and opt-out
  • Manual verification: jitter: false produces deterministic delays identical to prior behavior

RetryInterceptor used pure exponential backoff (initialDelay * 2^attempt),
causing all concurrent retries to fire at identical intervals after a
simultaneous failure (thundering herd). Now applies full jitter by default:
delay * (0.5 + Math.random() * 0.5), producing random delays between 50%
and 100% of the base delay. Opt out with retry.jitter = false.

Signed-off-by: MarioCadenas <MarioCadenas@users.noreply.github.com>
Copy link
Copy Markdown
Contributor

@ditadi ditadi left a comment

Choose a reason for hiding this comment

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

Sounds good, I just added two points.

Address PR review feedback:
- Use true full jitter (capped * Math.random()) giving range [0, capped]
  instead of half jitter (50%-100%)
- Remove jitter boolean flag — jitter is always applied since it is
  strictly better for production retry behavior

Signed-off-by: MarioCadenas <MarioCadenas@users.noreply.github.com>
@MarioCadenas MarioCadenas enabled auto-merge (squash) April 13, 2026 11:01
@MarioCadenas
Copy link
Copy Markdown
Collaborator Author

Sounds good, I just added two points.

addressed, thank you!

@MarioCadenas MarioCadenas merged commit bdf2ea3 into main Apr 13, 2026
7 checks passed
@MarioCadenas MarioCadenas deleted the fix/no-jitter-in-retry-backoff branch April 13, 2026 11:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants