Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Oct 29, 2025

Add support for parallel processing of alias groups in WP-CLI.

Currently, when running a command against an alias group (e.g., @all or a custom group like @both), WP-CLI processes each alias sequentially. This change adds support for parallel execution via the WP_CLI_ALIAS_GROUPS_PARALLEL environment variable, significantly improving execution speed when running commands across multiple WordPress installations.

Changes Made

  • Add WP_CLI_ALIAS_GROUPS_PARALLEL environment variable support
  • Modify the run_alias_group() method in Runner.php to check the environment variable
  • Add feature tests to validate parallel execution works correctly
  • Add documentation and examples for the environment variable
  • Ensure backward compatibility (default behavior remains sequential)
  • Pass code review with no issues
  • Pass security scan with no vulnerabilities
  • Fix Gherkin test style to use 'And' instead of 'When'

Implementation Details

The implementation uses the WP_CLI_ALIAS_GROUPS_PARALLEL environment variable:

  1. When set to a truthy value (e.g., 1), spawns all alias processes concurrently before waiting for results
  2. When not set (default), maintains the original sequential behavior
  3. Works with all types of aliases (local paths, SSH, docker, etc.)
  4. Environment variable is naturally inherited by child processes

Usage Examples

# Run command against multiple aliases in parallel
WP_CLI_ALIAS_GROUPS_PARALLEL=1 wp @both option get home

# Run command against all registered aliases in parallel
WP_CLI_ALIAS_GROUPS_PARALLEL=1 wp @all plugin list

# Works with quiet mode
WP_CLI_ALIAS_GROUPS_PARALLEL=1 wp @all core version --quiet

Performance Benefits

This change provides significant performance improvements when:

  • Running commands across multiple remote installations over SSH
  • Executing I/O-bound operations
  • Processing commands that take significant time to complete
  • Working with installations on different machines or containers

Backward Compatibility

The default behavior remains unchanged - aliases are processed sequentially unless the WP_CLI_ALIAS_GROUPS_PARALLEL environment variable is set. This ensures no breaking changes for existing workflows.

Security Summary

✅ All shell arguments are properly escaped using escapeshellarg()
✅ No new security vulnerabilities introduced
✅ Code review completed with no issues
✅ CodeQL security scan completed with no findings

Original prompt

This section details on the original issue you should resolve

<issue_title>Add switch to allow aliases to be processed in parallel</issue_title>
<issue_description>It would be useful to allow aliases to be processed in parallel, so that the machine controlling the process can open multiple connections at the same time. Under the right circumstances, this would drastically improve the speed of execution across multiple machines.

From @lukasleitsch via https://twitter.com/lukasleitsch/status/955749917544329216
</issue_description>

Comments on the Issue (you are @copilot in this section)

@danielbachhuber That'd be pretty nifty. It'd even improve performance running across multiple installs on the same machine.

✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI and others added 3 commits October 29, 2025 19:40
Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
Copilot AI changed the title [WIP] Add switch to allow aliases to be processed in parallel Add --parallel flag for concurrent alias group execution Oct 29, 2025
Copilot AI requested a review from swissspidy October 29, 2025 19:48
Copilot finished work on behalf of swissspidy October 29, 2025 19:48
@codecov
Copy link

codecov bot commented Oct 29, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@swissspidy
Copy link
Member

@copilot In features/aliases.feature:685, step "When I run wp @both option get home --parallel" should use And instead of When

Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Oct 29, 2025

@copilot In features/aliases.feature:685, step "When I run wp @both option get home --parallel" should use And instead of When

Fixed in c7238f5. Changed line 685 to use And for proper Gherkin style.

Copilot finished work on behalf of swissspidy October 29, 2025 20:16
@swissspidy
Copy link
Member

@copilot Instead of a new global argument, let's steer this with a new environment variable.

Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Oct 31, 2025

@copilot Instead of a new global argument, let's steer this with a new environment variable.

Changed to use WP_CLI_ALIAS_GROUPS_PARALLEL environment variable instead of a global argument in commit 703007c. The parallel flag has been removed from config-spec.php, and the implementation now checks getenv('WP_CLI_ALIAS_GROUPS_PARALLEL') directly in run_alias_group(). Tests and documentation updated accordingly.

Copilot AI changed the title Add --parallel flag for concurrent alias group execution Add WP_CLI_ALIAS_GROUPS_PARALLEL environment variable for concurrent alias group execution Oct 31, 2025
Copilot finished work on behalf of swissspidy October 31, 2025 00:32
@swissspidy swissspidy marked this pull request as ready for review October 31, 2025 00:50
@swissspidy swissspidy requested a review from a team as a code owner October 31, 2025 00:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add switch to allow aliases to be processed in parallel

2 participants