Skip to content

feat: report serialized model size in fga model get and validate#712

Merged
rhamzeh merged 3 commits into
mainfrom
feat/model-size-field
Jun 18, 2026
Merged

feat: report serialized model size in fga model get and validate#712
rhamzeh merged 3 commits into
mainfrom
feat/model-size-field

Conversation

@rhamzeh

@rhamzeh rhamzeh commented Jun 18, 2026

Copy link
Copy Markdown
Member

Description

What problem is being solved?

How is it being solved?

What changes are made to solve it?

We added size_kb to the output of fga model get and fga model validate

References

closes #711

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

    • Added size field option to the fga model get command for retrieving model size in kilobytes.
    • Model validation now includes model size (in KB) in the response.
  • Documentation

    • Updated documentation for fga model get command to show the new size field option and sample responses.
    • Updated documentation for fga model validate command to include size information in response examples.

Copilot AI review requested due to automatic review settings June 18, 2026 00:10
@rhamzeh rhamzeh requested review from a team as code owners June 18, 2026 00:10
@coderabbitai

coderabbitai Bot commented Jun 18, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

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: 166c2ecb-f445-48a6-975e-995a54a2046d

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

Adds model size reporting to the fga CLI: AuthzModel gains a GetSizeInKB() method computing the protobuf-serialized byte count rounded to two decimals, a buildDSLMetadata helper, and conditional size_kb emission in JSON/DSL output. The validate command includes size_kb in its result, and the get command's --field flag gains size as a valid option. README and depguard config are updated accordingly.

Changes

Model size reporting for get and validate

Layer / File(s) Summary
AuthzModel size computation and rendering
internal/authorizationmodel/model.go, internal/authorizationmodel/model_test.go, .golangci.yaml
AuthzModel gains SizeKB *float64 and GetSizeInKB() via proto marshaling with 2-decimal rounding. GetProtoModel() now uses DiscardUnknown: true. DisplayAsJSON() conditionally sets size_kb; DisplayAsDSL() delegates metadata to the new buildDSLMetadata() helper that conditionally emits a # Size: comment. depguard allow lists are extended for the proto import. Tests cover size value, rounding, and conditional rendering in both JSON and DSL formats.
validate command size output
cmd/model/validate.go, cmd/model/validate_test.go
validationResult adds SizeKB *float64 (size_kb); validate() populates it from inputModel.GetSizeInKB(). TestValidate expectations are updated and TestValidateReportsSize is added.
get command flag and README docs
cmd/model/get.go, README.md
--field help text adds size as an accepted value. README documents the new size field for fga model get (DSL and JSON examples with size_kb) and updates fga model validate response examples to include size_kb when parsing succeeds.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~15 minutes

Suggested reviewers

  • dyeam0
🚥 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
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main feature: adding model size reporting to fga model get and validate commands.
Linked Issues check ✅ Passed All objectives from issue #711 are addressed: size field added to fga model get via --field flag, size_kb included in model get and validate outputs, size displayed as comment in DSL format, and non-blocking validation implemented.
Out of Scope Changes check ✅ Passed All changes are within scope of issue #711: model size reporting implementation, documentation updates, and supporting tests. No unrelated modifications detected.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/model-size-field

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

Adds reporting of protobuf-serialized authorization model size (in KB) to CLI model inspection/validation flows, helping users gauge proximity to server-side max model size limits.

Changes:

  • Add size as a selectable --field for fga model get, exposing size_kb in JSON and # Size: … KB in FGA/DSL output.
  • Include size_kb in fga model validate JSON output when parsing succeeds.
  • Add/update tests and linter allowlists for the new protobuf usage.

Reviewed changes

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

Show a summary per file
File Description
README.md Documents new size field behavior and shows example outputs.
internal/authorizationmodel/model.go Adds size_kb field support and size computation + DSL metadata rendering.
internal/authorizationmodel/model_test.go Adds unit tests for size computation and output formatting.
cmd/model/validate.go Extends validate JSON output to include size_kb.
cmd/model/validate_test.go Updates validate tests and adds a size reporting test.
cmd/model/get.go Updates --field help text to include size.
.golangci.yaml Allows google.golang.org/protobuf/proto imports under depguard rules.

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

Comment thread internal/authorizationmodel/model.go Outdated
Comment thread README.md Outdated
Comment thread cmd/model/validate_test.go

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

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
cmd/model/validate.go (1)

58-69: ⚠️ Potential issue | 🟠 Major

Use DiscardUnknown: true option in protojson.Unmarshal at line 58 to prevent rejection of valid models with id.

When inputModel contains a valid ULID id, the setCreatedAt() method populates CreatedAt. The subsequent GetAsJSONString() call includes this field in the JSON output. The strict protojson.Unmarshal() at line 58 fails on the unknown created_at field (which doesn't exist in pb.AuthorizationModel), preventing validation from completing and size_kb from being set.

This pattern is already used correctly elsewhere in GetProtoModel() (internal/authorizationmodel/model.go:118). Apply the same solution here:

Suggested fix
-	err = protojson.Unmarshal([]byte(*modelJSONString), model)
+	err = (protojson.UnmarshalOptions{DiscardUnknown: true}).Unmarshal([]byte(*modelJSONString), model)
 	if err != nil {
 		output.IsValid = false
 		errorString := "unable to parse json input"
 		output.Error = &errorString
 
 		return output
 	}
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@cmd/model/validate.go` around lines 58 - 69, The protojson.Unmarshal call in
the validate function is failing because it strictly rejects unknown fields,
specifically the created_at field that gets added to the JSON when a model with
an id is processed. Modify the protojson.Unmarshal call to include the
UnmarshalOptions parameter with DiscardUnknown set to true, similar to how it is
already implemented in GetProtoModel function in
internal/authorizationmodel/model.go. This will allow the unmarshaling to
succeed by ignoring unknown fields and allow the validation to complete so that
SizeKB can be properly set in the output.
🧹 Nitpick comments (1)
cmd/model/validate_test.go (1)

103-119: ⚡ Quick win

Add a regression case for a valid ULID id path.

Current additions validate size_kb, but there’s still no test that passes a valid ULID id and asserts successful validation plus size_kb emission.

🧪 Suggested test addition
 func TestValidateReportsSize(t *testing.T) {
 	t.Parallel()

 	model := authorizationmodel.AuthzModel{}
 	if err := model.ReadFromJSONString(`{"schema_version":"1.1"}`); err != nil {
 		t.Fatalf("unexpected parse error: %v", err)
 	}

 	result := validate(model)
 	if result.SizeKB == nil {
 		t.Fatalf("expected SizeKB to be set")
 	}

 	if *result.SizeKB != model.GetSizeInKB() {
 		t.Errorf("expected %v to equal %v", *result.SizeKB, model.GetSizeInKB())
 	}
 }
+
+func TestValidateWithValidIDAndSize(t *testing.T) {
+	t.Parallel()
+
+	model := authorizationmodel.AuthzModel{}
+	if err := model.ReadFromJSONString(`{"id":"01GVKXGDCV2SMG6TRE9NMBQ2VG","schema_version":"1.1"}`); err != nil {
+		t.Fatalf("unexpected parse error: %v", err)
+	}
+
+	result := validate(model)
+	if !result.IsValid {
+		t.Fatalf("expected valid model, got error: %v", *result.Error)
+	}
+	if result.SizeKB == nil {
+		t.Fatalf("expected SizeKB to be set")
+	}
+}
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@cmd/model/validate_test.go` around lines 103 - 119, Add a new test case or
modify the TestValidateReportsSize test to include a valid ULID value in the
`id` field of the JSON input string passed to ReadFromJSONString. The test
should assert that when a valid ULID id is present, the validate function still
successfully processes the model without errors, and correctly reports the
SizeKB value. This ensures the validation logic properly handles the id field
alongside the size_kb emission.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@README.md`:
- Around line 502-503: The created_at timestamp example in the README.md file at
lines 502-503 uses ISO 8601 format with a T separator (2023-04-11T23:26:34.759
+0000 UTC), but the actual DSL output from internal/authorizationmodel/model.go
uses %v formatting which produces a space-separated timestamp instead of
T-separated. Update the example in README.md to use the correct format that
matches the actual CLI output by replacing the T separator with a space between
the date and time components.

---

Outside diff comments:
In `@cmd/model/validate.go`:
- Around line 58-69: The protojson.Unmarshal call in the validate function is
failing because it strictly rejects unknown fields, specifically the created_at
field that gets added to the JSON when a model with an id is processed. Modify
the protojson.Unmarshal call to include the UnmarshalOptions parameter with
DiscardUnknown set to true, similar to how it is already implemented in
GetProtoModel function in internal/authorizationmodel/model.go. This will allow
the unmarshaling to succeed by ignoring unknown fields and allow the validation
to complete so that SizeKB can be properly set in the output.

---

Nitpick comments:
In `@cmd/model/validate_test.go`:
- Around line 103-119: Add a new test case or modify the TestValidateReportsSize
test to include a valid ULID value in the `id` field of the JSON input string
passed to ReadFromJSONString. The test should assert that when a valid ULID id
is present, the validate function still successfully processes the model without
errors, and correctly reports the SizeKB value. This ensures the validation
logic properly handles the id field alongside the size_kb emission.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 316e37e9-9284-4866-8cf0-a6504a7ecdcd

📥 Commits

Reviewing files that changed from the base of the PR and between baaaff4 and ec126d4.

📒 Files selected for processing (7)
  • .golangci.yaml
  • README.md
  • cmd/model/get.go
  • cmd/model/validate.go
  • cmd/model/validate_test.go
  • internal/authorizationmodel/model.go
  • internal/authorizationmodel/model_test.go

Comment thread README.md Outdated

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

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

Comment thread cmd/model/validate.go Outdated
Comment thread cmd/model/validate_test.go Outdated
aaguiarz
aaguiarz previously approved these changes Jun 18, 2026
@rhamzeh rhamzeh added this pull request to the merge queue Jun 18, 2026
Merged via the queue into main with commit 6dff890 Jun 18, 2026
25 checks passed
@rhamzeh rhamzeh deleted the feat/model-size-field branch June 18, 2026 02:57
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.

Allow getting the proto serialized model size

4 participants