fix: RemoteFeatureFlagController client version change cache invalidation#7827
fix: RemoteFeatureFlagController client version change cache invalidation#7827Prithpal-Sooriya wants to merge 6 commits intomainfrom
Conversation
Co-authored-by: prithpal.sooriya <prithpal.sooriya@consensys.net>
|
Cursor Agent can help with this pull request. Just |
Co-authored-by: prithpal.sooriya <prithpal.sooriya@consensys.net>
Co-authored-by: prithpal.sooriya <prithpal.sooriya@consensys.net>
c1f8201 to
016bbe9
Compare
packages/remote-feature-flag-controller/src/remote-feature-flag-controller.ts
Outdated
Show resolved
Hide resolved
packages/remote-feature-flag-controller/src/remote-feature-flag-controller.test.ts
Outdated
Show resolved
Hide resolved
packages/remote-feature-flag-controller/src/remote-feature-flag-controller.test.ts
Show resolved
Hide resolved
- clean up jsdoc comments - add additional assertion that cache is set.
| localOverrides: {}, | ||
| rawRemoteFeatureFlags: {}, | ||
| cacheTimestamp: 0, | ||
| previousClientVersion: undefined, |
There was a problem hiding this comment.
This should be causing a type error 🤔 undefined is strictly disallowed in controller state, we only allow JSON.
There was a problem hiding this comment.
Oh wow interesting! Thanks for tagging, will clean up!
| includeInDebugSnapshot: false, | ||
| usedInUi: false, | ||
| }, | ||
| previousClientVersion: { |
There was a problem hiding this comment.
I'm not sure that we need an extra copy of this, we already have it in the AppMetadataController. Maybe we could get it from there instead?
There was a problem hiding this comment.
Hmm good callout!
Wondering if there is a controller race condition action issue?
- making
this.messenger.call()inside the constructor. - if the AppMetadataController version updates on initialisation before we can grab the previous version number
Will do some testing!
There was a problem hiding this comment.
It wouldn't be a race condition, but it would mean we'd strictly need to construct the AppMetadataController before this one. We try to avoid using actions/events in the constructor for this exact reason, to avoid initialization order requirements.
Could we fetch the AppMetadataController state lazily instead, rather than in the constructor? That would avoid any init order issues.
There was a problem hiding this comment.
Nice, I've refactored to pass in the previous version as a constructor parameter - so we can avoid Action invocation ordering issues.
I will spin up some preview builds to validate, but we can initialise this controller with:
// Last persisted version of the app
const prevClientVersion =
persistedState.AppMetadataController?.currentAppVersion;
const controller = new RemoteFeatureFlagController({
...
prevClientVersion,
})| disabled = false, | ||
| getMetaMetricsId, | ||
| clientVersion, | ||
| prevClientVersion, |
There was a problem hiding this comment.
Now stateless. We can pass in a constructor parameter for the previous version.
Example on clients:
// the persisted current app ver is the new prevClientVersion we will pass into the `RemoteFeatureFlagController`.
const prevClientVersion =
persistedState.AppMetadataController?.currentAppVersion;There was a problem hiding this comment.
I'll spin up preview builds on mobile and extension to validate.
…ersion - Introduced optional prevClientVersion to manage feature flag cache invalidation. - Updated JSDoc comments for clarity on new parameter usage.
a4e549b to
6dfa4ae
Compare
|
@metamaskbot publish-preview |
|
Preview builds have been published. See these instructions for more information about preview builds. Expand for full list of packages and versions. |
Explanation
What is the current state of things and why does it need to change?
The
RemoteFeatureFlagControllerdid not invalidate its cache when the client application version changed. This could lead to users receiving stale feature flags after an application upgrade, as the controller would continue to use cached flags from the previous version. This is detailed in [Bug]: Explore feature is not available when upgrading from 7.62.2/7.63.0 to 7.64.0 metamask-mobile#25474.What is the solution your changes offer and how does it work?
This PR introduces a
prevClientVersionproperty to the controller's constructor parameters. On initialization, the controller compares the currentclientVersionandprevClientVersion(passed in the constructor). If these versions differ, the cache is invalidated, forcing a fresh fetch of feature flags.Are there any changes whose purpose might not obvious to those unfamiliar with the domain?
No.
Preview Builds:
References
Checklist
Note
Medium Risk
Changes cache-invalidation behavior in
RemoteFeatureFlagControllerbased on app version, which can increase fetches or alter which flags users receive immediately after upgrades. Risk is limited to this controller’s initialization path and is covered by new unit tests.Overview
Remote feature flag caching now invalidates on app upgrades.
RemoteFeatureFlagControlleraccepts an optionalprevClientVersionand resetscacheTimestampto0when it differs from the currentclientVersion, forcing a fresh fetch instead of using potentially stale cached flags.Adds unit coverage for the version-change scenario and documents the fix in
CHANGELOG.md.Written by Cursor Bugbot for commit 6dfa4ae. This will update automatically on new commits. Configure here.