Commit da6abc0
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- packages
- account-tree-controller
- accounts-controller
- address-book-controller
- analytics-controller
- approval-controller
- assets-controllers
- base-controller
- bridge-controller
- bridge-status-controller
- build-utils
- chain-agnostic-permission
- claims-controller
- controller-utils
- core-backend
- delegation-controller
- eip-5792-middleware
- eip-7702-internal-rpc-middleware
- eip1193-permission-middleware
- ens-controller
- eth-block-tracker
- eth-json-rpc-middleware
- eth-json-rpc-provider
- gas-fee-controller
- gator-permissions-controller
- json-rpc-engine
- json-rpc-middleware-stream
- keyring-controller
- message-manager
- multichain-account-service
- multichain-api-middleware
- multichain-network-controller
- multichain-transactions-controller
- name-controller
- network-controller
- network-enablement-controller
- notification-services-controller
- permission-controller
- permission-log-controller
- polling-controller
- preferences-controller
- profile-metrics-controller
- profile-sync-controller
- rate-limit-controller
- remote-feature-flag-controller
- src
- utils
- sample-controllers
- seedless-onboarding-controller
- selected-network-controller
- shield-controller
- signature-controller
- storage-service
- subscription-controller
- token-search-discovery-controller
- transaction-controller
- transaction-pay-controller
- user-operation-controller
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| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
64 | 64 | | |
65 | 65 | | |
66 | 66 | | |
67 | | - | |
| 67 | + | |
68 | 68 | | |
69 | 69 | | |
70 | 70 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
58 | 58 | | |
59 | 59 | | |
60 | 60 | | |
61 | | - | |
| 61 | + | |
62 | 62 | | |
63 | 63 | | |
64 | 64 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
61 | 61 | | |
62 | 62 | | |
63 | 63 | | |
64 | | - | |
| 64 | + | |
65 | 65 | | |
66 | 66 | | |
67 | 67 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
51 | 51 | | |
52 | 52 | | |
53 | 53 | | |
54 | | - | |
| 54 | + | |
55 | 55 | | |
56 | 56 | | |
57 | 57 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
50 | 50 | | |
51 | 51 | | |
52 | 52 | | |
53 | | - | |
| 53 | + | |
54 | 54 | | |
55 | 55 | | |
56 | 56 | | |
| |||
0 commit comments