Skip to content

Search: decouple AI Answer block from jetpack_search_ai_answers_enabled (RSM-3608) - #48993

Merged
kangzj merged 2 commits into
trunkfrom
raven/rsm-3608-decouple-ai-answer-block
May 20, 2026
Merged

kangzj merged 2 commits into
trunkfrom
raven/rsm-3608-decouple-ai-answer-block

Conversation

@kangzj

@kangzj kangzj commented May 20, 2026

Copy link
Copy Markdown
Contributor

Fixes RSM-3608. Follow-up to #48986 (this PR is stacked on top of raven/rsm-3591-ai-answer-block and targets it as base — once #48986 lands on trunk, this branch can be rebased onto trunk).

Why

When the AI Answer block ships, the site-wide jetpack_search_ai_answers_enabled option will simultaneously control two unrelated decisions: whether the instant-search overlay fires AI Answers (where the option is the right gate — the overlay is the default UX on any search page), and whether an embedded jetpack-search/ai-answer block that an author explicitly inserted should render (where the block's presence in saved post content already is the opt-in signal). That coupling was flagged in #48986 (review).

This PR keeps the option's role for the overlay and removes it from the block path. To opt out of AI Answers for an embedded surface, an author removes the block — not flips a global flag.

Proposed changes

  • projects/packages/search/src/search-blocks/blocks/ai-answer/render.php — drop the AI_Answers::is_enabled() early return. The block renders whenever it's present in post content.
  • projects/packages/search/src/search-blocks/class-search-blocks.php build_initial_state() — drop the aiAnswersEnabled seed key; no block-side consumer reads it anymore.
  • projects/packages/search/src/search-blocks/store/index.js:
    • Remove the aiAnswersEnabled guards in actions.fetchAiAnswer() and actions.showExtendedAiAnswer(). The fetch is still gated by the aiBlockPresent module flag (set when the block mounts) plus the standard query-length + same-query memo.
    • Remove the aiAnswersEnabled clause from the aiPanelHidden getter — visible status alone determines panel visibility.
  • Tests: drop the option-related setup and the test_disabled_renders_nothing PHP case; add test_renders_panel_wrapper_independent_of_site_option that exercises render with the option off / unset / on. Drop the matching JS tests; the rest stop setting state.aiAnswersEnabled since it no longer exists.

Overlay behaviour is unchanged — class-helper.php still localizes aiAnswersEnabled for the overlay, and search-app.jsx::getAiAnswer still consults it.

Related product discussion/links

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

No. Same POST https://public-api.wordpress.com/wpcom/v2/ai/agent/jetpack-workflow-search_summarizer endpoint, same request shape, same site/query/filter payload. The only change is when the block's view bundle decides to call it — block presence on a page now suffices, the site option no longer overrides it.

Verification

The change is functional (a removed gate) rather than visual. Verified live on the raven docker env (https://jp-raven.jurassic.tube/):

Server-side render is independent of the option
# Option off:
$ wp option update jetpack_search_ai_answers_enabled 0
Success: Updated 'jetpack_search_ai_answers_enabled' option.

$ curl -s "http://localhost:18120/rsm-3591-ai-answer-block-fixture/?q=wordpress" \
    | grep -c "wp-block-jetpack-search-ai-answer\|jp-search-answers-panel"
43

# Option on:
$ wp option update jetpack_search_ai_answers_enabled 1
Success: Updated 'jetpack_search_ai_answers_enabled' option.

(On trunk + parent PR #48986, the same curl against an option-off site returns 0 — the gate was emitting nothing.)

Client-side: AI fetch fires + panel renders with the option off
// After visiting /rsm-3591-ai-answer-block-fixture/?q=wordpress
// with `jetpack_search_ai_answers_enabled = 0`:
{
  "aiAnswersEnabled": undefined,                              // ← no longer seeded
  "aiBriefStatus": "done",                                    // ← SSE fetch ran to completion
  "aiBriefTextPreview": "The results show two WordPress…",    // ← actual streamed content
  "panelHidden": false,                                       // ← panel visible
  "contentHidden": false                                      // ← content section visible
}
Unit tests
$ composer phpunit -- --filter Ai_Answer_Render_Test
OK (8 tests, 17 assertions)

$ npx jest tests/js/search-blocks/ai-answer-edit.test.jsx tests/js/search-blocks/ai-answers-store.test.js
Test Suites: 2 passed, 2 total
Tests:       24 passed, 24 total

Testing instructions

  1. Build the matrix: pnpm jetpack build packages/my-jetpack && pnpm jetpack build plugins/jetpack && pnpm jetpack build packages/search && pnpm jetpack build plugins/search.
  2. Bring up a docker / Jurassic Ninja env with this branch installed.
  3. Create a page containing the embedded AI Answer block:
    <!-- wp:jetpack-search/search-input /-->
    <!-- wp:jetpack-search/ai-answer /-->
    <!-- wp:jetpack-search/search-results -->
    <!-- wp:jetpack-search/results-list /-->
    <!-- /wp:jetpack-search/search-results -->
    

Verify each acceptance criterion from the issue:

  • With wp option update jetpack_search_ai_answers_enabled 0, visiting the page with ?q=wordpress still renders the AI Answer panel and the SSE fetch still fires.
  • With wp option update jetpack_search_ai_answers_enabled 0, the instant-search overlay (on the default /?s=wordpress route) still does NOT fire its AI Answers. (Unchanged behaviour — the overlay still reads window.SERVER_OBJECT_NAME.aiAnswersEnabled from class-helper.php.)
  • All existing PHP + JS tests for the block still pass. None were added that re-introduce the option gate.
  • No regressions in the overlay's AI Answers panel (toggle the option, refresh the overlay-backed search page).

@kangzj kangzj added [Status] In Progress [Plugin] Search A plugin to add an instant search modal to your site to help visitors find content faster. [Package] Search Contains core Search functionality for Jetpack and Search plugins labels May 20, 2026
@kangzj kangzj self-assigned this May 20, 2026
@kangzj

This comment has been minimized.

@kangzj

This comment has been minimized.

@github-actions

github-actions Bot commented May 20, 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 (Jetpack), and enable the raven/rsm-3608-decouple-ai-answer-block branch.
  • To test on Simple, run the following command on your sandbox:
bin/jetpack-downloader test jetpack raven/rsm-3608-decouple-ai-answer-block

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

@claude

This comment has been minimized.

@github-actions

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!


Search plugin:

No scheduled milestone found for this plugin.

If you have any questions about the release process, please ask in the #jetpack-releases channel on Slack.

This comment has been minimized.

Copilot finished work on behalf of kangzj May 20, 2026 05:10
@kangzj

This comment has been minimized.

@kangzj

This comment has been minimized.

@kangzj

This comment has been minimized.

@claude

This comment has been minimized.

This comment has been minimized.

Base automatically changed from raven/rsm-3591-ai-answer-block to trunk May 20, 2026 05:19
Copilot finished work on behalf of kangzj May 20, 2026 05:20
@kangzj

kangzj commented May 20, 2026

Copy link
Copy Markdown
Contributor Author

@copilot rebase the pr

kangzj added 2 commits May 20, 2026 17:27
…ed (RSM-3608)

The block was previously gated by the site-wide
`jetpack_search_ai_answers_enabled` option (via `AI_Answers::is_enabled()`):
on `render.php` it bailed to an empty string, in the seeded Interactivity
state `aiAnswersEnabled` shadowed it, and `fetchAiAnswer` /
`showExtendedAiAnswer` / the `aiPanelHidden` getter all consulted the
flag. That coupled two unrelated decisions: whether the *overlay* AI
Answers fires (where the option is the right gate, because the overlay
is the default UX on any search page), and whether the *embedded block*
an author explicitly inserted into post content should render (where
block presence already *is* the opt-in signal).

This change makes the block stand on its own:

* `render.php`: drop the `AI_Answers::is_enabled()` early return. The
  block renders whenever it's present in post content.
* `Search_Blocks::build_initial_state()`: drop the `aiAnswersEnabled`
  seed key — no block-side consumer reads it.
* `store/index.js`:
  * Remove the `aiAnswersEnabled` guards in `actions.fetchAiAnswer()`
    and `actions.showExtendedAiAnswer()`. The fetch is already gated
    by `aiBlockPresent` (set when the block mounts) plus the standard
    query-length + same-query memo.
  * Remove the `aiAnswersEnabled` clause from `aiPanelHidden`. Visible
    status alone determines whether the panel reserves space.
* Tests: drop the `update_option / delete_option` setup and the
  `test_disabled_renders_nothing` PHP case; add a single test that
  asserts the block renders with the option off, unset, and on.
  Drop the matching JS tests; the rest stop setting
  `state.aiAnswersEnabled` since it no longer exists.

Overlay behaviour is unchanged — `class-helper.php` still localizes
`aiAnswersEnabled` for the overlay surface, and the overlay's
`search-app.jsx` still consults it.
…comment (RSM-3608)

The comment listed the gates fetchAiAnswer() consults — but the
'enable-flag' (aiAnswersEnabled) check was removed in the parent commit.
Update the list to just 'query length (≥ 3 chars) + same-query memo'.
@kangzj
kangzj force-pushed the raven/rsm-3608-decouple-ai-answer-block branch from 9e2907d to 34d5036 Compare May 20, 2026 05:29

This comment has been minimized.

Copilot finished work on behalf of kangzj May 20, 2026 05:30
@kangzj

This comment has been minimized.

@claude

This comment has been minimized.

@jp-launch-control

Copy link
Copy Markdown

Code Coverage Summary

Coverage changed in 3 files.

File Coverage Δ% Δ Uncovered
projects/packages/search/src/search-blocks/blocks/ai-answer/render.php 109/109 (100.00%) 0.00% 0 💚
projects/packages/search/src/search-blocks/class-search-blocks.php 463/628 (73.73%) -0.04% 0 💚
projects/packages/search/src/search-blocks/store/index.js 424/495 (85.66%) 0.09% -1 💚

Full summary · PHP report · JS report

@kangzj

kangzj commented May 20, 2026

Copy link
Copy Markdown
Contributor Author

🤖 Review-cycle summary — 63571d72a5 → 34d5036502179583db9dc2e6b5a776ef845bf844

4 round(s); CI green (62/62 required checks passing); rebased onto fresh trunk after parent #48986 merged mid-loop; 1 review item from claude[bot] addressed; both bots returned clean LGTMs.

What changed during the cycle

Commits on this PR (after rebase):

  • 63571d72a5 — Search: decouple AI Answer block from jetpack_search_ai_answers_enabled (RSM-3608)
  • 34d5036502 — Address review: drop stale 'enable-flag' from the search() call-site comment (RSM-3608)

Diff vs trunk: 6 files changed, 53 insertions(+), 74 deletions(-)

Review items addressed:

Source Item Resolution
claude[bot] Stale "enable-flag" reference in store/index.js:987 call-site comment for actions.fetchAiAnswer() (the aiAnswersEnabled check was removed by this PR but the comment still listed it as a gate) Updated to "query length (≥ 3 chars) + same-query memo" in 34d5036502

Mid-loop rebase: parent PR #48986 merged at 05:19. This PR (originally based on raven/rsm-3591-ai-answer-block) was rebased --onto trunk f73bb49bca to drop the now-merged parent commits, and the PR's base branch was switched from the (now-deleted) feature branch to trunk. Tests + build re-verified clean against the new base.

Unaddressed: none.

CI: all 62 required checks passing.

@kangzj kangzj added [Status] Needs Team Review Obsolete. Use Needs Review instead. and removed [Status] In Progress labels May 20, 2026
@kangzj
kangzj merged commit cd6e6f6 into trunk May 20, 2026
77 checks passed
@kangzj
kangzj deleted the raven/rsm-3608-decouple-ai-answer-block branch May 20, 2026 21:33
@github-actions github-actions Bot added [Status] UI Changes Add this to PRs that change the UI so documentation can be updated. and removed [Status] Needs Team Review Obsolete. Use Needs Review instead. labels May 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Package] Search Contains core Search functionality for Jetpack and Search plugins [Plugin] Search A plugin to add an instant search modal to your site to help visitors find content faster. [Status] UI Changes Add this to PRs that change the UI so documentation can be updated. [Tests] Includes Tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants