Skip to content

Connection: Tell the admin when a failed fresh connection has left the site disconnected - #55384

Merged
darssen merged 5 commits into
trunkfrom
connect-627-connection-tell-the-admin-when-a-failed-fresh
Nov 24, 2026
Merged

darssen merged 5 commits into
trunkfrom
connect-627-connection-tell-the-admin-when-a-failed-fresh

Conversation

@darssen

@darssen darssen commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Fixes CONNECT-627

Proposed changes

Creating a fresh connection from Safe Mode disconnects the site first and registers it again second. If registration fails, the site is left disconnected, but the new Safe Mode screen showed the generic "Your site's server ran into a problem" message.

  • identity-crisis/start-fresh: when try_registration() fails, the error keeps its code (cannot_save_secrets, site_inaccessible, …) and gets disconnected: true in its data. Error data that isn't an array (empty, or the HTTP code) is not merged; WP_Error::add_data() keeps it in the response's additional_data. So for an error whose data was the HTTP code (e.g. site_inaccessible), data changes from a number to an object; nothing in the monorepo reads it.
  • Only the registration failure is marked. start_fresh_missing_connection_url and an error from the jetpack_idc_authorization_url filter come after registration succeeded, and the nonce and permission checks run before the disconnect, so they keep today's message.
  • getIdentityCrisisErrorCause() returns a new disconnected cause for it, and IdentityCrisisErrorNotice says the site is now disconnected, and to try again or connect it later in Settings › Connectors.
  • After that error, the screen offers only "Try again": the answers are disabled and Back is hidden, since the site is no longer in Safe Mode.
  • No new tracking property: the failure event in Connection: Record Tracks events on the new Safe Mode screen #55183 sends the cause as error_cause and the real reason as error_code.
  • Flag off: no change. The old screen and the Connectors card don't read the error's data, and its code and message are unchanged.

Related product discussion/links

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

No.

Testing instructions

Use a connected Jetpack site running this branch.

  1. Add a mu-plugin that turns the new screen on and makes registration fail:
    <?php
    add_filter( 'jetpack_feature_flag_enabled_connection-idc-screen', '__return_true' );
    add_filter( 'jetpack_pre_register', fn() => new WP_Error( 'test_registration_failed', 'Forced failure.' ) );
  2. Put the site in Safe Mode:
    wp eval '\Automattic\Jetpack\Identity_Crisis::init()->check_response_for_idc( array( "error_code" => "jetpack_url_mismatch", "wpcom_home" => "https://old-address.example", "wpcom_siteurl" => "https://old-address.example" ) );'
    
  3. Go to Posts. In the Safe Mode notice, pick "The original site", Next, "Give it its own connection" and "Connect separately".
  4. The notice says the site couldn't be registered with WordPress.com again and is now disconnected, with a "Try again" button. In the network tab, the start-fresh response has code: test_registration_failed and data.disconnected: true.
    The site is now disconnected and no longer in Safe Mode.
  5. Remove the jetpack_pre_register line, connect the site again and put it back in Safe Mode (step 2). Run step 3 again: you land on WordPress.com's connect flow.
  6. Repeat step 2. Log out in another tab, then pick "Connect separately" again. The notice keeps the "Your session expired" message.
  7. Flag off: remove the flag line and keep the failure line. Step 6 left the site in Safe Mode, so reload and start fresh from the old screen. It shows the same error as on trunk.

…e site disconnected

Starting a fresh connection from Safe Mode disconnects the site before it
registers again. When registration fails, the endpoint now adds
`disconnected: true` to the error's data, keeping its code, and the new Safe
Mode screen shows its own message for it instead of the generic server error.
@darssen darssen added Enhancement Changes to an existing feature — removing, adding, or changing parts of it [Status] In Progress [Package] Connection [Status] UI Changes Add this to PRs that change the UI so documentation can be updated. [Tests] Includes Tests labels Nov 24, 2026
@darssen darssen self-assigned this Nov 24, 2026
@github-actions

github-actions Bot commented Nov 24, 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 or WordPress.com Site Helper), and enable the connect-627-connection-tell-the-admin-when-a-failed-fresh branch.
  • To test on Simple, run the following command on your sandbox:
bin/jetpack-downloader test jetpack connect-627-connection-tell-the-admin-when-a-failed-fresh
bin/jetpack-downloader test jetpack-mu-wpcom-plugin connect-627-connection-tell-the-admin-when-a-failed-fresh

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
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!

@jp-launch-control

jp-launch-control Bot commented Nov 24, 2026 •

Copy link
Copy Markdown

Code Coverage Summary

Coverage changed in 4 files.

File Coverage Δ% Δ Uncovered
projects/js-packages/connection/components/identity-crisis/error-notice.tsx 6/13 (46.15%) 4.49% 0 💚
projects/js-packages/connection/components/identity-crisis/identity-crisis.tsx 54/58 (93.10%) 0.12% 0 💚
projects/js-packages/connection/hooks/use-identity-crisis-actions/get-error-cause.ts 25/25 (100.00%) 0.00% 0 💚
projects/packages/connection/src/identity-crisis/class-rest-endpoints.php 162/177 (91.53%) 0.10% 0 💚

Full summary · PHP report · JS report

@darssen
darssen marked this pull request as ready for review November 24, 2026 12:52
@darssen
darssen requested a review from a team as a code owner November 24, 2026 12:52
@darssen
darssen requested a balanced review from Copilot and removed request for a team November 24, 2026 12:57

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@bindlegirl
bindlegirl self-requested a review November 24, 2026 13:30
@darssen darssen added [Status] Needs Review This PR is ready for review. and removed [Status] In Progress labels Nov 24, 2026

@bindlegirl bindlegirl left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Tested and found one issue worth addressing. Also confirmed in code review:

  1. After the "disconnected" error, the screen still offers the Safe Mode choices (identity-crisis.tsx:170, L179).

Pressing Back, or picking the other answer on the same step, clears the error (use-identity-crisis-flow.ts:30-35). The new message disappears and the screen goes back to showing Safe Mode choices, although the site is no longer in Safe Mode.
Migrate then reports success and shows "Address update started" on a disconnected site.
Keep Safe Mode saves safe_mode_confirmed. After a reconnect, only the Jetpack plugin clears that setting. So on a site without the Jetpack plugin, the next real Safe Mode starts already confirmed and its notice is hidden.
The old screen has the same hole, but the new screen can now tell this case apart.
Fix: set isDisconnected = actions.error?.cause === 'disconnected', then disabled={ isBusy || isDisconnected } on ChoiceStep and canGoBack={ … && ! isDisconnected }. "Try again" keeps working.

  1. Minor issue: Testing step 2 is empty. It reads "Put the site in Safe Mode:" with nothing after the colon, and steps 5–7 depend on it. A code block probably got dropped.

);
case 'disconnected':
return __(
'Your site couldn’t be registered with WordPress.com again, so it is now disconnected. Try again to connect it, or connect it later from My Jetpack.',

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
'Your site couldn’t be registered with WordPress.com again, so it is now disconnected. Try again to connect it, or connect it later from My Jetpack.',
'Your site couldn’t be registered with WordPress.com again, so it is now disconnected. Try again to connect it, or connect it later from Settings->Connectors->Jetpack Connection',

Woo plugins don't have My Jetpack and Connectors card is the main connection hub so I think we should do it like this? I'm not sure if the format with -> is the best way though.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Nice catch!

I took your wording suggestion, with › instead of -> to match how our other strings write menu paths ("Settings › General"): example "…or connect it later in Settings › Connectors, under Jetpack Connection."

…h connection disconnects the site

Changing the answer or going back cleared the error and offered the Safe Mode
choices again, though the site was no longer in Safe Mode. The message now
points to Settings › Connectors, which every plugin has, instead of My Jetpack.
@darssen

darssen commented Nov 24, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for the review @bindlegirl

Tested and found one issue worth addressing. Also confirmed in code review:

  1. After the "disconnected" error, the screen still offers the Safe Mode choices (identity-crisis.tsx:170, L179).

Pressing Back, or picking the other answer on the same step, clears the error (use-identity-crisis-flow.ts:30-35). The new message disappears and the screen goes back to showing Safe Mode choices, although the site is no longer in Safe Mode. Migrate then reports success and shows "Address update started" on a disconnected site. Keep Safe Mode saves safe_mode_confirmed. After a reconnect, only the Jetpack plugin clears that setting. So on a site without the Jetpack plugin, the next real Safe Mode starts already confirmed and its notice is hidden. The old screen has the same hole, but the new screen can now tell this case apart. Fix: set isDisconnected = actions.error?.cause === 'disconnected', then disabled={ isBusy || isDisconnected } on ChoiceStep and canGoBack={ … && ! isDisconnected }. "Try again" keeps working.

Addressed in e3077e4. Once the error says the site is disconnected, the answers are disabled, and Back is hidden, so only "Try again" remains. Added a screen test for it.

  1. Minor issue: Testing step 2 is empty. It reads "Put the site in Safe Mode:" with nothing after the colon, and steps 5–7 depend on it. A code block probably got dropped.

Added an wp eval command in step 2.

…on-tell-the-admin-when-a-failed-fresh

# Conflicts:
#	projects/js-packages/connection/components/identity-crisis/identity-crisis.tsx
#	projects/js-packages/connection/components/identity-crisis/test/identity-crisis.test.tsx
@darssen
darssen requested a review from bindlegirl November 24, 2026 15:44

@bindlegirl bindlegirl left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Retested. LGTM! Nice work 🚢

@darssen
darssen merged commit c552c03 into trunk Nov 24, 2026
187 of 190 checks passed
@darssen
darssen deleted the connect-627-connection-tell-the-admin-when-a-failed-fresh branch November 24, 2026 16:01
@github-actions github-actions Bot removed the [Status] Needs Review This PR is ready for review. label Nov 24, 2026

@coder-karen coder-karen left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for working on this!

The lock added in the commit e3077e4 introduced an issue: the lock drops if 'try again' fails for another reason.

isDisconnected comes from the latest error, but "site is disconnected" is lasting state. run() calls setError( null ) on each attempt, then sets the new cause:

  1. Start fresh fails: disconnected, options locked.
  2. Try again fails with offline, session, blocked, output or server.
  3. isDisconnected is false: Back and Safe Mode options return, on a disconnected site.

How to replicate: force an error as per the testing steps. Before clicking 'try again', set to offline mode in the browser network tab. Presumably rare case, but still possible.

Suggested fix: keep it in the hook, like isMigrated, and never clear it:

// use-identity-crisis-actions/index.ts
const [ isDisconnected, setIsDisconnected ] = useState( false );
// in catch:
const cause = getIdentityCrisisErrorCause( caught );
if ( cause === 'disconnected' ) {
        setIsDisconnected( true );
}

Add isDisconnected: boolean to IdentityCrisisActions, and use actions.isDisconnected in the screen. Any host using the hook directly then gets it too. Extend the new test with a second, different rejection.


Additionally, closing the Connectors panel removes the lock.

"Close" unmounts the screen, dropping its state. The store still says Safe Mode, because its identityCrisis reducer never changes. Reopening shows the first question with no error. Migrate and Keep Safe Mode can then run on a disconnected site.

Suggested fix could be to hide the screen on Close instead of removing it.


Lastly, "Try again" can delete a connection made in the meantime - for example in testing assuming you have the safe model panels open in one tab and the connectors card in another.

@darssen

darssen commented Nov 24, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for working on this!

The lock added in the commit e3077e4 introduced an issue: the lock drops if 'try again' fails for another reason.

isDisconnected comes from the latest error, but "site is disconnected" is lasting state. run() calls setError( null ) on each attempt, then sets the new cause:

  1. Start fresh fails: disconnected, options locked.
  2. Try again fails with offline, session, blocked, output or server.
  3. isDisconnected is false: Back and Safe Mode options return, on a disconnected site.

How to replicate: force an error as per the testing steps. Before clicking 'try again', set to offline mode in the browser network tab. Presumably rare case, but still possible.

Suggested fix: keep it in the hook, like isMigrated, and never clear it:

// use-identity-crisis-actions/index.ts
const [ isDisconnected, setIsDisconnected ] = useState( false );
// in catch:
const cause = getIdentityCrisisErrorCause( caught );
if ( cause === 'disconnected' ) {
        setIsDisconnected( true );
}

Add isDisconnected: boolean to IdentityCrisisActions, and use actions.isDisconnected in the screen. Any host using the hook directly then gets it too. Extend the new test with a second, different rejection.

Additionally, closing the Connectors panel removes the lock.

"Close" unmounts the screen, dropping its state. The store still says Safe Mode, because its identityCrisis reducer never changes. Reopening shows the first question with no error. Migrate and Keep Safe Mode can then run on a disconnected site.

Suggested fix could be to hide the screen on Close instead of removing it.

Lastly, "Try again" can delete a connection made in the meantime - for example in testing assuming you have the safe model panels open in one tab and the connectors card in another.

Many thanks for the review @coder-karen.

Since I had already merged, and this is safe by being behind a feature flag, I'm tackling this in a newer PR. Will point to this one once it is created.

@darssen

darssen commented Nov 24, 2026

Copy link
Copy Markdown
Contributor Author

@coder-karen Opened #55402 to tackle the issues found in your review. Please take a look when you have some time :)

darssen added a commit that referenced this pull request Nov 25, 2026
…isconnected, and refuse a stale fresh connection (#55402)

* Connection: Keep the Safe Mode screen on Try again once the site is disconnected, and refuse a stale fresh connection

Follow-up to #55384's review. The screen now remembers a failed fresh
connection that left the site disconnected across later failures, and in the
connection store so a remounted screen (Connectors panel Close) remembers it
too. The start-fresh endpoint refuses to disconnect a site that is connected
and no longer in Safe Mode, so a screen left open in another tab can't undo a
connection made since.

* Connection: Mark the store from the Safe Mode actions hook, restore focus, and test the guard's Safe Mode case

Review follow-ups: the hook marks the connection store as soon as the request
fails, so closing the panel mid-request no longer loses it; focus moves to Try
again when the view switches; the notice hides while retrying so a repeated
failure is announced; the reducer skips a no-op update; the README lists
isDisconnected; and a test checks a connected site in Safe Mode can still start
fresh, with the Status cache cleared between tests.

* Connection: Remove the Safe Mode filter the start-fresh test adds

* Connection: Head the disconnected Safe Mode view accordingly and drop the host's actions there

* Connection: Show a Reload view once Safe Mode was resolved elsewhere, instead of Try again

* Connection: Note the Reload view and the screen's flag in the changelog
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Enhancement Changes to an existing feature — removing, adding, or changing parts of it [JS Package] Connection [Package] Connection RNA [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.

4 participants