Skip to content

Fix: auto update check error should not fail the running command#6345

Open
swissspidy with Copilot wants to merge 5 commits into
mainfrom
copilot/auto-update-check-warning
Open

Fix: auto update check error should not fail the running command#6345
swissspidy with Copilot wants to merge 5 commits into
mainfrom
copilot/auto-update-check-warning

Conversation

Copilot AI commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

When the background update check hits a network/HTTP error (e.g. 401, 403 rate-limit), CLI_Command::get_updates() calls WP_CLI::error(), which exits the process — silently killing whatever command the user actually ran.

Changes

  • Runner::auto_check_update(): Replace the bare ob_start() / WP_CLI::run_command() pattern with WP_CLI::runcommand() using exit_error => false and return => 'all'
    • exit_error => false sets $capture_exit = true so WP_CLI::error() throws ExitException instead of calling exit()
    • return => 'all' swaps in an Execution logger that captures stdout/stderr in memory — the error message is never printed to the terminal
    • On failure, a WP_CLI::debug() message is emitted (visible with --debug) and the check silently returns without affecting the user's command
// Before: any HTTP error in get_updates() would call exit(1)
ob_start();
WP_CLI::run_command( [ 'cli', 'check-update' ], [ 'format' => 'count' ] );
$count = ob_get_clean();

// After: errors are captured, not propagated
$result = WP_CLI::runcommand(
    'cli check-update --format=count',
    [ 'launch' => false, 'exit_error' => false, 'return' => 'all' ]
);
if ( ! is_object( $result ) || $result->return_code ) {
    WP_CLI::debug( 'Background update check failed: ' . ( is_object( $result ) ? trim( $result->stderr ) : '' ), 'auto-update' );
    return;
}

Summary by CodeRabbit

  • Bug Fixes
    • Prevented automatic update checks from disrupting unrelated CLI commands when the releases service is rate-limited or unreachable.
    • Improved resilience of background update detection so failures no longer cause non-update commands to exit non-zero.
  • Tests
    • Added coverage for the “rate limit exceeded” case and confirmed update checks don’t affect commands like wp help, including when auto-check timing is disabled.

@coderabbitai

This comment was marked as resolved.

Copilot AI linked an issue Jul 16, 2026 that may be closed by this pull request
@github-actions github-actions Bot added bug command:cli-check-update Related to 'cli check-update' command command:cli-update Related to 'cli update' command labels Jul 16, 2026
@codecov

codecov Bot commented Jul 16, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 0% with 9 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
php/WP_CLI/Runner.php 0.00% 9 Missing ⚠️

📢 Thoughts on this report? Let us know!

Use WP_CLI::runcommand() with exit_error=>false and return=>'all'
in Runner::auto_check_update() so that HTTP/network errors during
the background update check are silently captured (logged at debug
level) instead of propagating and failing the user's command.

Closes #6344

Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix auto update check error on command failure Fix: auto update check error should not fail the running command Jul 16, 2026
Copilot AI requested a review from swissspidy July 16, 2026 13:46
@swissspidy
swissspidy requested a review from Copilot July 16, 2026 15:22

This comment was marked as resolved.

Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
@swissspidy
swissspidy marked this pull request as ready for review July 16, 2026 15:39
@swissspidy
swissspidy requested a review from a team as a code owner July 16, 2026 15:39
coderabbitai[bot]

This comment was marked as resolved.

@coderabbitai

This comment was marked as resolved.

Fixed 1 file(s) based on 1 unresolved review comment.

Co-authored-by: CodeRabbit <noreply@coderabbit.ai>
@swissspidy swissspidy added this to the 3.0.0 milestone Jul 20, 2026
Try using a GITHUB_TOKEN
"""

Scenario: Does not fail unrelated command when background update check is rate limited

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

At first glance, wp help in an empty dir makes sense, that path does call auto_check_update(). But I don't think this scenario actually exercises the fix: auto_check_update() bails out well before the check-update call, first on ! inside_phar() (Behat runs from source, not a Phar) and then on ! posix_isatty( STDOUT ) (Behat pipes STDOUT, so it's never a TTY). So the runcommand is never reached, and the 403 mock is never hit by the auto path. Quickest way to confirm: revert the Runner.php hunk and this scenario still passes. That's also why codecov/patch is red, the new branch gets no coverage.

I'd rather we either drop this scenario (the manual repro in the PR description is the real evidence, and a green check that guards nothing is worse than no check), or, if we want genuine coverage, pull the 'run check-update and interpret the result' core out into a testable seam and unit-test it with a mocked runcommand. A full feature test would need a test-only bypass of the Phar/TTY guards, which I don't think is worth it here.

Comment thread php/WP_CLI/Runner.php
]
);
$count = ob_get_clean();
if ( ! is_object( $result ) || $result->return_code ) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Minor: with return => 'all', runcommand always hands back the object, so ! is_object( $result ) can't actually be true here. Harmless as defensive code, so feel free to leave it.

Comment thread php/WP_CLI/Runner.php
);
$count = ob_get_clean();
if ( ! is_object( $result ) || $result->return_code ) {
WP_CLI::debug( 'Background update check failed: ' . ( is_object( $result ) ? trim( $result->stderr ) : '' ), 'auto-update' );

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Tiny thing: runcommand already trims stderr on the way out (it builds the all object with trim( $stderr )), so the trim() here is redundant.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug command:cli-check-update Related to 'cli check-update' command command:cli-update Related to 'cli update' command

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Auto update check error should not fail command

4 participants