Skip to content

WPCOM_JSON_API: coerce unrenderable upstream statuses to 502 in output()#50109

Draft
darssen wants to merge 2 commits into
trunkfrom
update/json-api-output-renderable-status
Draft

WPCOM_JSON_API: coerce unrenderable upstream statuses to 502 in output()#50109
darssen wants to merge 2 commits into
trunkfrom
update/json-api-output-renderable-status

Conversation

@darssen

@darssen darssen commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

Proposed changes

WPCOM_JSON_API::output() hands the upstream status straight to WordPress's status_header(), which silently no-ops on any code get_status_header_desc() doesn't recognize508, Cloudflare 52x, and other non-standard upstream/proxy codes. When it no-ops, no status line is sent, and the response falls back to PHP's default 200 OK.

This PR adds a renderable_status_code() helper that maps any status WordPress can't render to a generic 502, applied at both status_header() call sites in output():

  • Renderable codes (400, 404, 500, …) pass through unchanged.
  • Unrenderable codes (508, 52x, 599) become 502 Bad Gateway, so a real error status always goes out.
  • The http_envelope path is untouched — it already sends 200 with the true code in the response body, so the coercion is a no-op there and only affects the raw-status path it is meant to fix.

Related product discussion/links

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

No.

Testing instructions

Unit tests

jetpack docker phpunit jetpack -- --filter=WPCOM_JSON_API_Renderable_Status_Code_Test

13 tests: renderable codes pass through, unrenderable (508, 52x, 599) → 502, numeric-string cast.

Reproduce on a sandbox

  1. Deploy this branch to your sandbox:

    bin/jetpack-downloader test jetpack update/json-api-output-renderable-status
    

WIP

@github-actions

github-actions Bot commented Jul 1, 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 update/json-api-output-renderable-status branch.
  • To test on Simple, run the following command on your sandbox:
bin/jetpack-downloader test jetpack update/json-api-output-renderable-status

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 added [Plugin] Jetpack Issues about the Jetpack plugin. https://wordpress.org/plugins/jetpack/ [Status] In Progress [Tests] Includes Tests labels Jul 1, 2026
@github-actions

github-actions Bot commented Jul 1, 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!


Jetpack plugin:

The Jetpack plugin has different release cadences depending on the platform:

  • WordPress.com Simple releases happen as soon as you deploy your changes after merging this PR (PCYsg-Jjm-p2).
  • WoA releases happen weekly.
  • Releases to self-hosted sites happen monthly:
    • Scheduled release: July 7, 2026
    • Code freeze: July 6, 2026

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

@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 Jul 1, 2026
@darssen darssen changed the title JSON API: coerce unrenderable upstream statuses to 502 in output() (CONNECT-267 problem 2) WPCOM_JSON_API: coerce unrenderable upstream statuses to 502 in output() Jul 1, 2026
@jp-launch-control

Copy link
Copy Markdown

Code Coverage Summary

Coverage changed in 1 file.

File Coverage Δ% Δ Uncovered
projects/plugins/jetpack/class.json-api.php 51/476 (10.71%) 0.19% 0 💚

Full summary · PHP report · JS report

@darssen darssen removed the [Status] Needs Author Reply We need more details from you. This label will be auto-added until the PR meets all requirements. label Jul 1, 2026
@darssen darssen self-assigned this Jul 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Plugin] Jetpack Issues about the Jetpack plugin. https://wordpress.org/plugins/jetpack/ [Status] In Progress [Tests] Includes Tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant