Skip to content

fix(schema): preserve annotations on unchanged definitions during schema writes - #3440

Merged
josephschorr merged 1 commit into
authzed:mainfrom
josephschorr:fix-schema-annotations-stripped
Oct 30, 2026
Merged

josephschorr merged 1 commit into
authzed:mainfrom
josephschorr:fix-schema-annotations-stripped

Conversation

@josephschorr

Copy link
Copy Markdown
Member

Fixes #3412

Description

Since v1.49.0, every schema write has stripped the aliasing_relation and canonical_cache_key annotations from definitions that did not change. The write path annotated only definitions with a semantic diff, but then wrote every compiled definition, so unchanged ones replaced their stored, annotated copies. This happens in both the legacy and single-store schema modes.

Without the annotations, permissions that alias a relation are dispatched as separate subproblems, and equivalent permissions stop sharing dispatch cache entries. Affected deployments see more dispatches, higher check latency and more datastore load, with no errors.

Changes

  • Annotate every definition before writing the schema, not only changed ones. Both storage paths write from the same set of definitions, so this fixes legacy and single-store writes alike. It also repairs datastores that were already stripped: writing the schema again restores the annotations.
  • Size the BDD operation caches used to compute canonical cache keys to the expression being canonicalized, instead of rudd's 10,000-entry default per cache. Annotating every definition otherwise raised memory allocated per schema write by about 80%; with this change the increase is about 3–5%, and annotation itself is about 40% faster. The caches only memoize operations, so the computed keys are unchanged.

Testing

A new test writes a schema, then rewrites it, in all four schema modes, and checks that annotations survive an identical rewrite and a rewrite that adds a definition, that they are restored when starting from stripped definitions, and that recomputed keys match the originals. The test fails in every mode without the fix.

@josephschorr
josephschorr requested a review from a team as a code owner October 29, 2026 16:44
@github-actions github-actions Bot added the area/tooling Affects the dev or user toolchain (e.g. tests, ci, build tools) label Oct 29, 2026
@josephschorr
josephschorr force-pushed the fix-schema-annotations-stripped branch from 4b85840 to a711f1b Compare October 29, 2026 16:47

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

LGTM

@codecov

codecov Bot commented Oct 29, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 40.00000% with 6 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
internal/services/shared/schema.go 33.34% 4 Missing and 2 partials ⚠️

📢 Thoughts on this report? Let us know!

…ema writes

Schema writes passed every compiled definition to WriteSchema, but only
annotated those with a semantic diff. Unchanged definitions were therefore
written without their aliasing_relation and canonical_cache_key
annotations, in both the legacy and unified schema storage paths.

Annotate every definition before writing, which also restores annotations
on datastores already affected. Size the BDD operation caches used for
canonical cache keys to the expression, rather than the 10,000-entry
default, so annotating every definition does not add significant
allocation.

Fixes authzed#3412
@josephschorr
josephschorr force-pushed the fix-schema-annotations-stripped branch from a711f1b to bd02550 Compare October 30, 2026 16:30
@josephschorr
josephschorr enabled auto-merge (rebase) October 30, 2026 16:30
@josephschorr
josephschorr merged commit 2eb0537 into authzed:main Oct 30, 2026
44 of 45 checks passed
@github-actions github-actions Bot locked and limited conversation to collaborators Oct 30, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area/tooling Affects the dev or user toolchain (e.g. tests, ci, build tools)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

WriteSchema strips aliasing_relation and canonical_cache_key from unchanged definitions (v1.49.0+)

2 participants