Skip to content

Limit WriteAssertions to 100 assertions#619

Merged
rhamzeh merged 5 commits intomainfrom
fix/batch-assertions
Mar 10, 2026
Merged

Limit WriteAssertions to 100 assertions#619
rhamzeh merged 5 commits intomainfrom
fix/batch-assertions

Conversation

@aaguiarz
Copy link
Member

@aaguiarz aaguiarz commented Jan 17, 2026

Description

What problem is being solved?

Fixes #618

How is it being solved?

OpenFGA does not support storing more than 100 assertions.

When trying to import a store with fga store import, if the file has more than 100 assertions, the whole import fails.

What changes are made to solve it?

Only write the first 100 assertions and print a warning.

References

Review Checklist

  • I have clicked on "allow edits by maintainers".
  • I have added documentation for new/changed functionality in this PR or in a PR to openfga.dev [Provide a link to any relevant PRs in the references section above]
  • The correct base branch is being used, if not main
  • I have added tests to validate that the change in functionality is working as expected

Summary by CodeRabbit

  • New Features

    • Assertion imports now process in batches, optimizing handling of large import volumes.
  • Tests

    • Added test coverage for batched assertion imports to ensure correct behavior with large datasets.
  • Refactor

    • Optimized memory allocation and improved code efficiency across import and test utilities.

✏️ Tip: You can customize this high-level summary in your review settings.

@aaguiarz aaguiarz requested a review from a team as a code owner January 17, 2026 01:18
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 17, 2026

Walkthrough

This PR addresses a limitation where importing store files with more than 100 assertions would fail. The changes implement batching of assertion imports in groups of 100, precompute total assertion counts for efficient slice allocation, introduce comprehensive test coverage for batching behavior, and apply performance-oriented slice preallocation optimizations across test utilities.

Changes

Cohort / File(s) Summary
Assertion batching implementation
cmd/store/import.go, cmd/store/import_test.go
Added batching logic in getCheckAssertions to split assertions into groups of maxAssertionsPerWrite (100). Precomputes totalAssertions to preallocate slice capacity. New test TestImportStoreWithBatchedAssertions validates batching with 150 assertions split into two batches. Introduced test constants testModelID and testStoreID, and helper setupBatchedWriteAssertionsMock to configure mock expectations for multiple batched calls. Updated existing tests to use new constants.
Test utility slice preallocation
internal/storetest/localtest.go, internal/storetest/remotetest.go
Replaced empty slice initializations with preallocated slices in RunLocalCheckTest, RunLocalListObjectsTest, RunLocalListUsersTest, RunRemoteCheckTest, RunRemoteListObjectsTest, RunRemoteListUsersTest, and RunRemoteTest. Capacity calculated based on product of input dimensions (e.g., len(users)\*len(objects)\*len(assertions)). No functional logic changes.
String parsing optimization
internal/storetest/testresult.go
Replaced strings.Index and slicing with strings.Cut to locate "# Test Summary #" header in FriendlyBody. Functionally equivalent but more idiomatic.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Suggested labels

codex

Suggested reviewers

  • Siddhant-K-code
  • rhamzeh
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed The PR successfully implements batching of assertions into groups of 100 as required by issue #618, addressing the server validation error for large imports.
Out of Scope Changes check ✅ Passed All changes are directly related to the batching objective: assertion batching logic, supporting test infrastructure, and slice preallocation optimizations for performance.
Title check ✅ Passed The title 'Limit WriteAssertions to 100 assertions' accurately reflects the main change: batching assertions to respect the 100-assertion limit per write operation.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

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

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/batch-assertions

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.

@dosubot
Copy link

dosubot bot commented Jan 17, 2026

Documentation Updates

1 document(s) were updated by changes in this PR:

Contextual Tuples Support
View Changes
@@ -26,6 +26,14 @@
 For ABAC scenarios, an optional `context` object can be included to provide additional attribute data for condition evaluation.
 
 There are limits on the number of contextual tuples: up to 100 per request (as of OpenFGA v1.7.0), and up to 20 per assertion in Write Assertions. Exceeding these limits will result in a request error. [Reference](https://github.com/openfga/openfga/blob/28ed51fb5f6c9e3eb113e15b8b98fb7eb1aa56aa/CHANGELOG.md#L287-L764)
+
+### CLI Import Behavior for Write Assertions
+
+When using the `fga store import` command, there is a limit of 100 assertions per write operation. If you attempt to import a store with more than 100 assertions, the CLI will:
+- Write only the first 100 assertions
+- Display a warning message: `Warning: N test assertions found, but only the first 100 will be written`
+
+This limit is enforced by the CLI tool's import functionality, not by the OpenFGA server API itself. If you need to import more than 100 assertions, you will need to make multiple separate write operations.
 
 ## Specifying Contextual Tuples in Requests
 

How did I do? Any feedback?  Join Discord

Copy link
Member

@rhamzeh rhamzeh left a comment

Choose a reason for hiding this comment

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

This does not work as you'd expect - the API accepts a max of 100 assertions: https://github.com/openfga/api/blob/main/openfga/v1/openfga_service.proto#L1639-L1650

Every following WriteAssertions request will just override what came before it.

Copilot AI review requested due to automatic review settings March 9, 2026 03:35
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Addresses #618 by changing how store import writes test assertions to comply with the API limit of 100 assertions per WriteAssertions request.

Changes:

  • Introduces a maxAssertionsPerWrite limit (100) in the store import flow.
  • Updates assertion import error message text.
  • Adds/updates tests around importing assertions with large volumes.

Reviewed changes

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

File Description
internal/storetest/remotetest.go Minor formatting change (blank line) in remote list-users test helper.
cmd/store/import.go Adds max-assertions limit handling and tweaks error message for assertion import.
cmd/store/import_test.go Refactors IDs into constants and adds a new test for >100 assertions behavior.

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

@aaguiarz aaguiarz changed the title Write assertions in batches Limit WriteAssertions to 100 assertions Mar 10, 2026
@aaguiarz aaguiarz requested a review from rhamzeh March 10, 2026 11:43
@rhamzeh rhamzeh added this pull request to the merge queue Mar 10, 2026
Merged via the queue into main with commit 67afb55 Mar 10, 2026
22 checks passed
@rhamzeh rhamzeh deleted the fix/batch-assertions branch March 10, 2026 13:42
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.

Failure when importing a store file with more than 100 assertions

3 participants