Skip to content

Commit da6abc0

Browse files
MarioAslauGudahtt
andauthored
feat: Make A/B tests independent (#7511)
## Explanation <!-- Thanks for your contribution! Take a moment to answer these questions so that reviewers have the information they need to properly understand your changes: * What is the current state of things and why does it need to change? * What is the solution your changes offer and how does it work? * Are there any changes whose purpose might not obvious to those unfamiliar with the domain? * If your primary goal was to update one package but you found you had to update another one along the way, why did you do so? * If you had to upgrade a dependency, why did you do so? --> Right now, only the ID is used as a seed to determine what bucket the user falls into in an A/B test. Due to this, if there’s more than 1 A/B test configured, they will never be independent of each other **Solution:** Optimizes threshold-based feature flag processing to ensure independent user assignment across different flags. Define the distribution using profile/metametrics ID + A/B test ID as a seed instead of just profile/metametrics ID **Key changes:** - Use sha256 from @metamask/[email protected] to generate unique threshold per flag (native crypto.subtle.digest - 10-100x faster) - Persist threshold values in controller state to avoid recalculating on app restart - Skip cryptographic operations for non-threshold arrays - Batch cache updates and cleanup into single state change - Automatically remove stale cache entries when flags are deleted - Remove @noble/hashes dependency (now available in @metamask/utils) ## References <!-- Are there any issues that this pull request is tied to? Are there other links that reviewers should consult to understand these changes better? Are there client or consumer pull requests to adopt any breaking changes? For example: * Fixes #12345 * Related to #67890 --> ## Checklist - [x] I've updated the test suite for new or updated code as appropriate - [x] I've updated documentation (JSDoc, Markdown, etc.) for new or updated code as appropriate - [ ] I've communicated my changes to consumers by [updating changelogs for packages I've changed](https://github.com/MetaMask/core/tree/main/docs/contributing.md#updating-changelogs) - [ ] I've introduced [breaking changes](https://github.com/MetaMask/core/tree/main/docs/breaking-changes.md) in this PR and have prepared draft pull requests for clients and consumer packages to resolve them <!-- CURSOR_SUMMARY --> --- > [!NOTE] > Implements per-flag deterministic A/B assignment with cached thresholds in the Remote Feature Flag Controller and upgrades @metamask/utils to ^11.9.0 repo-wide. > > - **Remote Feature Flag Controller**: > - Implement per-flag threshold selection using `sha256(metaMetricsId + flagName)` via `@metamask/utils@^11.9.0`. > - Add `thresholdCache` to state; batch cache updates and clean up stale entries; skip processing for non-threshold arrays. > - Update tests and expectations; remove reliance on external hashing utility. > - **Dependencies**: > - Upgrade `@metamask/utils` to `^11.9.0` across packages (yarn.lock updated). > > <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit 297369a. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup> <!-- /CURSOR_SUMMARY --> --------- Co-authored-by: Mark Stacey <[email protected]>
1 parent 1bb6d53 commit da6abc0

File tree

116 files changed

+952
-134
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

116 files changed

+952
-134
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464
"@metamask/eth-json-rpc-provider": "^6.0.0",
6565
"@metamask/json-rpc-engine": "^10.2.0",
6666
"@metamask/network-controller": "^27.1.0",
67-
"@metamask/utils": "^11.8.1",
67+
"@metamask/utils": "^11.9.0",
6868
"@ts-bridge/cli": "^0.6.4",
6969
"@types/jest": "^27.4.1",
7070
"@types/lodash": "^4.14.191",

packages/account-tree-controller/CHANGELOG.md

Lines changed: 1 addition & 0 deletions

packages/account-tree-controller/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
"@metamask/snaps-sdk": "^9.0.0",
5959
"@metamask/snaps-utils": "^11.0.0",
6060
"@metamask/superstruct": "^3.1.0",
61-
"@metamask/utils": "^11.8.1",
61+
"@metamask/utils": "^11.9.0",
6262
"fast-deep-equal": "^3.1.3",
6363
"lodash": "^4.17.21"
6464
},

packages/accounts-controller/CHANGELOG.md

Lines changed: 1 addition & 0 deletions

packages/accounts-controller/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@
6161
"@metamask/snaps-sdk": "^9.0.0",
6262
"@metamask/snaps-utils": "^11.0.0",
6363
"@metamask/superstruct": "^3.1.0",
64-
"@metamask/utils": "^11.8.1",
64+
"@metamask/utils": "^11.9.0",
6565
"deepmerge": "^4.2.2",
6666
"ethereum-cryptography": "^2.1.2",
6767
"immer": "^9.0.6",

packages/address-book-controller/CHANGELOG.md

Lines changed: 1 addition & 0 deletions

packages/address-book-controller/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
"@metamask/base-controller": "^9.0.0",
5252
"@metamask/controller-utils": "^11.17.0",
5353
"@metamask/messenger": "^0.3.0",
54-
"@metamask/utils": "^11.8.1"
54+
"@metamask/utils": "^11.9.0"
5555
},
5656
"devDependencies": {
5757
"@metamask/auto-changelog": "^3.4.4",

packages/analytics-controller/CHANGELOG.md

Lines changed: 4 additions & 0 deletions

packages/analytics-controller/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
"dependencies": {
5151
"@metamask/base-controller": "^9.0.0",
5252
"@metamask/messenger": "^0.3.0",
53-
"@metamask/utils": "^11.8.1"
53+
"@metamask/utils": "^11.9.0"
5454
},
5555
"devDependencies": {
5656
"@metamask/auto-changelog": "^3.4.4",

packages/approval-controller/CHANGELOG.md

Lines changed: 4 additions & 0 deletions

0 commit comments

Comments
 (0)