Repository navigation
Commit d7078e0
authored
feat: add protocol-v2 multivariate flag evaluation (#744)
## Summary
- Make evaluator v2 a clean major release: `newEvaluator({ flags,
segments })` prepares a complete collection and returns
`evaluateAll(context)` and `evaluateFlag(context, flagKey)` methods.
Remove the v1 value-rule API and legacy serialization helpers.
- Batch evaluation returns `{ context, flags }` with normalized context
once and independent per-flag results/diagnostics. One unresolved flag
does not stop the remaining outputs. Single-flag evaluation visits only
its selected root and dependencies. The methods map naturally to Node
SDK `getFlags()` / `getFlagsForBootstrap()` and `getFlag()`
respectively; SDK wrappers, overrides and fallbacks remain outside the
evaluator.
- Preserve flag and segment references instead of requiring publishers
to inline their filters. Flag references match explicit variant keys,
never the truthiness of variant values. Segments remain reusable
predicates and can reference other segments or flags.
- Resolve references recursively for every evaluation. **No
dependency-result caching or memoization**; repeated references are
evaluated again. Retain the existing definition-level membership Sets
and percentage-bound preparation.
- Preserve a valid matching referenced selection despite diagnostics
from unsuccessful independent sibling rules. Nonmatches accompanied by
diagnostics remain invalid through negation, so an uncertain negative
reference cannot grant access. Ordinary authored AND/OR error handling
is unchanged. Propagated diagnostics identify their original flag or
segment.
- Reject duplicate keys, missing references, unknown referenced variant
keys and cycles during preparation, including mixed flag/segment cycles
and unreachable references. Evaluating an unknown flag key also throws.
- Preserve generic variant values and use a discriminated `resolved`
result, distinguishing selected `undefined` from failure and requiring
success metadata.
- Keep prepared Sets and percentage bounds private. Precompute
lookups/bounds once, use a simple allocation scan, and preserve boolean
cohort hashing.
- Return structured diagnostics instead of console logging. Invalid
numeric/date comparisons cannot match through negation.
- Keep the legacy Node SDK on published evaluator 1.1.2 via an npm
alias, retaining main's v1 diagnostic fixes without linking it to the v2
workspace. Node SDK v2 adoption is separate in #790.
## Main synchronization
Merged `main` at `abb17bd2f801a8b299ef02eca87b2d9ca774572a` through
merge commit `486b2099e0d03f5e86566ab31660b0cb95b20ea8`. The reviewed
collection evaluator source is unchanged. Main's SDK fixes, dependency
updates and Vitest 4.1.11 migration are retained; an additional
invalid-operator regression covers v2 fail-closed handling. No history
was rewritten. The separate SDK branches were not changed and need their
own synchronization with this updated base.
## API
```ts
const evaluator = newEvaluator({
flags: compiledFlags,
segments: compiledSegments,
});
const batch = evaluator.evaluateAll(context); // { context, flags }
const result = evaluator.evaluateFlag(context, "my-flag");
```
Reference filters:
```ts
{ type: "flag", key: "model", variantKey: "quality" }
{ type: "segment", key: "enterprise" }
```
A matching selected variant is authoritative even if earlier rules
produced diagnostics. A diagnostic-bearing nonmatch is deliberately more
conservative than explicitly matching the selected fallback variant.
Segments do not introduce independent-rule boundaries.
## Validation
- **301 evaluator tests** and **265 legacy Node SDK tests** passed after
the main merge. Consumer regressions also passed: **208 Browser, 65
React, 13 Vue, 27 OpenFeature Browser and 28 OpenFeature Node tests**.
These are the v1 SDKs retained on this evaluator PR, not the separate
SDK v2 branches.
- **14 batch/single-flag API cases** cover result-type narrowing, output
selection, normalized-context sharing, per-flag failure isolation,
parity between operations, unrelated-root exclusion, no memoization in
either definition order, returned-state isolation, selected undefined
values, empty collections and dangerous object keys.
- **71 collection/reference cases** cover the original independent-grant
reproduction; both source-rule orders; missing context; unsupported
arrays; invalid comparisons and operators; rollout/distribution
behavior; nested flag/segment references; diagnostic provenance and
deduplication; negative-reference safety; duplicate/missing/cyclic
definitions; shared acyclic dependencies; and repeated evaluation
without result caching.
- Evaluator/test TypeScript checks and builds/declarations passed for
evaluator, Node, Browser, React, Vue, both OpenFeature providers and
React Native. Immutable installation, scoped formatting/lint and
PR-delta whitespace checks passed. Scoped evaluator/Node lint has zero
warnings/errors; repository lint has zero errors and one existing
generated Next.js triple-slash-reference warning. Existing dependency
peer warnings remain. Normal commit hooks passed without changing the
verified content.
- Existing definition-level benchmarks passed with the preceding
collection change. No dependency-graph performance claim is made;
correctness is the focus of this work.
- Changesets release-plan validation selects evaluator 2.0.0, Node SDK
1.8.3 and OpenFeature Node 1.2.8; legacy SDKs are not migrated to the v2
protocol.
- Full workspace build was previously attempted but blocked locally by
missing Java for unrelated Management SDK OpenAPI generation; it was not
rerun for this merge. No E2E was run in this checkpoint.
Upstream-generated Management SDK files were retained unchanged; the PR
delta contains no Management SDK changes.
## Scope
Still a draft; nothing published or deployed. This layers the
collection-based alternative discussed in #780 into v2 rather than
adding `ruleEvaluation: "independent"` metadata to v1. #780 and its
companion web PR are untouched.
Publisher/compiler changes and matching server-side consumers are
separate in reflagcom/web#3660. SDK adoption of `/flags` and
variant-valued public APIs are separate in #790 and draft #791. Existing
v1 consumers must not receive v2 reference nodes.
Read-only inspection of web and its Advanced flags work (#3660) confirms
the follow-up needs a distinct reference-preserving v2 lowering,
reachable compiled segments, complete collection transport, and
snapshot-level evaluator ownership. Boolean v2 rules must be compiled
from normalized sources rather than copied from the already-inlined
legacy rules. Keep legacy `/features` and config compilation unchanged,
and retain the complete graph while selecting/authorizing output roots.1 parent abb17bd commit d7078e0
16 files changed
Lines changed: 2667 additions & 2522 deletions
File tree
- .changeset
- packages
- flag-evaluation
- src
- test
- node-sdk
- src
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | | - | |
| 3 | + | |
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
| |||
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
| 19 | + | |
19 | 20 | | |
20 | 21 | | |
21 | 22 | | |
| |||
30 | 31 | | |
31 | 32 | | |
32 | 33 | | |
| 34 | + | |
33 | 35 | | |
34 | 36 | | |
35 | 37 | | |
| |||
0 commit comments