Skip to content

Feature Flags: re-read wpcom overrides after switch_to_blog() - #52555

Closed
dognose24 wants to merge 1 commit into
trunkfrom
fix/wpcom-feature-flags-reset-overrides-on-switch-blog
Closed

dognose24 wants to merge 1 commit into
trunkfrom
fix/wpcom-feature-flags-reset-overrides-on-switch-blog

Conversation

@dognose24

@dognose24 dognose24 commented Sep 21, 2026 •

Copy link
Copy Markdown
Contributor

Proposed changes

Wpcom_Feature_Flags memoizes a site's flag overrides in a static property the first time any flag is resolved, and never re-reads them. On WordPress.com Simple, the public API process resolves flags before it switches to the requested site (premium-analytics-dashboard-composition is checked on init, for one), so the map memoized then is the process's first blog, not the site the request is for. Every override set on Tools → Feature Flags therefore applies in that site's wp-admin but not to its wpcom/v2 REST responses, which is where a Premium Analytics dashboard reads its sections from.

  • Drop the memoized override map on switch_blog, so the next resolution reads the current blog's option.
  • Pin it with a test that resolves a flag, changes the option behind the cache, fires switch_blog, and expects the new value. The bootstrap-wiring test now also checks the switch_blog hook.

Found while testing #52549 on a Simple site: with premium-analytics-a11n-all-sections forced on, the Feature Flags screen reported it effective, yet GET /wpcom/v2/sites/…/dashboards/…/sections kept returning the preview's two tabs. Running the same resolution in the sandbox CLI reproduced it: false after switch_to_blog(), true after reset_overrides_cache().

Related product discussion/links

Does this pull request change what data or activity we track or use?

No.

Testing instructions

Automated:

  • jp test php packages/jetpack-mu-wpcom --filter Wpcom_Feature_Flags

On a WordPress.com Simple sandbox, with a site whose Premium Analytics preview is switched on through its own opt-in and no jetpack-premium-analytics override (Traffic and Insights only), and with #52549 applied:

  1. Sandbox both the site's domain and public-api.wordpress.com.
  2. As an Automattician, open Tools → Feature Flags (a8c), force premium-analytics-a11n-all-sections on, and save.
  3. Open https://public-api.wordpress.com/wpcom/v2/sites/<blog-id>/dashboards/jetpack-premium-analytics_dashboard/sections from the dashboard (or copy the request the tab bar makes).
  4. On trunk, the response still lists only traffic and insights. With this PR, it lists every section the site qualifies for, and the dashboard's tab bar follows.
  5. Set the flag back to Default. The response returns to the two preview tabs.

🤖 Generated with Claude Code

Wpcom_Feature_Flags memoized the override map on the first resolution and
kept it for the rest of the request, even after switch_to_blog(). On
WordPress.com's public API a flag is resolved before the request switches
to the requested site, so that site's overrides never applied to its REST
responses. Drop the cache on switch_blog and pin it with a test.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@github-actions

github-actions Bot commented Sep 21, 2026 •

Copy link
Copy Markdown
Contributor

Are you an Automattician? Please test your changes on all WordPress.com environments to help mitigate accidental explosions.

  • To test on WoA, go to the Plugins menu on a WoA dev site. Click on the "Upload" button and follow the upgrade flow to be able to upload, install, and activate the Jetpack Beta plugin. Once the plugin is active, go to Jetpack > Jetpack Beta, select your plugin (WordPress.com Site Helper), and enable the fix/wpcom-feature-flags-reset-overrides-on-switch-blog branch.
  • To test on Simple, run the following command on your sandbox:
bin/jetpack-downloader test jetpack-mu-wpcom-plugin fix/wpcom-feature-flags-reset-overrides-on-switch-blog

Interested in more tips and information?

  • In your local development environment, use the jetpack rsync command to sync your changes to a WoA dev blog.
  • Read more about our development workflow here: PCYsg-eg0-p2
  • Figure out when your changes will be shipped to customers here: PCYsg-eg5-p2

@github-actions

github-actions Bot commented Sep 21, 2026 •

Copy link
Copy Markdown
Contributor

Thank you for your PR!

When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:

  • ✅ Include a description of your PR changes.
  • ✅ Add a "[Status]" label (In Progress, Needs Review, ...).
  • ✅ Add testing instructions.
  • ✅ Specify whether this PR includes any changes to data or privacy.
  • ✅ Add changelog entries to affected projects

This comment will be updated as you work on your PR and make changes. If you think that some of those checks are not needed for your PR, please explain why you think so. Thanks for cooperation 🤖


Follow this PR Review Process:

  1. Ensure all required checks appearing at the bottom of this PR are passing.
  2. Make sure to test your changes on all platforms that it applies to. You're responsible for the quality of the code you ship.
  3. You can use GitHub's Reviewers functionality to request a review.
  4. When it's reviewed and merged, you will be pinged in Slack to deploy the changes to WordPress.com simple once the build is done.

If you have questions about anything, reach out in #jetpack-developers for guidance!

@dognose24
dognose24 requested a review from louwie17 September 21, 2026 15:25
@github-actions github-actions Bot added the [Status] Needs Author Reply We need more details from you. This label will be auto-added until the PR meets all requirements. label Sep 21, 2026
@dognose24
dognose24 requested a review from enejb September 21, 2026 15:25
@dognose24 dognose24 self-assigned this Sep 21, 2026
@jp-launch-control

jp-launch-control Bot commented Sep 21, 2026 •

Copy link
Copy Markdown

Code Coverage Summary

Coverage changed in 1 file.

File Coverage Δ% Δ Uncovered
projects/packages/jetpack-mu-wpcom/src/features/wpcom-feature-flags/class-wpcom-feature-flags.php 214/225 (95.11%) 0.02% 0 💚

Full summary · PHP report · JS report

@louwie17
louwie17 force-pushed the fix/wpcom-feature-flags-reset-overrides-on-switch-blog branch from 2143e7b to ca77ba2 Compare September 21, 2026 15:45
@dognose24

Copy link
Copy Markdown
Contributor Author

Superseded by #52558, which keys the cache by blog instead of resetting on switch_blog. That avoids the extra option read a switch_to_blog()/restore_current_blog() pair would trigger here, and it covers the same public-api case. Verified locally: #52558's suite passes (54 tests), and its per-blog test fails against this branch's implementation.

@dognose24 dognose24 closed this Sep 21, 2026
@github-actions github-actions Bot removed [Status] Needs Author Reply We need more details from you. This label will be auto-added until the PR meets all requirements. [Status] In Progress labels Sep 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant