Skip to content

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

Open
khvn26 wants to merge 7 commits into
stack/1-evaluation-mappersfrom
stack/2-identity-evaluation
Open

khvn26 wants to merge 7 commits into
stack/1-evaluation-mappersfrom
stack/2-identity-evaluation

Conversation

@khvn26

@khvn26 khvn26 commented Sep 23, 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 all identity flag evaluations (SDK API + dashboard segment membership checks) via the evaluation engine. Environment flags go through it too, without segments for now, so their output is unchanged.

Evaluation services now return EvaluatedFeatureState, pairing each engine result with the feature state it came from. SDK serialisers, the identity webhook and the analytics integrations read evaluated fields (enabled, value, variant) from the former, and stored fields from the latter. FeatureState no longer evaluates: get_feature_state_value() returns the stored value only.

The dashboard …/featurestates/all/ view evaluates through the engine as well, but its serialiser is shared with edge identities, so it switches to EvaluatedFeatureState in #8575.

No behaviour change is intended, except that ?feature= is now case-sensitive, as in Edge API. Multivariate allocation behaviour is pinned to static expectations in tests, and verified to be identical to current Core.

There are some query count / performance implications:

  • Identity.get_segments now fetches feature states.
  • GET /flags/?identifier=…&feature=… now fetches all feature states regardless of the feature query parameter, because dependent flags.
  • Deprecated GET /identities/{identifier}/ asks for flags and segments separately, so it builds a context twice.
  • GET /flags/ makes one more query, prefetching multivariate values.
  • The identity webhook's percentage_allocation now comes from the engine's split weight, rather than a query per flag.

How did you test this code?

Multivariate bucketing is pinned to static data in test_evaluate_identity__multivariate_feature__buckets_as_before_the_engine. The feature is split into ten equal variants, so the variant an identity gets tells you which decile its hash fell in. The environment API key and hashing salt are pinned too. The expected values were derived from Core API's allocation before the engine took over.

The before-and-after tests for bucketing stability (change request commit, versioning weight change, experiment rollout re-applied) now go through evaluate_identity via a variant_assignment fixture.

The identity integration tests no longer mock the engine's hashing.

The SDK view tests assert full responses; only the deprecated endpoint's query counts change. The OpenAPI schema is unchanged.

Added a test for variant on a multivariate flag with no variants, or a keyless one; it passes on main too.

@vercel

vercel Bot commented Sep 23, 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 24, 2026 9:23pm UTC
flagsmith-frontend-preview Ignored Ignored Preview Sep 24, 2026 9:23pm UTC
flagsmith-frontend-staging Ignored Ignored Preview Sep 24, 2026 9:23pm UTC

Request Review

@coderabbitai

coderabbitai Bot commented Sep 23, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Advanced

Run ID: 44bf5d53-8004-479d-a4b0-1e1f4a9a0e38

📥 Commits

Reviewing files that changed from the base of the PR and between 69b7b83 and dd18806.

📒 Files selected for processing (3)
  • api/evaluation/mappers.py
  • api/tests/unit/environments/identities/test_unit_identities_views.py
  • api/tests/unit/evaluation/test_unit_evaluation_mappers.py

Included review availability: Your plan provides up to 8 included reviews per hour; 7 remain after this review.


📝 Walkthrough

Walkthrough

The change adds services that evaluate identity and environment feature states through flag-engine and pair each result with its source feature state. API views, serializers and integration wrappers now consume these evaluated states. The change also moves evaluation-context mapping into the evaluation module, adds split-weight parsing, and updates tests for evaluation precedence, segment priority and multivariate allocation.

Estimated code review effort: 4 (Complex) | ~60 minutes

Merge Risk: ⚪ Minimal · up to dd188

The change preserves override selection, strengthens the allocation check, and excludes the synthetic override context from reported segment membership. No actionable merge risk remains.


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 23, 2026
@codecov

codecov Bot commented Sep 23, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.81%. Comparing base (f27eaf9) to head (acd6b5f).

Additional details and impacted files
@@                     Coverage Diff                     @@
##           stack/1-evaluation-mappers    #8574   +/-   ##
===========================================================
  Coverage                       98.81%   98.81%           
===========================================================
  Files                            1644     1647    +3     
  Lines                           67435    67524   +89     
===========================================================
+ Hits                            66636    66724   +88     
- Misses                            799      800    +1     

☔ 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.

@khvn26
khvn26 force-pushed the stack/2-identity-evaluation branch from 01b53c5 to ed92679 Compare September 23, 2026 08:59
@github-actions github-actions Bot added feature New feature or request and removed feature New feature or request labels Sep 23, 2026
@khvn26
khvn26 force-pushed the stack/2-identity-evaluation branch from ed92679 to 882de75 Compare September 23, 2026 09:17
@github-actions github-actions Bot added feature New feature or request and removed feature New feature or request labels Sep 23, 2026
@khvn26
khvn26 force-pushed the stack/2-identity-evaluation branch from 882de75 to c2846fc Compare September 23, 2026 09:36
@github-actions github-actions Bot added feature New feature or request and removed feature New feature or request labels Sep 23, 2026
@khvn26
khvn26 force-pushed the stack/2-identity-evaluation branch from c2846fc to e26a8b5 Compare September 23, 2026 10:25
@github-actions github-actions Bot added feature New feature or request and removed feature New feature or request labels Sep 23, 2026
@khvn26
khvn26 force-pushed the stack/2-identity-evaluation branch from e26a8b5 to 8118f64 Compare September 23, 2026 10:42
@github-actions github-actions Bot added feature New feature or request and removed feature New feature or request labels Sep 23, 2026
@khvn26
khvn26 force-pushed the stack/2-identity-evaluation branch from 8118f64 to 3b83433 Compare September 23, 2026 11:31
@github-actions github-actions Bot added feature New feature or request and removed feature New feature or request labels Sep 23, 2026
@khvn26
khvn26 force-pushed the stack/2-identity-evaluation branch from 3b83433 to c47236f Compare September 23, 2026 11:44
@github-actions github-actions Bot added the feature New feature or request label Sep 23, 2026
@khvn26
khvn26 added this pull request to stack #8588 September 23, 2026 18:58

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 3


ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Advanced

Run ID: 4c6bc876-a540-4f11-a0ed-4b5bffcaac95

📥 Commits

Reviewing files that changed from the base of the PR and between 1cc7b76 and 791a14c.

📒 Files selected for processing (41)
  • api/environments/identities/models.py
  • api/environments/identities/views.py
  • api/environments/sdk/serializers.py
  • api/evaluation/mappers.py
  • api/evaluation/results.py
  • api/evaluation/services.py
  • api/evaluation/types.py
  • api/features/models.py
  • api/features/serializers.py
  • api/features/views.py
  • api/integrations/amplitude/amplitude.py
  • api/integrations/common/wrapper.py
  • api/integrations/heap/heap.py
  • api/integrations/mixpanel/mixpanel.py
  • api/integrations/rudderstack/rudderstack.py
  • api/integrations/segment/segment.py
  • api/integrations/webhook/serializers.py
  • api/integrations/webhook/webhook.py
  • api/tests/conftest.py
  • api/tests/integration/conftest.py
  • api/tests/integration/environments/identities/test_integration_identities.py
  • api/tests/types.py
  • api/tests/unit/environments/identities/test_unit_identities_models.py
  • api/tests/unit/environments/identities/test_unit_identities_views.py
  • api/tests/unit/evaluation/test_unit_evaluation_mappers.py
  • api/tests/unit/evaluation/test_unit_evaluation_services.py
  • api/tests/unit/experimentation/test_services.py
  • api/tests/unit/features/test_unit_features_models.py
  • api/tests/unit/features/versioning/test_unit_versioning_versioning_service.py
  • api/tests/unit/features/workflows/core/test_unit_workflows_models.py
  • api/tests/unit/import_export/test_unit_import_export_export.py
  • api/tests/unit/integrations/amplitude/test_unit_amplitude.py
  • api/tests/unit/integrations/heap/test_unit_heap.py
  • api/tests/unit/integrations/mixpanel/test_unit_mixpanel.py
  • api/tests/unit/integrations/rudderstack/test_unit_rudderstack.py
  • api/tests/unit/integrations/segment/test_unit_segment.py
  • api/tests/unit/integrations/test_unit_integration.py
  • api/tests/unit/integrations/webhook/test_unit_webhook.py
  • api/tests/unit/integrations/webhook/test_unit_webhook_serializers.py
  • api/tests/unit/util/mappers/test_unit_mappers_engine.py
  • api/util/mappers/engine.py

Included review availability: Your plan provides up to 8 included reviews per hour; 6 remain after this review.

Comment thread api/integrations/webhook/serializers.py Outdated
Comment thread api/tests/unit/experimentation/test_services.py Outdated
Comment thread api/tests/unit/integrations/mixpanel/test_unit_mixpanel.py
@khvn26
khvn26 force-pushed the stack/2-identity-evaluation branch from 791a14c to 7a94e1b Compare September 23, 2026 19:47
@github-actions github-actions Bot added feature New feature or request and removed feature New feature or request labels Sep 23, 2026
@khvn26
khvn26 force-pushed the stack/2-identity-evaluation branch from 7a94e1b to 5ad2f43 Compare September 23, 2026 20:13
@github-actions github-actions Bot added feature New feature or request and removed feature New feature or request labels Sep 23, 2026
@khvn26
khvn26 force-pushed the stack/2-identity-evaluation branch from 5ad2f43 to 69b7b83 Compare September 24, 2026 11:32
@github-actions github-actions Bot added feature New feature or request and removed feature New feature or request labels Sep 24, 2026
Feature states now only ever hold stored values. The evaluation services
return each engine result paired with the feature state it came from, and
evaluated-path serialisers read evaluated fields from the former and stored
fields from the latter. Environment flags are evaluated too, without
segments, so their output is unchanged.
… overrides

The identity overrides pseudo-segment always matches, so every segment was
reported as a member for an identity with overrides. Evaluating once per
payload also stops the query count from growing with the number of segments.

Also tighten the rollout split assertion, and cover the analytics
integrations reporting evaluated rather than stored values.
@khvn26
khvn26 force-pushed the stack/2-identity-evaluation branch from 69b7b83 to dd18806 Compare September 24, 2026 18:19
@github-actions github-actions Bot added feature New feature or request and removed feature New feature or request labels Sep 24, 2026
The engine only splits between variants for an identity, so environment
flags no longer query them.
@github-actions github-actions Bot added feature New feature or request and removed feature New feature or request labels Sep 24, 2026
@github-actions github-actions Bot added feature New feature or request and removed feature New feature or request labels Sep 24, 2026

This branch has not been deployed

No deployments
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.

2 participants