Skip to content

Use Agents Manager state endpoint#46937

Open
jom wants to merge 7 commits intotrunkfrom
change/use-wpcom-agents-manager-endpoint
Open

Use Agents Manager state endpoint#46937
jom wants to merge 7 commits intotrunkfrom
change/use-wpcom-agents-manager-endpoint

Conversation

@jom
Copy link
Member

@jom jom commented Feb 3, 2026

Fixes AI-850
Paired with 202452-ghe-Automattic/wpcom

Proposed changes:

  • Switches the Agents Manager Jetpack proxy (WP_REST_Agents_Manager_Persisted_Open_State) from the general /me/preferences endpoint to the new dedicated /wpcom/v2/agents-manager/state endpoint.
  • Removes the calypso_preferences wrapper from both request and response handling — the new endpoint uses flat key/value format.
  • Extracts a DEFAULTS constant for fallback values, reducing duplication between get_state and set_state.
  • Updates class-agents-manager.php to fetch the unified_ai_chat preference from /agents-manager/state instead of /me/preferences.
  • Updates test mocks to match the new endpoint URL.

Why are these changes being made?

  • The general /me/preferences endpoint exposes all calypso preferences, which is unnecessarily broad for Agents Manager.
  • On Jetpack-connected sites, the proxy forwards user-token-authenticated requests to wpcom. Using a dedicated scoped endpoint follows the principle of least privilege — only the Agents Manager keys are accessible.
  • The new endpoint also validates value types on write (booleans, enum for position, structured object for router history).

Other information:

  • Have you written new tests for your changes, if applicable?
  • Have you checked the E2E test CI results, and verified that your changes do not break them?
  • Have you tested your changes on WordPress.com, if applicable (if so, you'll see a generated comment below with a script to run)?

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

No

Testing instructions:

See Automattic/wp-calypso#108636 for testing instructions

@github-actions
Copy link
Contributor

github-actions bot commented Feb 3, 2026

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 change/use-wpcom-agents-manager-endpoint branch.
  • To test on Simple, run the following command on your sandbox:
bin/jetpack-downloader test jetpack-mu-wpcom-plugin change/use-wpcom-agents-manager-endpoint

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
Copy link
Contributor

github-actions bot commented Feb 3, 2026

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!

@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 Feb 3, 2026
@jp-launch-control
Copy link

jp-launch-control bot commented Feb 3, 2026

Code Coverage Summary

Coverage changed in 1 file.

File Coverage Δ% Δ Uncovered
projects/packages/jetpack-mu-wpcom/src/features/agents-manager/class-wp-rest-agents-manager-persisted-open-state.php 18/63 (28.57%) 5.19% -14 💚

Full summary · PHP report

@jom jom requested a review from a team February 18, 2026 00:29
@jom jom 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 Feb 18, 2026
@github-actions github-actions bot added [Status] In Progress [Status] Needs Author Reply We need more details from you. This label will be auto-added until the PR meets all requirements. labels Feb 18, 2026
@jom jom marked this pull request as ready for review February 18, 2026 00:30
Copilot AI review requested due to automatic review settings February 18, 2026 00:30
@jom jom self-assigned this Feb 18, 2026
@jom jom added [Status] Needs Review This PR is ready for review. and removed [Status] In Progress labels Feb 18, 2026
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates the Agents Manager feature to use a new dedicated /wpcom/v2/agents-manager/state API endpoint instead of the general /me/preferences endpoint. The change follows the principle of least privilege by limiting access to only the specific Agents Manager preferences rather than all Calypso preferences.

Changes:

  • Switched REST API proxy endpoint from /me/preferences to /agents-manager/state for persisted state management
  • Removed calypso_preferences wrapper from request/response handling in favor of flat key-value format with a state parameter
  • Extracted a DEFAULTS constant to reduce duplication and centralize default values

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
class-wp-rest-agents-manager-persisted-open-state.php Updated to use new /agents-manager/state endpoint, removed calypso_preferences wrapper, added DEFAULTS constant, improved error handling
class-agents-manager.php Updated fetch_unified_experience_preference() to call /agents-manager/state?key=unified_ai_chat with updated comments
Agents_Manager_Test.php Updated test mocks to check for new endpoint URL /agents-manager/state
changelog entry Added changelog entry documenting the endpoint migration


// The response is the value of the preference directly when using preference_key.
// The response is { "unified_ai_chat": true/false } when using key param.
$result = ! empty( $decoded_body );
Copy link

Copilot AI Feb 18, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The response parsing logic appears incorrect. According to the comment, the response should be { "unified_ai_chat": true/false } when using the key param, but the code uses ! empty( $decoded_body ) which will return true for any non-empty response object, regardless of the actual value of unified_ai_chat.

For example, if the API returns { "unified_ai_chat": false }, this code will incorrectly evaluate to true because the array is not empty. The code should explicitly check the value: $result = ! empty( $decoded_body['unified_ai_chat'] );

Suggested change
$result = ! empty( $decoded_body );
$result = is_array( $decoded_body ) && ! empty( $decoded_body['unified_ai_chat'] );

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[mu wpcom Feature] Agents Manager [Package] Jetpack mu wpcom WordPress.com Features [Status] Needs Author Reply We need more details from you. This label will be auto-added until the PR meets all requirements. [Status] Needs Review This PR is ready for review. [Tests] Includes Tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant