Automattic / Automattic/jetpack

AI Assistant feature endpoint returns 500 on unconnected Jetpack sites

Open
#52,066 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
PHP
Stars
1.8k
Forks
898
Avg merge
1d 18h
Merged PRs (30d)
774

Description

### Impact

Opening the block editor on a local site with Jetpack active but not connected produces an avoidable REST 500 and console error:

```text
GET /wp-json/wpcom/v2/jetpack-ai/ai-assistant-feature?_locale=user 500
{ "code": "failed_to_fetch_data", "message": "Unable to fetch the requested data.", "data": { "status": "" } }
```

This is separate from the duplicate data-store registration warnings tracked in #49772.

### Reproduction

1. Create a fresh local WordPress site.
2. Activate Jetpack without connecting the site to WordPress.com.
3. Log in as an administrator and open the block editor.
4. Inspect the browser network requests and console.

Tested with Jetpack 16.1.3. The same backend path is still present on current `trunk`.

### Root-cause evidence

`Jetpack_Options::get_option( 'id' )` has no value on the unconnected site. `Jetpack_AI_Helper::get_ai_assistance_feature()` formats that value with `%d`, then requests:

```text
/sites/0/jetpack-ai/ai-assistant-feature
```

The unsuccessful request has no numeric response status. The helper wraps it in a `WP_Error` whose `data.status` is empty, and the local REST endpoint surfaces it as HTTP 500.

Relevant code:

- `projects/plugins/jetpack/_inc/lib/class-jetpack-ai-helper.php`
- `projects/plugins/jetpack/_inc/lib/core-api/wpcom-endpoints/class-wpcom-rest-api-v2-endpoint-ai.php`

### Expected behavior

An unconnected site should avoid the WordPress.com feature request or return a valid non-error/default feature response. Merely opening the editor should not produce a REST 500.

### AI assistance

OpenAI GPT-5.6 Sol via OpenCode reproduced the browser failure, isolated the request, inspected the site connection state, checked current Jetpack trunk, and traced the endpoint to the missing site ID.

Contributor guide

Open the contributing guide

Research direction

Start in projects/plugins/jetpack/_inc/lib/class-jetpack-ai-helper.php and trace get_ai_assistance_feature(), then inspect projects/plugins/jetpack/_inc/lib/core-api/wpcom-endpoints/class-wpcom-rest-api-v2-endpoint-ai.php. Reproduce the request on an unconnected local site and verify the missing site ID no longer causes a REST 500; the endpoint should skip the WordPress.com request or return a valid default response.

Written by the indexing model from the issue text.

Assessment

Tech stack
php
Domain
api, backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
74/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.