Skip to content

feat(remote-feature-flag-controller): segment threshold flags by metaMetricsFlags with canonical ID default#9325

Open
asalsys wants to merge 11 commits into
mainfrom
feat/remote-feature-flag-threshold-groups-clean
Open

feat(remote-feature-flag-controller): segment threshold flags by metaMetricsFlags with canonical ID default#9325
asalsys wants to merge 11 commits into
mainfrom
feat/remote-feature-flag-threshold-groups-clean

Conversation

@asalsys

@asalsys asalsys commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Add optional getCanonicalProfileId constructor callback and metaMetricsFlags map for threshold flag segmentation.
  • Threshold flags use canonical profile ID by default; flags whose names are present in metaMetricsFlags use MetaMetrics ID instead.
  • Generalize threshold calculation to hash the selected segmentation ID while preserving the existing deterministic bucketing behavior.
  • Pass the new optional segmentation options through @metamask/wallet remote feature flag controller initialization.

Segmentation Behavior

Flag configuration Identifier used Constructor callback
Flag name absent from metaMetricsFlags Canonical profile ID getCanonicalProfileId()
Flag name present in metaMetricsFlags MetaMetrics ID getMetaMetricsId()

If the selected identifier is empty, threshold arrays are preserved as-is and not processed.

Example threshold config using canonical segmentation by default:

{
  "myCanonicalFlag": [
    {
      "name": "groupA",
      "scope": { "type": "threshold", "value": 0.5 },
      "value": "valueA"
    },
    {
      "name": "groupB",
      "scope": { "type": "threshold", "value": 1.0 },
      "value": "valueB"
    }
  ]
}

Example controller setup for a flag that should keep MetaMetrics segmentation:

new RemoteFeatureFlagController({
  // ...
  getMetaMetricsId,
  getCanonicalProfileId,
  metaMetricsFlags: {
    legacyMetaMetricsFlag: true,
  },
});

Migration

Consumers must pass getCanonicalProfileId for threshold flags that should use canonical profile segmentation, which is now the default for flags absent from metaMetricsFlags.

Existing threshold flags that must keep MetaMetrics-based bucketing should be listed in metaMetricsFlags and continue to provide getMetaMetricsId.

Test plan

  • yarn workspace @metamask/remote-feature-flag-controller run jest --no-coverage src/utils/user-segmentation-utils.test.ts src/remote-feature-flag-controller.test.ts
  • Threshold flags absent from metaMetricsFlags use getCanonicalProfileId for segmentation
  • Threshold flags present in metaMetricsFlags use getMetaMetricsId for segmentation
  • Threshold arrays are preserved when the selected identifier is empty
  • Threshold cache entries use the selected segmentation ID and stale entries are cleaned up when flags are removed from the server response

Related


Note

High Risk
Changes default A/B bucketing for threshold flags, so users can land in different groups unless legacy flags are listed in metaMetricsFlags; rollout and cache behavior are user-facing and migration-sensitive.

Overview
Threshold rollout no longer always keys off MetaMetrics ID. RemoteFeatureFlagController now accepts optional getCanonicalProfileId and metaMetricsFlags: flags not listed in the map hash canonicalProfileId + flag name for bucketing and cache keys; flags in the map keep MetaMetrics-based segmentation (for legacy behavior).

When the chosen segmentation ID is empty, threshold arrays are left unprocessed (same as before for missing MetaMetrics). Explicit metaMetricsIds targeting is unchanged but only runs when MetaMetrics ID is available. calculateThresholdForFlag is generalized to any non-empty segmentation ID. Stale thresholdCache cleanup now drops entries for either the current MetaMetrics or canonical ID.

@metamask/wallet forwards the new options into remote feature flag initialization. Tests and changelogs are updated accordingly.

Reviewed by Cursor Bugbot for commit 9c6a7a1. Bugbot is set up for automated code reviews on this repo. Configure here.

…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>
@asalsys asalsys requested review from a team as code owners June 30, 2026 23:04
@asalsys asalsys temporarily deployed to default-branch June 30, 2026 23:04 — with GitHub Actions Inactive
Comment thread packages/remote-feature-flag-controller/src/remote-feature-flag-controller.ts Outdated
@asalsys asalsys changed the title feat(remote-feature-flag-controller): return threshold values directly and track threshold groups feat(remote-feature-flag-controller): segment threshold flags by idType with canonical ID default Jul 1, 2026
…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>
@asalsys asalsys enabled auto-merge July 1, 2026 03:11

@NicolasMassart NicolasMassart left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Two comments, one blocking and a nit.

const firstThresholdEntry = flagValue.find(isFeatureFlagWithScopeValue);

return firstThresholdEntry?.idType ?? FeatureFlagIdType.Canonical;
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

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.

Outdated we are removing idType and passing metaMetricsFlags from the client.

idType?: FeatureFlagIdType;
/**
* Selects the threshold entry output shape. Unrecognized versions fall back
* to the legacy `{ name, value }` wrapper for backwards compatibility.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

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.

Outdated we are removing idType and passing metaMetricsFlags from the client.

@asalsys asalsys changed the title feat(remote-feature-flag-controller): segment threshold flags by idType with canonical ID default feat(remote-feature-flag-controller): segment threshold flags by metaMetricsFlags with canonical ID default Jul 6, 2026

@cursor cursor 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.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit b933ca5. Configure here.

@asalsys asalsys requested a review from NicolasMassart July 6, 2026 21:25
NicolasMassart
NicolasMassart previously approved these changes Jul 7, 2026
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