My Jetpack: chat authentication caches failed WordPress.com responses and emits an invalid status
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 45/100
Research direction
First settle whether the orphaned chat routes should remain, since removing them would make this fix unnecessary. If they remain, inspect REST_Zendesk_Chat in projects/packages/my-jetpack and compare the response-code checks in class-rest-purchases.php and class-rest-recommendations-evaluation.php. Locate the tests for both handlers, then verify failed non-200 responses are not cached, healthy retries recover, and emitted statuses are valid.
Written by the indexing model from the issue text.
Description
REST_Zendesk_Chat in projects/packages/my-jetpack treats any non-empty response body from WordPress.com as a success, and emits an invalid HTTP status when the request fails.
Failed responses are cached
get_chat_authentication() guards only on is_wp_error() and an empty body:
if ( is_wp_error( $response ) || empty( $response['body'] ) ) {
return new WP_Error( 'chat_authentication_failed', … );
}
set_transient( $transient_key, $body, self::TRANSIENT_EXPIRY );
A 4xx or 5xx from WordPress.com that returns a body passes that guard and is stored in the transient cache, so a single failed upstream response can be served from cache for the full one-week TTL rather than being retried.
The emitted status is not a valid HTTP status
wp_remote_retrieve_response_code() is called before the is_wp_error() check, so a transport error (for example a missing user token) yields '', and the REST server emits status 0. WP_REST_Response::is_error() returns false for that, so a failed request can read as a success to a client.
get_chat_availability() has the identical shape in its chat_config_data_fetch_failed path.
What the fix should entail
Fail on any non-200, don't cache it, and emit a valid status. Both handlers already compute $response_code, so it is a matter of including it in the existing guard and falling back when it is empty:
if ( is_wp_error( $response ) || empty( $response['body'] ) || 200 !== $response_code ) {
return new WP_Error( '…', '…', array( 'status' => $response_code ? $response_code : 400 ) );
}
is_wp_error() must stay first so the $response['body'] access remains short-circuited.
This matches the convention already used elsewhere in the same package — class-rest-purchases.php and class-rest-recommendations-evaluation.php both gate on 200 !== $response_code.
Worth covering with tests, for both handlers, that a non-200 is not cached, that a caller recovers once the upstream is healthy again, and that the emitted status is valid.
Worth deciding first
Both chat/* routes look orphaned. No JS in the monorepo calls chat/authentication or chat/availability — the ZendeskChat component and its queries were removed in #42477 — and the endpoint constants at projects/packages/my-jetpack/_inc/data/constants.ts (REST_API_CHAT_AVAILABILITY_ENDPOINT, REST_API_CHAT_AUTHENTICATION_ENDPOINT) are declared but never imported. The routes are still registered in Initializer and callable by any logged-in user.
If the intent is to remove the routes rather than keep them, that would make this moot, so it is probably worth settling that before fixing the caching.
- Dominant language
- PHP
- Stars
- 1.9k
- Forks
- 913
- Avg merge
- 1d 18h
- Merged PRs (30d)
- 809
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from Automattic/jetpack
-
Bug Needs triage
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
Automattic/jetpack#55870 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
Automattic/jetpack#55385 · 1 comment ·
Maintainers usually reply within 1 day
-
WAF: jetpack_waf_blocklog is created without the site's charset and collationPossibly taken @jwebbdev claimed this 3 days ago. Open[Plugin] Protect Bug Customer Report
Difficulty 1/5 Under an hour Newbie friendliness 85/100
Automattic/jetpack#55365 · 1 assignee ·
Maintainers usually reply within 1 day
-
[Package] Stats Admin [Type] Bug
Difficulty 1/5 Under an hour Newbie friendliness 86/100
Automattic/jetpack#54188 ·
Maintainers usually reply within 1 day
-
Bug Needs triage
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
Automattic/jetpack#53467 ·
Maintainers usually reply within 1 day
All issues in Automattic/jetpack
Similar issues
-
follow-up
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Maintainers usually reply within 1 day
-
Invoice reminders more than a month after the due date, and bill reminders more than a month before it, are not sentPossibly taken @officialasishkumar claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
Automattic/blocks-engine#7881 ·
Maintainers usually reply within 1 day
-
[FrameworkBundle] MicroKernelTrait lists BundleAdapter instead of the bundle class in kernel.bundlesPossibly taken A pull request linked to this issue is open or already merged. OpenBug FrameworkBundle Status: Needs Review
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
Maintainers usually reply within 1 day
-
[Flaky Test] testMonitorCallbackReturnExitsPossibly taken @uintaam claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
valkey-io/valkey-glide-php#515 ·
Maintainers usually reply within 4 days