Skip to content

chore: evaluate client-side rules and rollouts - #13

Merged
lourens-octopus merged 4 commits into
mainfrom
lourens/bmbb-1514/evaluate-rules
Nov 22, 2026
Merged

lourens-octopus merged 4 commits into
mainfrom
lourens/bmbb-1514/evaluate-rules

Conversation

@lourens-octopus

@lourens-octopus lourens-octopus commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Resolves BMBB-1514.

Ports .NET's V4/ServerSideEvaluation, ClientSideRule and Conditions/*, so a flag deferred to the client resolves from its rules. evaluate(slug, context) is unchanged.

What's in it

  • Rules: OR'd, first match wins (Matched rule '<name>'.). Conditions within a rule are AND'd and short-circuit. No match gives false (Did not match any rules.).
  • context-attribute-is-one-of / is-not-one-of: keys and values compare case-insensitively, uppercased one character at a time as .NET's OrdinalIgnoreCase and Java's equalsIgnoreCase do. So Straße doesn't match STRASSE, although the browser provider's toUpperCase would match them. Every case variant of a key is checked, and non-string attributes count as absent. The second condition is the exact negation of the first.
  • percentage-by-context: pure-Python MurmurHash3 x86_32, seed 0, over the UTF-8 bytes of evaluationKey:targetingKey. Bucket is hash % 100 + 1, included when bucket <= percentage. An empty or missing targeting key matches only at 100. Out-of-range percentages raise ParseError rather than clamping.
  • Unknown condition types never match. A missing type raises ParseError at evaluation, as in .NET.
  • Parsing: rules and conditions become typed objects. A wrong-typed field reads as absent, so it raises ParseError at evaluation and costs only that flag. true and 50.0 aren't accepted as a percentage. An empty values list raises ParseError, as in .NET.

Tests

  • The 114 [evaluationKey, targetingKey, bucket] vectors, copied verbatim from .NET's PercentageRolloutTests.cs with the "DO NOT modify" comment.
  • Evaluator-seam cases the fixtures don't cover: wrong-typed fields; int, bool, float, datetime, sequence and mapping attributes; non-ASCII keys and values where the providers disagree (ß, ligatures); and a malformed rule or condition that evaluation never reaches.
  • as_int directly, alongside the other JSON helpers.
  • Locally, all 71 specification fixture cases (spec main, 0f49852) pass against the evaluator on value, reason and error code. That runner isn't committed; BMBB-1548 adds the real one.

Malformed parts are only read if evaluation reaches them

Nothing checks the response up front. A malformed rule behind a matching one, or a malformed condition behind a failing one, never fails the flag. This is deliberate and matches the other providers: it was agreed in the review of openfeature-provider-dotnet PR 93, so every library "bails on an evaluation" the same OpenFeature-supported way. .NET, Java and the browser provider each test it, and so does this PR now.

The spec fixture saying a missing type "fails the whole evaluation rather than just its own rule" contrasts it with an unknown type, which fails only its own rule. It doesn't mean validating up front. BMBB-1553 proposes spec fixtures that pin this behaviour, and non-ASCII case matching, for every provider.

Errors resolve to the caller's default

The ticket says that on any error the evaluator must return value=default_value and reason=ERROR itself. That's because the SDK passes a returned error resolution through unchanged. The evaluator doesn't return errors, though. It raises ParseError, as before, and the SDK (v0.10.0, openfeature/client.py) catches any OpenFeatureError and returns value=default_value, reason=ERROR with its error code and message.

I checked this through a real OpenFeatureClient with a stub provider calling evaluate on an untyped condition. get_boolean_details returned the caller's default for both True and False, with reason=ERROR and PARSE_ERROR.

So this needs nothing more here or in BMBB-1515. The provider only has to let ParseError propagate rather than turning it into a returned resolution.

🤖 Generated with Claude Code

Ports .NET's ServerSideEvaluation, ClientSideRule and Conditions so a flag
deferred to the client resolves from its rules:

- Rules are OR'd and the first match wins, with reason
  "Matched rule '<name>'.". Conditions within a rule are AND'd and
  short-circuit. No match gives false with "Did not match any rules.".
- context-attribute-is-one-of and is-not-one-of compare keys and values
  case-insensitively, and treat non-string attributes as absent.
- percentage-by-context buckets with a pure-Python MurmurHash3 x86_32 over
  "evaluationKey:targetingKey". A missing targeting key matches only at 100.
- Unrecognised condition types never match.

Rules and conditions are parsed into typed objects. A field of the wrong
type reads as absent, so it raises ParseError when its flag is evaluated
and costs only that flag.

Tests cover the 114 shared rollout vectors, wrong-typed fields and
non-string context attributes. The specification fixtures cover the rest.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@lourens-octopus
lourens-octopus requested a review from a team as a code owner November 19, 2026 23:51
lourens-octopus and others added 2 commits November 20, 2026 00:09
str.upper applies Unicode's full case mappings, so "Straße" matched
"STRASSE", where .NET's OrdinalIgnoreCase and Java's equalsIgnoreCase
don't. Keys and values are now uppercased one character at a time, keeping
any character that would expand.

Also:

- Make "Did not match any rules." a constant rather than a function.
- Say in parse_condition's docstring that a missing type raises at
  evaluation, unlike an unrecognised one.
- Test as_int directly.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Nothing checks a response up front, so a malformed rule behind a matching
one, or a malformed condition behind a failing one, never fails the flag.
That was agreed in the review of the .NET provider's client-side
evaluation, and the .NET, Java and browser providers each pin it with the
same tests. The specification fixtures don't cover it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@liamhughes liamhughes left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A couple of things I'd be interested for your opinion on, but looks good. 👍

Comment on lines +33 to +34
Written out rather than taken from ``mmh3`` so the provider doesn't need a
native wheel. The blocks are read little-endian, as every provider does.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably doesn't matter too much, but curious about the decision to roll our own.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's to avoid a native dependency. The other providers' libraries are plain .NET/Java/JS, but Python's only maintained option, mmh3, is a C extension. On any platform without a prebuilt wheel (a new CPython release, free-threaded builds, unusual Linux images), installing the provider would need a compiler, and it's one more runtime dependency in customers' apps.

pytest.param("пользователь", "ПОЛЬЗОВАТЕЛЬ", True, id="cyrillic"),
],
)
def test_a_non_ascii_value_compares_one_character_at_a_time(

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure about the non-ASCII stuff. I know .NET/Java and TypeScript disagree and it is pretty hard to get it to align. Not sure if we want to lock in the edge cases, but I guess at least the tests show that we're aware of it.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah the it's been a bit of a headache, I've had Claude update BMBB-1553 to set fixtures for what we want to do, if we want to do anything or just accept that they may be a bit different 🤷

The accented and Cyrillic cases behave the same in every provider, so
they pinned nothing. What's left are the "ß" and ligature cases, where
.NET and Java differ from the browser provider, with a pointer to
BMBB-1553, which will settle which way the specification goes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@lourens-octopus
lourens-octopus merged commit 94bd4dc into main Nov 22, 2026
18 checks passed
@lourens-octopus
lourens-octopus deleted the lourens/bmbb-1514/evaluate-rules branch November 22, 2026 18:55
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.

2 participants