Skip to content

fix(fga): raise engine list caps so list_permissions reports truncation - #903

Merged
lakhansamani merged 2 commits into
mainfrom
fix/fga-list-engine-cap
Nov 19, 2026
Merged

lakhansamani merged 2 commits into
mainfrom
fix/fga-list-engine-cap

Conversation

@lakhansamani

@lakhansamani lakhansamani commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Problem

The embedded OpenFGA server is built without WithListObjectsMaxResults / WithListUsersMaxResults, so OpenFGA v1.22.1's DefaultListObjectsMaxResults / DefaultListUsersMaxResults (both 1000) apply per call. That equals service.maxFgaListResults (1000).

A single (type, relation) pair with, say, 5,000 matches came back from the engine as exactly 1000. ListPermissions appended all 1000, never saw a 1001st, and returned truncated: false, so results were dropped with no signal to the caller.

Fix

internal/authorization/engine/openfga/openfga.go: configure the server with WithListObjectsMaxResults(maxListResults) and WithListUsersMaxResults(maxListResults), where maxListResults = 1001 (service cap + 1). The service-side cap is now the one that applies, so truncated is set correctly. Kept as a literal like maxBatchCheckSize, so the engine doesn't import service; a comment documents the coupling.

Delegated callers (second commit)

For an RFC 8693 delegated caller, ListPermissions enumerates the agent and the user separately and intersects the results. Each per-subject slice is capped by the engine before the intersection, and OpenFGA returns objects unordered, so two capped slices of large sets overlap far less than the true intersection. The folded result could fall under the cap and be reported as truncated: false while most reachable objects were dropped. This was already the case before this PR.

internal/service/list_permissions.go: mark the response truncated when any raw per-subject slice exceeds maxFgaListResults (meaning the engine hit its maxFgaListResults + 1 cap), before intersecting. Aggregation still stops at the service cap.

Tests

  • TestOpenFGAEngine_ListAboveServiceCap: 1,050 grants; ListObjects and ListUsers must each return 1001 (both returned 1000 before).
  • TestFGAListPermissionsTruncated: end-to-end list_permissions with 1,050 grants on one pair → 1000 permissions, truncated: true. Verified failing without the fix.
  • TestAgentIntersectionListPermissionsTruncated: delegated token; user grants on document:0..2999, agent on document:1000..3999 (true intersection 2000). truncated must be true. Failed 3/3 runs before the second commit.

go build ./..., go vet ./..., make test, make lint-go pass locally.

Not covered (follow-ups)

  • No pagination upstream: OpenFGA v1.22.1 (latest) has no continuation token on ListObjects/ListUsers, and maintainers have said paging is not planned (openfga#2828). A truncated response is an arbitrary 1000 objects, not the first 1000.

  • Deadline truncation: DefaultListObjectsDeadline (3s) returns partial results with no error, so truncated can still be a false negative on slow queries.

  • _fga_list_users: its 1000 cap now actually applies, but the response has no truncated field, so callers can't detect truncation (needs a GraphQL + proto schema change).

The embedded OpenFGA server was built without WithListObjectsMaxResults /
WithListUsersMaxResults, so OpenFGA v1.22.1's defaults (1000) applied per
call. That equals service.maxFgaListResults, so a single (type, relation)
pair with more than 1000 matches came back as exactly 1000 and the service
never saw a 1001st result: list_permissions returned truncated=false while
silently dropping results.

Set both engine caps to maxListResults = 1001 (service cap + 1) so the
service-side cap is the one that bites and truncated is reported.

Regression tests: engine-level ListObjects/ListUsers above the cap, and an
integration test asserting list_permissions returns 1000 with
truncated=true for 1050 grants (fails without the fix).
For a delegated caller, list_permissions enumerates each subject
(agent and user) separately and intersects the results. Each
per-subject slice is capped by the engine before the intersection,
and OpenFGA returns objects unordered, so two capped slices of large
sets overlap far less than the true intersection. The folded result
could fall under the service cap and be reported as truncated=false
while most reachable objects were dropped.

Mark the response truncated when any raw per-subject slice exceeds
maxFgaListResults (i.e. the engine hit its maxFgaListResults+1 cap),
before intersecting. Aggregation still stops at the service cap.

Regression test: user grants on 3000 documents, agent on 3000 with a
2000-document overlap; truncated must be true (failed 3/3 before).
@lakhansamani
lakhansamani merged commit 0a05418 into main Nov 19, 2026
4 checks passed
@lakhansamani
lakhansamani deleted the fix/fga-list-engine-cap branch November 19, 2026 10:46
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