v2breaking

package
v1.22.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 6, 2026 License: Apache-2.0 Imports: 8 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package v2breaking detects request shapes whose v1 vs v2 (weighted-graph) resolution behavior is known to differ. It exists so the server can emit telemetry about potential breaking-change exposure before the weighted-graph resolver becomes the default — see the openfga.dev breaking-change writeup.

All predicates here are schema-shape filters only: they read the model, not stored tuples. They may over-report (the request shape matches but no tuple triggers the divergence) but never miss a real divergence.

Index

Constants

View Source
const (
	ReasonSelfReferentialUserset = "self_referential_userset"
	ReasonAliasUserset           = "alias_userset"
	ReasonComputedUsersetSelfObj = "computed_userset_self_object"
	ReasonTTUUserset             = "ttu_userset"
	ReasonUsersetWithExclusion   = "userset_with_exclusion"
	ReasonWildcardWithExclusion  = "wildcard_with_exclusion"
)

Reason constants are stable strings emitted in logs/metrics. Do not rename without coordinating with downstream dashboards.

Variables

This section is empty.

Functions

func CheckExclusionReason

func CheckExclusionReason(typesys *typesystem.TypeSystem, tk *openfgav1.CheckRequestTupleKey) string

CheckExclusionReason returns a non-empty reason string when the Check request's target relation is shaped such that v2 would have rejected the request at request time. Used on the v1 fallback path, where v2Check did not run (or failed before validating request shape) and CheckReasonFromV2Error therefore has no error to map.

Detection:

  • Userset user + Difference anywhere in the target rewrite → userset_with_exclusion.
  • Non-userset user of type T + Difference whose base branch can reach a T:* wildcard leaf → wildcard_with_exclusion. The reachability walk crosses ComputedUserset and TupleToUserset edges (see walkForWildcardUnderDifference), so shapes where the Difference sits one hop away via TTU are still detected.

func CheckReason

func CheckReason(typesys *typesystem.TypeSystem, tk *openfgav1.CheckRequestTupleKey) string

CheckReason returns a non-empty reason string when the Check request shape matches a known v1→v2 divergence for userset users. The caller is expected to have already verified that the user is a userset (object#relation) and that v2Check returned FALSE — this function does not re-check those.

Shape catalogue:

  • "self_referential_userset": v1 unconditionally returned TRUE for check(o#r, r, o); v2 evaluates against the schema and returns FALSE.

  • "alias_userset": the target relation directly accepts T#R' where R' resolves via computed_userset to the user's relation R, and R is not itself directly assignable on the target. v1 follows the alias from a stored tuple, v2 does not.

  • "computed_userset_self_object": user's object equals the target object, and the user's relation appears as a ComputedUserset leaf in the target relation's rewrite tree.

  • "ttu_userset": target relation's rewrite contains a TupleToUserset whose computed relation equals the user's relation, AND the user's object type is directly-related to the tupleset relation.

func CheckReasonFromV2Error

func CheckReasonFromV2Error(err error) string

CheckReasonFromV2Error maps a v2Check error to a v2-breaking reason when the error is one of the exclusion-shape rejections v2Check emits at request time. Returns "" for any other error (context, throttling, generic failure, etc.).

V2Check rejects two exclusion shapes at request time:

  • check.ErrWildcardInvalidRequest — a wildcard user reaches a Difference node (directly or transitively through TTU/ComputedUserset).
  • check.ErrUsersetInvalidRequest — a userset user reaches a Difference node.

The v1 fallback path will still produce an answer, so callers should log the reason as a potential-divergence signal alongside the returned v2 error.

func ListObjectsReason added in v1.20.0

func ListObjectsReason(typesys *typesystem.TypeSystem, targetObjectType, relation, subject string) string

ListObjectsReason returns a non-empty reason string when the ListObjects request shape matches a known v1→v2 divergence. A userset subject (object#relation) exercises the four per-userset shapes plus userset_with_exclusion; a concrete or wildcard subject can only reach wildcard_with_exclusion.

For userset/wildcard subjects the v2 pipeline currently routes to the legacy (v1) algorithm (see the precondition in list_objects.go). They are still reported, but their result might change once ListObjects respects the v2 path.

func ListObjectsResponseConfirmsReason added in v1.20.0

func ListObjectsResponseConfirmsReason(reason, subject string, objects []string) bool

ListObjectsResponseConfirmsReason reports whether the ListObjects response is consistent with v1 having actually traversed the divergent path for the given reason. It mirrors ListUsersResponseConfirmsReason and suppresses false- positive logs on shape-matched requests whose responses didn't observably exercise the v1 behaviour.

The response is a list of object IDs (the target objects the subject relates to). For the two self-object shapes v1 surfaces the subject's own object (check(o, r, o#r') is unconditionally/structurally TRUE), so the confirmation checks that specific object is present. For the alias, TTU and exclusion shapes we cannot attribute a specific object to the divergent path, so a non-empty response is taken as confirmation that v1 walked it.

This lets the breaking-change tests run with the v2 pipeline enabled: today the pipeline routes userset/wildcard subjects to v1 and the divergent object is present, so the log fires; once the v2 pipeline is made consistent with v2 the object will drop out of the response, the log will stop firing, and the tests will fail — signalling they can be removed.

func ListUsersReason

func ListUsersReason(typesys *typesystem.TypeSystem, object *openfgav1.Object, relation string, filter *openfgav1.UserTypeFilter) string

ListUsersReason returns a non-empty reason string when the ListUsers request shape matches a known v1→v2 divergence. Compared to CheckReason, it also detects the two exclusion-shape cases that v2Check rejects at request time (rather than silently returning FALSE):

  • "userset_with_exclusion": the filter is a userset and the target relation's rewrite contains a Difference node.

  • "wildcard_with_exclusion": the filter is a non-userset of type T and the target relation's rewrite contains a Difference whose base branch can accept a typed wildcard T:*.

func ListUsersResponseConfirmsReason

func ListUsersResponseConfirmsReason(reason string, typesys *typesystem.TypeSystem, object *openfgav1.Object, relation string, filter *openfgav1.UserTypeFilter, users []*openfgav1.User) bool

ListUsersResponseConfirmsReason reports whether the ListUsers response is consistent with v1 having actually traversed the divergent path for the given reason. It is used to suppress false-positive logs on shape-matched requests whose responses didn't observably exercise the v1 behavior.

For the four per-user-shape reasons, this looks for the specific user that v1 surfaces via the divergent path. For the exclusion-shape reasons, v2 would reject the request at request time — so any non-empty v1 response on a Difference-containing relation means v1 actually walked the exclusion path to produce it.

Returns true for unknown reasons, so the caller's logic stays simple.

Types

type BatchReasoner added in v1.20.0

type BatchReasoner struct {
	// contains filtered or unexported fields
}

BatchReasoner accumulates potential v1→v2 (weighted-graph) resolution divergences across a batch of Check tuple keys evaluated against a single type system. It encapsulates the per-check shape detection, the memoization that keeps repeated shapes cheap, and the aggregation the caller needs to emit a single summary log.

Detection is purely schema-shape (see CheckExclusionReason / CheckReason) and does NOT gate on the check's allowed result: the outcome reflects whichever engine answered (v2 normally, v1 on fallback), so gating on it would silently drop real divergences on the fallback path — the path this telemetry most needs to flag. Being shape-only, the predicates may over-report.

The predicates walk the model's rewrite tree, which is the dominant cost. For a fixed type system both reasons are functions of the request's shape (object type, relation, user type[#relation]), not its identifiers, so shapes are memoized and each is walked at most once. Two caches are kept:

  • exclusionCache: pure-shape key. CheckExclusionReason never compares object identity, so e.g. document:1@group:eng#member and document:2@group:sales#member share one entry.
  • checkReasonCache: shape key plus a sameObject bool, since CheckReason's self_referential / computed_userset_self_object shapes depend on the user's object equalling the target object — collapsing the concrete IDs to one bit that still keys them together.

A BatchReasoner is not safe for concurrent use.

func NewBatchReasoner added in v1.20.0

func NewBatchReasoner(typesys *typesystem.TypeSystem, batchSize int) *BatchReasoner

NewBatchReasoner returns a BatchReasoner that detects divergences against the given type system. BatchSize is the number of checks in the batch and is used only as a capacity hint for the maps that grow with the batch (the shape caches and the per-correlation-id attribution, each bounded by batchSize); a zero or negative hint is harmless. ReasonSet is left unhinted since it is bounded by the small fixed set of reason kinds, not the batch size.

func (*BatchReasoner) Add added in v1.20.0

func (b *BatchReasoner) Add(correlationID string, tk *openfgav1.CheckRequestTupleKey)

Add detects the divergence shape for a single check and, when one matches, records it against correlationID. Checks that don't match any shape are ignored.

func (*BatchReasoner) Empty added in v1.20.0

func (b *BatchReasoner) Empty() bool

Empty reports whether no check added so far matched a divergence shape.

func (*BatchReasoner) MatchedChecks added in v1.20.0

func (b *BatchReasoner) MatchedChecks() int

MatchedChecks returns the number of checks that matched a divergence shape.

func (*BatchReasoner) Reasons added in v1.20.0

func (b *BatchReasoner) Reasons() []string

Reasons returns the distinct divergence reasons found across the batch, sorted for stable log output.

func (*BatchReasoner) ReasonsByCorrelationID added in v1.20.0

func (b *BatchReasoner) ReasonsByCorrelationID() map[string]string

ReasonsByCorrelationID returns the per-check attribution of each flagged check to its divergence reason.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL