Skip to content

feat(api): Evaluate identity flags through flag-engine - #8555

Draft
khvn26 wants to merge 5 commits into
mainfrom
feat/engine-evaluation-authority
Draft

khvn26 wants to merge 5 commits into
mainfrom
feat/engine-evaluation-authority

Conversation

@khvn26

@khvn26 khvn26 commented Sep 18, 2026

Copy link
Copy Markdown
Member

Thanks for submitting a PR! Please check the boxes below:

  • I have read the Contributing Guide.
  • I have added information to docs/ if required so people know about the feature.
  • I have filled in the "Changes" section below.
  • I have filled in the "How did you test this code" section below.

Changes

Contributes to #6654

In this PR, we route identity flag evaluation through get_evaluation_result, leaving Core API responsible only for building an EvaluationContext.

How did you test this code?

Added api/tests/unit/environments/identities/test_unit_identities_evaluation.py, and fixed existing test.

@vercel

vercel Bot commented Sep 18, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

3 Skipped Deployments
Project Deployment Actions Updated
docs Ignored Ignored Preview Sep 22, 2026 11:36am UTC
flagsmith-frontend-preview Ignored Ignored Preview Sep 22, 2026 11:36am UTC
flagsmith-frontend-staging Ignored Ignored Preview Sep 22, 2026 11:36am UTC

Request Review

@coderabbitai

coderabbitai Bot commented Sep 18, 2026

Copy link
Copy Markdown

Important

Draft PR not reviewed

Draft PRs are not automatically reviewed by default.

  • Trigger a manual review

To automatically review draft PRs, update your CodeRabbit configuration:

reviews:
  auto_review:
    drafts: true

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.

@github-actions github-actions Bot added api Issue related to the REST API feature New feature or request labels Sep 18, 2026
@codecov

codecov Bot commented Sep 18, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.81%. Comparing base (47db6dc) to head (0d31446).

Additional details and impacted files
@@           Coverage Diff            @@
##             main    #8555    +/-   ##
========================================
  Coverage   98.80%   98.81%            
========================================
  Files        1631     1637     +6     
  Lines       66920    67117   +197     
========================================
+ Hits        66123    66320   +197     
  Misses        797      797            

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@github-actions github-actions Bot added feature New feature or request and removed feature New feature or request labels Sep 21, 2026
Core API resolved override precedence and multivariate bucketing itself,
in parallel with the engine it already used for segment matching. This
routes identity flag evaluation through `get_evaluation_result` instead,
leaving Core API responsible only for building an `EvaluationContext`.

`Identity.get_all_feature_states` now asks the engine which override won
rather than comparing feature states with `>`. It still returns Django
rows: `FlagResult.metadata.feature_state_id` maps the engine's verdict
back to the row it came from, so callers are unaffected for now.

Identity overrides reach the engine the way SDKs express them, as a
synthetic segment whose overrides sit at `priority = -inf`. That encodes
"no segment override outranks an identity override", which until now was
`FeatureState.__gt__` returning True unconditionally.

Every segment with an override in the environment is now evaluated,
rather than pre-filtering to segments the identity is known to match.
A single pass is what lets a segment condition depend on a flag that is
itself only resolved during evaluation (#1674).

Contributes to #6654.
Drop the redundant OR term on the transient path, and the module
docstring, comments and pragmas that restated what the code says.
…ypes

`evaluation.py` mixed a mapper, a service and two result types. Split it
along the lines the rest of the package already uses, and rename
`build_identity_evaluation_context` to `map_identity_to_evaluation_context`
to match the mapper naming convention.

Tests follow the split. No behaviour change.
@khvn26
khvn26 force-pushed the feat/engine-evaluation-authority branch from 02251d0 to e7192f5 Compare September 22, 2026 10:15
@github-actions github-actions Bot added feature New feature or request and removed feature New feature or request labels Sep 22, 2026
…n_context

The caller had to query feature states and hand them back in four
mutually-consistent arguments. Resolve them in the mapper instead, as
`map_environment_to_engine` alongside it already does, leaving one
argument per genuine caller choice.

`environments.identities.mappers` had nothing left to do and is gone;
`evaluate_identity` calls the engine mapper directly.

Feature states are now always resolved, so `Identity.get_segments` costs
one more query. That is the price of correctness once segment conditions
can read `$.flags.*`: a segments-only context cannot answer them.
@khvn26
khvn26 force-pushed the feat/engine-evaluation-authority branch from 6910685 to 6ac930f Compare September 22, 2026 11:06
@github-actions github-actions Bot added feature New feature or request and removed feature New feature or request labels Sep 22, 2026
Serialisers and integrations re-resolved a feature state's value per
identity, hashing multivariate allocation themselves, after the engine
had already decided it. Carry the engine's `FlagResult` on each feature
state `Identity.get_all_feature_states` returns, so the value and variant
travel with the row they came from.

Removes `FeatureState.get_multivariate_feature_state_value` and
`get_feature_state_value_by_hash_key`, and the `identity` argument to
`get_feature_state_value`, which now means only "this state's stored
value". `evaluated_value` is the value as evaluated, falling back to the
stored one where nothing evaluated it.

Edge identities keep their overrides in DynamoDB, so the rows the edge
serialiser reads never pass through an evaluation. Those resolve through
`features.evaluation.evaluate_feature_state` instead, which asks the
engine about a single feature state.
@github-actions github-actions Bot added feature New feature or request and removed feature New feature or request labels Sep 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api Issue related to the REST API feature New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant