Skip to content

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

Open
cvas22 wants to merge 1 commit into
openfga:mainfrom
cvas22:fix/zero-min-wait
Open

cvas22 wants to merge 1 commit into
openfga:mainfrom
cvas22:fix/zero-min-wait

Conversation

@cvas22

@cvas22 cvas22 commented Nov 5, 2026

Copy link
Copy Markdown

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

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 59 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: c198f0a0-c3f5-4a33-8173-bbd86c25e516
Commits

Reviewing files that changed from the base of the PR and between c5d3305 and 56c96eb.

Files selected for processing: 4

  • openfga_sdk/api_client.py
  • openfga_sdk/oauth2_common.py
  • openfga_sdk/sync/api_client.py
  • test/backoff_test.py
  • 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

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