feat(remote-feature-flag-controller): segment threshold flags by idType with canonical ID default#9325
feat(remote-feature-flag-controller): segment threshold flags by idType with canonical ID default#9325asalsys wants to merge 4 commits into
Conversation
…y and support canonical id segmentation Threshold flags now expose selected values directly, track group names in featureFlagThresholdGroups, and can use getCanonicalId when idType is canonical. Co-authored-by: Cursor <cursoragent@cursor.com>
…nd changelog links Default threshold segmentation to canonical ID, link changelog entries to PR #9325, add wallet changelog entry, and fix ESLint violations. Co-authored-by: Cursor <cursoragent@cursor.com>
| const firstThresholdEntry = flagValue.find(isFeatureFlagWithScopeValue); | ||
|
|
||
| return firstThresholdEntry?.idType ?? FeatureFlagIdType.Canonical; | ||
| } |
There was a problem hiding this comment.
issue (blocking): idType is modeled as a per-entry property, but getThresholdIdType determines the segmentation ID by looking only at the first valid threshold entry. That means a mixed configuration silently uses the first entry's idType for the entire flag, making the behavior dependent on entry ordering.
If mixed idType values are not intended, it would be safer to validate that all threshold entries agree and fail fast (or move idType to a flag-level configuration). Otherwise, please add a test documenting the intended behavior for mixed configurations.
| idType?: FeatureFlagIdType; | ||
| /** | ||
| * Selects the threshold entry output shape. Unrecognized versions fall back | ||
| * to the legacy `{ name, value }` wrapper for backwards compatibility. |
There was a problem hiding this comment.
nitpick (non-blocking): This comment still says unrecognized threshold versions fall back to the legacy { name, value } wrapper, but this PR removes that behavior and now always returns the selected value directly. The documentation should be updated to match the implementation.
Summary
FeatureFlagIdType(metametrics|canonical) and optionalidTypeon threshold entries so each flag can choose which client identifier drives deterministic bucket assignment.getCanonicalIdconstructor callback. Threshold processing usesgetCanonicalId()by default whenidTypeis omitted, andgetMetaMetricsId()whenidTypeismetametrics.valuedirectly fromremoteFeatureFlagsinstead of a{ name, value }wrapper object.featureFlagThresholdGroupsstate field (Record<string, string>) that maps feature flag names to their selected threshold group name when the selected threshold entry includesname.normalizeThresholdValueand the legacy{ name, value }wrapper fallback.idType behavior
idTypeon threshold entrygetCanonicalId()"canonical"getCanonicalId()"metametrics"getMetaMetricsId()If the configured identifier is empty, threshold arrays are preserved as-is and not processed.
Example threshold config using canonical segmentation (default):
[ { "name": "groupA", "scope": { "type": "threshold", "value": 0.5 }, "value": "valueA" }, { "idType": "metametrics", "name": "legacyGroup", "scope": { "type": "threshold", "value": 1.0 }, "value": "legacyValue" } ]Migration
Threshold segmentation
Consumers must pass
getCanonicalIdwhen using threshold flags that rely on canonical segmentation (the default). PassgetMetaMetricsIdas before for flags explicitly configured withidType: "metametrics".Threshold value shape
Consumers that previously read threshold group names from
remoteFeatureFlags[flagName].nameshould instead:remoteFeatureFlags[flagName].featureFlagThresholdGroups[flagName]when available.Before:
After:
Test plan
yarn workspace @metamask/remote-feature-flag-controller run test— all tests pass with 100% coveragegetCanonicalIdwhenidTypeis omittedidType: "metametrics"usegetMetaMetricsIdfor segmentationidType: "canonical"usegetCanonicalIdfor segmentationfeatureFlagThresholdGroupswhen the selected entry includesnamefeatureFlagThresholdGroupsand threshold cache entries are cleaned up when flags are removed from the server responseRelated
Note
High Risk
Breaking changes to threshold flag shapes and default segmentation (canonical vs MetaMetrics) affect all consumers of remote feature flags and experiment assignment across extension/mobile.
Overview
Threshold feature flags can now choose which client ID drives deterministic bucketing via optional
idTypeon threshold entries (FeatureFlagIdType: canonical by default, ormetametrics). The controller accepts an optionalgetCanonicalIdcallback (defaults to empty string) and uses#getSegmentationIdplusgetThresholdIdTypeso cache keys and hashing use MetaMetrics or canonical ID as configured; if the chosen ID is missing, threshold arrays are left unprocessed.BREAKING: Processed threshold flags expose the selected
valuedirectly inremoteFeatureFlagsinstead of a{ name, value }object. The chosen groupnameis stored in new optional statefeatureFlagThresholdGroups, which is updated and pruned alongsidethresholdCachewhen flags change.@metamask/walletwiresgetCanonicalIdthrough remote feature flag initialization.Reviewed by Cursor Bugbot for commit 18f1728. Bugbot is set up for automated code reviews on this repo. Configure here.