Skip to content

fix: add max delay to retries#42

Merged
pedrocrvz merged 1 commit into
masterfrom
fix/max-backoff-on-retries
Feb 17, 2026
Merged

fix: add max delay to retries#42
pedrocrvz merged 1 commit into
masterfrom
fix/max-backoff-on-retries

Conversation

@pedrocrvz

Copy link
Copy Markdown
Contributor

No description provided.

@gemini-code-assist

Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @pedrocrvz, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request enhances the retry mechanism by introducing a maxDelay option. This new parameter allows for better control over exponential backoff, ensuring that retry delays do not exceed a specified maximum. This change improves the robustness and predictability of retry operations, particularly in scenarios where unbounded exponential delays could be problematic.

Highlights

  • New Feature: Max Delay for Retries: Introduced a maxDelay option to the withRetries utility, allowing users to cap the maximum wait time between retries, especially useful for exponential backoff strategies.
  • Improved Retry Logic: The exponential backoff mechanism now respects the maxDelay setting, preventing retry delays from growing indefinitely and ensuring more predictable retry behavior.
  • Documentation and Testing: Updated relevant README.md files to reflect the new maxDelay option and added a dedicated test case to withRetries.test.ts to verify its functionality.
Changelog
  • .changeset/every-ducks-yell.md
    • Added a new changeset file for the patch release.
  • README.md
    • Updated the max retry option description to reflect a 0-5 range.
    • Clarified delay as 'Base delay' in the retry options table.
    • Added the new maxDelay option to the retry configuration documentation.
  • src/README.md
    • Added the new maxDelay option to the retry configuration documentation.
  • src/utils/withRetries.test.ts
    • Added a new test case to verify that maxDelay correctly caps exponential backoff.
  • src/utils/withRetries.ts
    • Introduced the maxDelay property to the WithRetriesOptions interface.
    • Implemented logic within the withRetries function to cap exponential backoff delay using the maxDelay value.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@pedrocrvz
pedrocrvz merged commit 636db74 into master Feb 17, 2026
2 checks passed
@pedrocrvz
pedrocrvz deleted the fix/max-backoff-on-retries branch February 17, 2026 17:09

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a maxDelay option to cap the exponential backoff delay in the retry mechanism, which is a useful addition for controlling retry behavior. However, a potential Denial of Service vulnerability has been identified because the maxDelay cap is not applied to the 'fixed' backoff strategy. It is recommended to apply maxDelay to all backoff strategies to enhance robustness. Additionally, there's an inconsistency in the default value for maxDelay between the implementation and the documentation that needs to be aligned.

Comment thread src/utils/withRetries.ts
const code = (error as { code?: number }).code;
if (attempt < max && code !== undefined && errorCodes.includes(code)) {
const wait = backoff === 'exponential' ? delay * 2 ** attempt : delay;
const wait = backoff === 'exponential' ? Math.min(delay * 2 ** attempt, maxDelay) : delay;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

security-medium medium

The maxDelay parameter caps the retry delay for the 'exponential' backoff strategy, but it is not applied when the backoff strategy is 'fixed'. If a user can control the delay option, they could provide a very large value, causing the function to wait for an extended period. This can lead to resource exhaustion and a potential Denial of Service (DoS) vulnerability. The maxDelay cap should be applied to all backoff strategies.

Suggested change
const wait = backoff === 'exponential' ? Math.min(delay * 2 ** attempt, maxDelay) : delay;
const wait = Math.min(backoff === 'exponential' ? delay * 2 ** attempt : delay, maxDelay);

Comment thread src/utils/withRetries.ts
const errorCodes = options?.errorCodes ?? [SimulationFailedRpcError.code];
const delay = options?.delay ?? 200;
const backoff = options?.backoff ?? 'exponential';
const maxDelay = options?.maxDelay ?? 12_000;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

There's an inconsistency in the default value for maxDelay. The implementation uses 12_000, but the JSDoc for the WithRetriesOptions interface (line 15) and the documentation in README.md and src/README.md all state the default is 10000. To ensure consistency between the code and its documentation, please update the default value here to match what's documented.

Suggested change
const maxDelay = options?.maxDelay ?? 12_000;
const maxDelay = options?.maxDelay ?? 10_000;

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.

1 participant