Skip to content

fix: correctly set default retry params#394

Merged
SoulPancake merged 2 commits into
openfga:mainfrom
kamilogorek:default-retry-params
May 4, 2026
Merged

fix: correctly set default retry params#394
SoulPancake merged 2 commits into
openfga:mainfrom
kamilogorek:default-retry-params

Conversation

@kamilogorek

@kamilogorek kamilogorek commented May 2, 2026

Copy link
Copy Markdown
Contributor

The OpenFgaClient will by default retry API requests up to 3 times on 429 and 5xx errors.

Well, it won't as of today 😅

This has been never caught because you always override retryParams for every test client.
Also "429 with retry in config and retry is successful" test was broken, because nock body matcher was incorrect, so it was skipped, making 200 response always evaluate first, skipping a retry entirely.

Summary by CodeRabbit

  • Bug Fixes
    • Fixed retry parameter initialization to ensure default values are applied when not explicitly configured, improving SDK robustness during transient failures.
    • Enhanced HTTP 429 rate-limit error handling to properly retry requests and achieve successful responses with default retry configuration.

Copilot AI review requested due to automatic review settings May 2, 2026 20:50
@kamilogorek kamilogorek requested a review from a team as a code owner May 2, 2026 20:50
@coderabbitai

coderabbitai Bot commented May 2, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto incremental reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 86966e63-de8d-4aaa-b9dd-b43b97f130f9

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Walkthrough

The SDK's Configuration constructor now initializes retryParams by merging user-provided values onto defaults from GetDefaultRetryParams(), ensuring retry behavior always has sensible defaults. Tests validate that HTTP 429 responses succeed with both default and custom retry configurations.

Changes

Default Retry Configuration

Layer / File(s) Summary
Core Initialization
configuration.ts
this.retryParams is now assigned via Object.assign(GetDefaultRetryParams(), params.retryParams) so defaults apply when user-provided values are omitted.
Tests
tests/index.test.ts
New test case verifies 429 retry succeeds with default configuration; existing 429 retry test is updated to include authorization_model_id in the mocked check request for consistency.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'fix: correctly set default retry params' directly and clearly summarizes the main change—correcting the initialization of default retry parameters in the Configuration class.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Tip

💬 Introducing Slack Agent: The best way for teams to turn conversations into code.

Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.

  • Generate code and open pull requests
  • Plan features and break down work
  • Investigate incidents and troubleshoot customer tickets together
  • Automate recurring tasks and respond to alerts with triggers
  • Summarize progress and report instantly

Built for teams:

  • Shared memory across your entire org—no repeating context
  • Per-thread sandboxes to safely plan and execute work
  • Governance built-in—scoped access, auditability, and budget controls

One agent for your entire SDLC. Right inside Slack.

👉 Get your free trial and get 200 agent minutes per Slack user (a $50 value).


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

Comment @coderabbitai help to get the list of available commands and usage tips.

Copilot AI 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.

Pull request overview

This PR fixes the SDK’s default retry behavior so that retryParams are correctly initialized even when not explicitly provided, and updates tests to cover the default-retry scenario and correct a previously-broken 429 retry test matcher.

Changes:

  • Initialize Configuration.retryParams by merging GetDefaultRetryParams() with user-provided overrides.
  • Add a new test case validating that a 429 followed by success is retried when using default retry configuration.
  • Fix the 429 retry test’s nock request body matcher to include authorization_model_id.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
configuration.ts Ensures default retry parameters are applied when retryParams are omitted.
tests/index.test.ts Adds/adjusts 429 retry tests to validate default retry behavior and correct request matching.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread tests/index.test.ts Outdated
Comment thread tests/index.test.ts
Comment thread tests/index.test.ts
@kamilogorek kamilogorek force-pushed the default-retry-params branch from e9cd6fa to 6b08e4a Compare May 2, 2026 21:04

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

Thanks a lot @kamilogorek !

@SoulPancake SoulPancake changed the title fix: Correctly set default retry params fix: correctly set default retry params May 3, 2026

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

@kamilogorek

One small follow-up: this exposes a failure in tests/client.test.ts › ListRelations › should throw an error if any check returns an error. With retries now actually applied, scope3 mocks the 500 only once, the SDK retries, and the retry has no interceptor,,so the error goes through the network-error branch in common.ts and gets wrapped as a plain FgaError instead of FgaApiError.

Two small asks:
Mock the 500 DefaultMaxRetry + 1 times in that test. That way the test exercises the actual production path (transient 5xx → retried → exhausted → FgaApiInternalError)

Move nock.disableNetConnect() from client.test.ts into tests/setup.ts so that unmatched requests fail everywhere

Happy to push onto your branch if easier.
Thanks again

@kamilogorek

Copy link
Copy Markdown
Contributor Author

No worries, I missed to run tests after follow-up change, my bad.
There's few more things that could be improved in the test suites overall, but I will send them in a separate PR to not pollute this one with unrelated changes.

@kamilogorek

Copy link
Copy Markdown
Contributor Author

Follow-up cleanup PR #395

@SoulPancake

Copy link
Copy Markdown
Member

Thanks a lot

@SoulPancake SoulPancake added this pull request to the merge queue May 4, 2026
@codecov-commenter

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 85.59%. Comparing base (286f8fd) to head (6836c03).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #394      +/-   ##
==========================================
- Coverage   85.82%   85.59%   -0.24%     
==========================================
  Files          26       26              
  Lines        1270     1270              
  Branches      250      226      -24     
==========================================
- Hits         1090     1087       -3     
  Misses        110      110              
- Partials       70       73       +3     

☔ View full report in Codecov by Sentry.
📢 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.

Merged via the queue into openfga:main with commit 6b03882 May 4, 2026
15 checks passed
@kamilogorek kamilogorek deleted the default-retry-params branch May 4, 2026 09:09
@kamilogorek

Copy link
Copy Markdown
Contributor Author

Anytime. #395 has also been rebased and tests are all green locally 🫡

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.

4 participants