Skip to content

fix: allow a minimum retry wait of 0 ms - #332

Merged
SoulPancake merged 2 commits into
openfga:mainfrom
cvas22:fix/zero-min-wait
Nov 25, 2026
Merged

SoulPancake merged 2 commits into
openfga:mainfrom
cvas22:fix/zero-min-wait

Conversation

@cvas22

@cvas22 cvas22 commented Nov 5, 2026

Copy link
Copy Markdown
Contributor

Description

With retry_params.min_wait_in_ms = 0, the first retry crashes:

ValueError: empty range in randrange(0, 0)

random_time() (in api_client.py and sync/api_client.py) and jitter() (in oauth2_common.py) compute the wait as random.randrange(minimum, maximum) with bounds of 2**n * min_wait_in_ms and 2**(n+1) * min_wait_in_ms. When min_wait_in_ms is 0, both bounds are 0 and randrange raises. So a configuration asking to retry without waiting fails with an unrelated error instead. I hit this while writing the tests for #331.

Change: when the range is empty, the helpers return the minimum (0 s here) instead of calling randrange. Nothing changes for a positive min_wait_in_ms.

Testing

New test/backoff_test.py:

  • random_time (async and sync) and jitter return 0 with a minimum wait of 0. These fail on main with the error above.
  • random_time stays within [2**n * min, 2**(n+1) * min) for a positive minimum.

pytest test passes locally: 529 passed, 12 skipped. ruff check is clean on the new test file.

random_time() and jitter() pick the wait with random.randrange(minimum,
maximum), which raises ValueError on an empty range. With
min_wait_in_ms set to 0 both bounds are 0, so the first retry crashed
instead of retrying immediately. Return the minimum when the range is
empty.

Signed-off-by: Srinivas Chippagiri <cvas22@gmail.com>
@cvas22
cvas22 requested a review from a team as a code owner November 5, 2026 10:04
@coderabbitai

coderabbitai Bot commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

Caution

Review failed

The pull request is closed.

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@cvas22

cvas22 commented Nov 20, 2026

Copy link
Copy Markdown
Contributor Author

@SoulPancake could you take a look when you have a moment? thx

@codecov-commenter

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 70.00%. Comparing base (c5d3305) to head (56c96eb).
⚠️ Report is 4 commits behind head on main.

❌ Your project status has failed because the head coverage (70.00%) is below the target coverage (80.00%). You can increase the head coverage or adjust the target coverage.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #332      +/-   ##
==========================================
+ Coverage   69.99%   70.00%   +0.01%     
==========================================
  Files         142      142              
  Lines       10774    10780       +6     
==========================================
+ Hits         7541     7547       +6     
  Misses       3233     3233              

☔ 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.

@SoulPancake SoulPancake left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thank you @cvas22
LGTM

@SoulPancake
SoulPancake added this pull request to the merge queue Nov 25, 2026
Merged via the queue into openfga:main with commit 1e99d08 Nov 25, 2026
5 of 8 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.

3 participants