Skip to content

feat: include selected variant key in flag results#314

Open
gagantrivedi wants to merge 1 commit into
mainfrom
feat/multivariate-variant-key
Open

feat: include selected variant key in flag results#314
gagantrivedi wants to merge 1 commit into
mainfrom
feat/multivariate-variant-key

Conversation

@gagantrivedi

@gagantrivedi gagantrivedi commented Jun 4, 2026

Copy link
Copy Markdown
Member

Changes

Every flag result now carries a variant field, mirroring OpenFeature's ResolutionDetails.variant (always present, nullable):

  • the variant's key when a named multivariate variant is selected,
  • "control" when an identity falls in the control bucket (the leftover allocation 100 − Σ weights that resolves to the feature's default value) — the control is not a multivariate option, so the engine synthesises this key,
  • null otherwise — a standard feature, an unkeyed variant, or evaluation without an identity (nothing is bucketed).
{ "name": "checkout_button", "enabled": true, "value": "blue", "reason": "SPLIT; weight=30", "variant": "v_a" }
{ "name": "checkout_button", "enabled": true, "value": "blue", "reason": "DEFAULT",          "variant": "control" }
{ "name": "basic_flag",      "enabled": false, "value": "",    "reason": "DEFAULT",          "variant": null }

Selection logic, hashing and ordering are unchanged. feat: commit → release-please cuts a minor (10.2.0).

Files

  • flag_engine/context/types.py (generated): FeatureValue gains key: NotRequired[str]
  • flag_engine/result/types.py (generated): FlagResult.variant: Optional[str] (required, nullable)
  • flag_engine/segments/evaluator.py: single variant value threaded through one result construction
  • .gitmodules + submodule: corpus bumped to v3.9.0

Test coverage

The behaviour is covered end-to-end by the shared engine-test-data corpus (v3.9.0), so the variant-specific unit test was dropped as redundant:

scenario variant corpus
no identity / standard feature null
unkeyed variant selected null ✓ (SPLIT cases)
control bucket "control"
keyed variant selected the key ✓ (added in v3.9.0)

Landed dependencies

How did you test this code?

Full suite 382 passed against the released v3.9.0 corpus. mypy (strict), black, flake8, isort clean. Generated types verified with datamodel-code-generator 0.33.0 against the merged schema.

Cross-engine note

flagsmith-rust-flag-engine pins an older corpus tag and is unaffected until it adopts v3.9.0; the keyed-variant case is what will catch key passthrough not being implemented there.

@github-actions

github-actions Bot commented Jun 4, 2026

Copy link
Copy Markdown

File Coverage Missing
All files 100%

Minimum allowed coverage is 100%

Generated by 🐒 cobertura-action against 871d63c

@codspeed-hq

codspeed-hq Bot commented Jun 4, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 1 untouched benchmark


Comparing feat/multivariate-variant-key (871d63c) with main (ef90a90)

Open in CodSpeed

@gagantrivedi gagantrivedi force-pushed the feat/multivariate-variant-key branch 2 times, most recently from a293154 to 1f12564 Compare June 8, 2026 10:12
@gagantrivedi gagantrivedi force-pushed the feat/multivariate-variant-key branch from 1f12564 to 8694ce4 Compare June 8, 2026 10:47
@gagantrivedi gagantrivedi marked this pull request as ready for review June 8, 2026 10:47
@gagantrivedi gagantrivedi requested a review from a team as a code owner June 8, 2026 10:47
@gagantrivedi gagantrivedi requested review from khvn26 and removed request for a team June 8, 2026 10:47
@gagantrivedi gagantrivedi requested review from Zaimwa9 and removed request for khvn26 June 8, 2026 10:48
@gagantrivedi gagantrivedi force-pushed the feat/multivariate-variant-key branch 2 times, most recently from a34303f to 8bd1ce1 Compare June 8, 2026 11:00
@gagantrivedi gagantrivedi force-pushed the feat/multivariate-variant-key branch from 8bd1ce1 to 9f61777 Compare June 8, 2026 11:23
Every flag result now carries a `variant` field, mirroring OpenFeature's
`ResolutionDetails.variant` (always present, nullable):

- the variant's key when a named multivariate variant is selected,
- `"control"` when an identity falls in the control bucket (the leftover
  allocation that resolves to the feature's default value); the control is
  not a multivariate option, so the engine synthesises this key,
- `null` otherwise (standard features, unkeyed variants, or evaluation
  without an identity, where nothing is bucketed).

Selection logic, hashing and ordering are unchanged. The behaviour is
covered by the shared engine-test-data corpus, bumped to v3.9.0.
@gagantrivedi gagantrivedi force-pushed the feat/multivariate-variant-key branch from 9f61777 to 871d63c Compare June 8, 2026 11:54
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.

3 participants