Skip to content

Conversation

@coder-karen
Copy link
Contributor

@coder-karen coder-karen commented Jan 7, 2026

Fixes SYNC-173

Proposed changes:

  • This PR checks that the relevant sync module name key exists in the $progress and $config arrays before attempting to access them. Previously with the warnings we were still processing in send_full_sync_actions (but with empty $status and $config). If we retain the existing behavior and pass null defaults in those cases, we generate more warnings, within class-module.php. So just replicating existing behavior isn't ideal in this case.
  • As an improvement, we also now store $module->name() in a variable, reducing repeated method calls.
  • The changes prevent array key warnings such as Undefined array key "woocommerce_hpos_orders", and also Undefined array key "sent" warnings in class-module.php.
  • The reason the warnings would be happening is because the list of modules to be synced has updated during the running of the function, for example when we calculate $config or $progress initially in send, vs when we get modules in get_remaining_modules_to_send.

There are two other options here:

  • Freeze the module set for a given full sync - for example in get_remaining_modules_to_send we can ensure we don't continue if $status['progress'][ $module_name ] is not set.
  • Alternatively, update the module set during full sync rather than freezing it - so that $progress and $config have the up to date modules.

Why the current approach instead of these?

  • Preserves existing behavior as much as possible (which also makes it lower risk) without redesigning start/range/ordering logic.
  • The run remains aligned with the jetpack_full_sync_start config/range.
  • We still capture late ongoing changes to existing modules

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)?

Jetpack product discussion

p1763754755558699/1763754199.536589-slack-C05PV073SG3

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

No.

Testing instructions:

A code review should suffice here (I also couldn't naturally replicate this).

Testing the happy path:

  • On a Jetpack-connected site (WoA or self-hosted), apply this PR using the Jetpack beta tester plugin, run a full sync via the Jetpack debugger. All modules should sync as expected.

@coder-karen coder-karen self-assigned this Jan 7, 2026
@coder-karen coder-karen added [Type] Bug When a feature is broken and / or not performing as intended [Status] In Progress [Package] Sync labels Jan 7, 2026
@github-actions
Copy link
Contributor

github-actions bot commented Jan 7, 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 (Jetpack or WordPress.com Site Helper), and enable the update/full_sync_immediately-send-check-modules-exist branch.
  • To test on Simple, run the following command on your sandbox:
bin/jetpack-downloader test jetpack update/full_sync_immediately-send-check-modules-exist
bin/jetpack-downloader test jetpack-mu-wpcom-plugin update/full_sync_immediately-send-check-modules-exist

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 Jan 7, 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 a "[Type]" label (Bug, Enhancement, Janitorial, Task).
  • ✅ 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
Copy link

jp-launch-control bot commented Jan 7, 2026

Code Coverage Summary

Coverage changed in 1 file.

File Coverage Δ% Δ Uncovered
projects/packages/sync/src/modules/class-full-sync-immediately.php 32/195 (16.41%) -1.08% 12 💔

Full summary · PHP report · JS report

If appropriate, add one of these labels to override the failing coverage check: Covered by non-unit tests Use to ignore the Code coverage requirement check when E2Es or other non-unit tests cover the code Coverage tests to be added later Use to ignore the Code coverage requirement check when tests will be added in a follow-up PR I don't care about code coverage for this PR Use this label to ignore the check for insufficient code coveage.

@coder-karen coder-karen marked this pull request as ready for review January 8, 2026 09:55
Copilot AI review requested due to automatic review settings January 8, 2026 09:55
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 addresses array key warnings that occur when sync modules are added or removed during a full sync operation. The fix adds checks using the null coalescing operator before accessing module-specific configuration and progress data, and extracts the module name into a variable to reduce repeated method calls.

Key Changes:

  • Adds null coalescing operator checks for module config and progress array keys
  • Stores module name in a variable to avoid repeated $module->name() calls
  • Corrects doc block parameter type from string to array for $config

Reviewed changes

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

File Description
projects/packages/sync/src/modules/class-full-sync-immediately.php Adds array key existence checks and extracts module name to variable
projects/packages/sync/src/modules/class-module.php Corrects parameter type documentation and formatting
projects/packages/sync/changelog/update-full_sync_immediately-send-check-modules-exist Adds changelog entry for the bug fix

@coder-karen coder-karen marked this pull request as draft January 8, 2026 10:18
@coder-karen coder-karen marked this pull request as ready for review January 8, 2026 10:54
Copilot AI review requested due to automatic review settings January 8, 2026 10:54
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

Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.

Comment on lines 399 to 430
if ( isset( $progress[ $module_name ] ) && array_key_exists( $module_name, $config ) ) {
$progress[ $module_name ] = $module->send_full_sync_actions( $config[ $module_name ], $progress[ $module_name ], $send_until, $started );
if ( isset( $progress[ $module_name ]['error'] ) ) {
unset( $progress[ $module_name ]['error'] );
$this->update_status( array( 'progress' => $progress ) );
return false;
} elseif ( ! $progress[ $module_name ]['finished'] ) {
$this->update_status( array( 'progress' => $progress ) );
return true;
}
}

if ( $this->get_status()['started'] !== $started ) {
// Full sync was restarted, stop sending.
return false;
}
}

// Only end if everything is finished. If not, persist and try again next time.
// We may end up in this state if get_remaining_modules_to_send returns more modules than we initially stored in $progress or $config.
$all_progress_finished = true;
foreach ( $progress as $progress_module_name ) {
if ( empty( $progress_module_name['finished'] ) || true !== $progress_module_name['finished'] ) {
$all_progress_finished = false;
break;
}
}

if ( ! $all_progress_finished ) {
$this->update_status( array( 'progress' => $progress ) );
return true; // release lock and continue later
}
Copy link

Copilot AI Jan 8, 2026

Choose a reason for hiding this comment

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

The new logic for handling missing modules (lines 399-409) and the verification loop (lines 419-430) lack test coverage. Given that the project has existing test infrastructure and this change addresses a critical bug scenario (modules appearing/disappearing during sync execution), consider adding tests that verify: 1) modules not in $progress or $config are properly skipped without warnings, 2) sync completes successfully when all tracked modules finish, and 3) the behavior when module lists change mid-sync.

Copilot uses AI. Check for mistakes.
Comment on lines 420 to 421
foreach ( $progress as $progress_module_name ) {
if ( empty( $progress_module_name['finished'] ) || true !== $progress_module_name['finished'] ) {
Copy link

Copilot AI Jan 8, 2026

Choose a reason for hiding this comment

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

The variable name 'progress_module_name' is misleading. This variable doesn't contain a module name string - it contains a module's progress status array (which should have keys like 'finished', 'last_sent', etc.). Consider renaming it to 'module_progress' or 'progress_status' to better reflect what it contains.

Suggested change
foreach ( $progress as $progress_module_name ) {
if ( empty( $progress_module_name['finished'] ) || true !== $progress_module_name['finished'] ) {
foreach ( $progress as $module_progress ) {
if ( empty( $module_progress['finished'] ) || true !== $module_progress['finished'] ) {

Copilot uses AI. Check for mistakes.
// We may end up in this state if get_remaining_modules_to_send returns more modules than we initially stored in $progress or $config.
$all_progress_finished = true;
foreach ( $progress as $progress_module_name ) {
if ( empty( $progress_module_name['finished'] ) || true !== $progress_module_name['finished'] ) {
Copy link

Copilot AI Jan 8, 2026

Choose a reason for hiding this comment

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

The condition 'true !== $progress_module_name['finished']' is redundant given the preceding 'empty()' check. If 'empty()' returns false (meaning the value exists and is truthy), the only possible value that would pass the 'empty()' check but still need to be compared to 'true' would be a truthy non-boolean value. However, throughout the codebase, 'finished' is consistently set to 'true' (boolean). The 'empty()' check alone is sufficient here.

Suggested change
if ( empty( $progress_module_name['finished'] ) || true !== $progress_module_name['finished'] ) {
if ( empty( $progress_module_name['finished'] ) ) {

Copilot uses AI. Check for mistakes.
Comment on lines 419 to 425
$all_progress_finished = true;
foreach ( $progress as $progress_module_name ) {
if ( empty( $progress_module_name['finished'] ) || true !== $progress_module_name['finished'] ) {
$all_progress_finished = false;
break;
}
}
Copy link

Copilot AI Jan 8, 2026

Choose a reason for hiding this comment

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

The combination of skipping modules (line 399) and the new verification logic (lines 419-425) could create a deadlock. If a module exists in $progress as unfinished but is no longer returned by get_remaining_modules_to_send() (e.g., removed from $config or Modules::get_module() returns null for it), the module will be skipped during processing but the verification loop will detect it's unfinished and prevent sync completion. On subsequent calls to send(), the same situation repeats indefinitely. Consider checking the verification loop against the same conditions used in the skip check - only verify modules that exist in both $progress and $config.

Copilot uses AI. Check for mistakes.
@coder-karen coder-karen marked this pull request as draft January 8, 2026 17:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Package] Sync [Status] In Progress [Type] Bug When a feature is broken and / or not performing as intended

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants