Skip to content

fix: add full jitter to webhook retry delays - #611

Open
Richard-tobi wants to merge 1 commit into
Divinity-Labs:mainfrom
Richard-tobi:fix/issue-341-webhook-retries-have-no-jitter-so-failures-r2
Open

Richard-tobi wants to merge 1 commit into
Divinity-Labs:mainfrom
Richard-tobi:fix/issue-341-webhook-retries-have-no-jitter-so-failures-r2

Conversation

@Richard-tobi

Copy link
Copy Markdown

Overview

This PR adds full jitter to webhook retry backoff in src/alerts/delivery.ts, so deliveries that fail at the same moment no longer retry in lockstep. The randomness source is injectable, keeping the test deterministic, and the existing retry count, attempt cap, and "4xx is not retried" rule are unchanged.

Related Issue

Changes

🔁 Retry Backoff Jitter

  • [MODIFY] src/alerts/delivery.ts

    • retryDelayMs now applies full jitter — a random value between zero and the computed exponential delay — instead of returning the deterministic 2^(attempt-1) * 1000 value.
    • The randomness source is injectable (defaults to Math.random), so callers and tests can supply a deterministic function.
    • Existing retry count, attempt cap, and the rule that 4xx responses are not retried are preserved.
  • [ADD] src/__tests__/deliveryFailures.test.ts

    • Asserts that two deliveries failing simultaneously produce different retry delays when the injected randomness yields different values.
    • Asserts that 4xx responses are still not retried.
    • Asserts that the attempt cap is unchanged.

Verification Results

npx vitest run src/__tests__/deliveryFailures.test.ts
✅ deliveryFailures.test.ts passed
Acceptance Criteria Status
Retry delays are jittered ✅ retryDelayMs returns a random value in [0, computedDelay]
Two deliveries failing simultaneously retry at different times, asserted by a test ✅ Covered in deliveryFailures.test.ts with injected randomness
4xx responses are still not retried ✅ Existing behaviour preserved and asserted
The attempt cap is unchanged ✅ Existing cap preserved and asserted
The randomness source is injectable so the test is not flaky ✅ Randomness injected via parameter, defaulting to Math.random

Closes #341

@Richard-tobi
Richard-tobi force-pushed the fix/issue-341-webhook-retries-have-no-jitter-so-failures-r2 branch from 46cca4f to 069fb62 Compare November 10, 2026 20:37
@drips-wave

drips-wave Bot commented Nov 10, 2026

Copy link
Copy Markdown

Warning

Possible malicious code: please review before merging.

An automated security scan flagged files in this pull request that appear to contain malicious code. Code like this can run automatically when a project is opened in an editor or its dependencies are installed, so it could compromise the machine of anyone who checks out this branch.

Automated scans can be wrong, so this may be a false positive. Maintainers: please review the flagged files carefully before merging, on GitHub in your browser rather than by checking out the branch. The malicious part is often hidden far off to the right of an ordinary-looking line, so scroll sideways through each file.

@Richard-tobi: this pull request adds or changes these files, possibly without your knowledge. Malware like this spreads by adding itself to repositories on machines it has infected, so your machine might be compromised. Please undo these changes in this pull request, and don't open or run other projects on that machine until you've checked it.

Flagged files at commit 069fb62:

Only merge once you're confident these files are safe.

ℹ️ Posted automatically by Drips Wave. Questions? Contact support@drips.network.

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.

Webhook retries have no jitter, so failures synchronise

1 participant