Skip to content

Feat/backoff jitter strategies#666

Merged
Baskarayelu merged 4 commits into
CredenceOrg:mainfrom
shogun444:feat/backoff-jitter-strategies
Jun 29, 2026
Merged

Feat/backoff jitter strategies#666
Baskarayelu merged 4 commits into
CredenceOrg:mainfrom
shogun444:feat/backoff-jitter-strategies

Conversation

@shogun444

Copy link
Copy Markdown
Contributor

Summary

Closes #641

This PR adds configurable jitter strategies to the retry backoff helpers while preserving the existing default behavior. It also introduces deterministic testing via injectable RNGs and property-based tests to verify the mathematical bounds of each strategy.

Changes

  • Added configurable jitter strategies:

    • none
    • full
    • equal
    • decorrelated
  • Extended BackoffOptions with:

    • jitter
    • randomFn (defaults to Math.random)
  • Added state tracking for decorrelated jitter using the previous delay.

  • Extracted backoff delay calculation into a dedicated helper for clarity.

  • Extended RetryJitterStrategy with decorrelated.

  • Added decorrelated jitter support to getBackoffDelayMs() while keeping existing callers backward compatible.

Tests

Added deterministic and property-based tests covering:

  • Full jitter stays within [0, cap]
  • Equal jitter stays within [cap / 2, cap]
  • Decorrelated jitter stays within its expected bounds and respects the configured cap
  • All strategies never exceed the configured maximum delay
  • Default behavior remains unchanged
  • Decorrelated jitter correctly handles the initial delay and subsequent retries

Validation

  • npm run test -- backoff retryPolicy (36/36 passing)
  • npm run build
  • npm run lint

No breaking API changes were introduced. Existing callers continue using the current default (full) jitter strategy.

shogun444 and others added 4 commits June 27, 2026 12:40
feat(metrics): restrict /metrics endpoint to cluster CIDRs
…nds tests

Extends utils/backoff.ts with an injectable RNG and configurable
JitterStrategy ('none' | 'full' | 'equal' | 'decorrelated').
Adds decorrelated jitter to retryPolicy.ts RetryJitterStrategy.
Adds fast-check property tests proving each strategy stays within
its theoretical bounds.

Default behavior is unchanged (full jitter in backoff.ts).
No breaking changes to retryPolicy.ts callers.
@drips-wave

drips-wave Bot commented Jun 29, 2026

Copy link
Copy Markdown

@shogun444 Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

@Baskarayelu Baskarayelu merged commit ef45d9c into CredenceOrg:main Jun 29, 2026
0 of 2 checks passed
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.

Add a configurable jitter strategy and tests to the retry backoff helper in utils/backoff.ts

2 participants