feature: Exponential Backoff And Jitter by ysknsid25 · Pull Request #582 · unjs/ofetch · GitHub
Skip to content

feature: Exponential Backoff And Jitter#582

Open
ysknsid25 wants to merge 1 commit into
unjs:mainfrom
ysknsid25:feature/backoff-and-jitter
Open

feature: Exponential Backoff And Jitter#582
ysknsid25 wants to merge 1 commit into
unjs:mainfrom
ysknsid25:feature/backoff-and-jitter

Conversation

@ysknsid25

@ysknsid25 ysknsid25 commented May 16, 2026

Copy link
Copy Markdown
Contributor

resolves: #581

Summary by CodeRabbit

  • New Features

    • Added exponential backoff with jitter for retries with three configurable strategies (full-jitter, equal-jitter, decorrelated-jitter)
    • Retry attempt counter now accessible in request context
    • retryBackoff configuration takes precedence over retryDelay for advanced retry control
  • Documentation

    • Updated retry documentation with exponential backoff configuration guide and jitter strategy details

Review Change Stack

Signed-off-by: ysknsid25 <kengo071225@gmail.com>
@coderabbitai

coderabbitai Bot commented May 16, 2026

Copy link
Copy Markdown

@codecov

codecov Bot commented May 16, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 86.66%. Comparing base (27996d3) to head (0b15f3e).
⚠️ Report is 103 commits behind head on main.

Additional details and impacted files
@@             Coverage Diff             @@
##             main     #582       +/-   ##
===========================================
+ Coverage   56.86%   86.66%   +29.79%     
===========================================
  Files          16        6       -10     
  Lines         728      285      -443     
  Branches      113      140       +27     
===========================================
- Hits          414      247      -167     
+ Misses        303       33      -270     
+ Partials       11        5        -6     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/retry.ts`:
- Around line 11-14: The JSDoc for the `base` field is misleading: update the
comment for `base` (in src/retry.ts) to explain it is the base/backoff factor
used to compute retry delays rather than a guaranteed minimum delay — explicitly
state that for jitter strategies like `full-jitter` and `equal-jitter` computed
delays can be below `base` (even 0); keep `cap` description as the upper bound.
Mention the relevant symbols `base`, `cap`, and the jitter strategies
(`full-jitter`, `equal-jitter`) so readers understand the semantics.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 19017108-30b1-49e8-bbb6-ac238b81518b

📥 Commits

Reviewing files that changed from the base of the PR and between dfbe3ca and 0b15f3e.

📒 Files selected for processing (6)
  • README.md
  • src/fetch.ts
  • src/retry.ts
  • src/types.ts
  • test/index.test.ts
  • test/retry.test.ts

Comment thread src/retry.ts
Comment on lines +11 to +14
/** Minimum delay in milliseconds. */
base: number;
/** Maximum delay in milliseconds. */
cap: number;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Clarify base semantics in API docs.

base is not a strict minimum delay for full-jitter and equal-jitter (those can go below base, including 0). Please reword this to avoid misleading users.

Suggested wording
-  /** Minimum delay in milliseconds. */
+  /** Base delay in milliseconds used by backoff calculations. */
   base: number;
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/retry.ts` around lines 11 - 14, The JSDoc for the `base` field is
misleading: update the comment for `base` (in src/retry.ts) to explain it is the
base/backoff factor used to compute retry delays rather than a guaranteed
minimum delay — explicitly state that for jitter strategies like `full-jitter`
and `equal-jitter` computed delays can be below `base` (even 0); keep `cap`
description as the upper bound. Mention the relevant symbols `base`, `cap`, and
the jitter strategies (`full-jitter`, `equal-jitter`) so readers understand the
semantics.

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.

Exponential backoff with jitter for retries

1 participant