Skip to content

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

Open
swissspidy with Copilot wants to merge 3 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 3 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 interrupting unrelated CLI commands when the releases service is rate-limited or unavailable.
    • Added graceful handling for failed update checks, allowing commands such as wp cli version to complete successfully.

@coderabbitai

coderabbitai Bot commented Jul 16, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

The auto-update check now handles release API rate-limit failures without disrupting unrelated commands. A feature scenario verifies wp cli version succeeds with default settings and when automatic checks are forced.

Changes

Update check resilience

Layer / File(s) Summary
Auto-check failure handling and regression coverage
php/WP_CLI/Runner.php, features/cli-check-update.feature
auto_check_update() captures the update-check result, detects failures, logs debug output, and exits early; the feature scenario verifies successful version commands when GitHub returns HTTP 403.

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related issues

  • wp-cli/wp-cli#6344 — Both changes prevent background update-check failures from breaking unrelated commands.

Suggested reviewers: swissspidy

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main change: background auto-update check errors no longer fail the running command.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch copilot/auto-update-check-warning

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 PHPStan (2.2.5)

Invalid configuration:
Unexpected item 'parameters › strictRules'.


Comment @coderabbitai help to get the list of available commands.

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

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.

Pull request overview

This PR prevents WP-CLI’s background auto-update check from terminating the user’s currently running command when the update check encounters HTTP/network errors (e.g., GitHub 401/403/rate limiting). It does so by switching the auto-check to WP_CLI::runcommand() with options that capture errors/output instead of exiting the process.

Changes:

  • Replace ob_start() + WP_CLI::run_command() with WP_CLI::runcommand() for cli check-update --format=count.
  • Run the update check with exit_error => false and return => 'all' to capture failures/output without printing or exiting.
  • On failure, emit a WP_CLI::debug() message (group auto-update) and return early.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread php/WP_CLI/Runner.php
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 coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@features/cli-check-update.feature`:
- Around line 61-64: Update the scenario around the `wp cli version` commands to
exercise the auto-update code path, such as using a help command that triggers
the update check, or add an assertion confirming the mocked GitHub request was
made. Preserve the return-code assertions while ensuring the 403 stub is
consumed and the regression cannot pass without executing the auto-update
branch.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: ad24f7dc-7b18-4417-a1fc-52de3ed7ae33

📥 Commits

Reviewing files that changed from the base of the PR and between 90946a6 and 21ea034.

📒 Files selected for processing (2)
  • features/cli-check-update.feature
  • php/WP_CLI/Runner.php

Comment on lines +61 to +64
When I run `wp cli version`
Then the return code should be 0
When I run `WP_CLI_AUTO_CHECK_UPDATE_DAYS=0 wp cli version`
Then the return code should be 0

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

printf '\n== auto_check_update call sites ==\n'
rg -n "auto_check_update\s*\(" php features -S || true

printf '\n== help/version related registrations ==\n'
rg -n "cli version|version" php/WP_CLI features/cli-check-update.feature -S || true

printf '\n== inspect Runner around call sites ==\n'
file=php/WP_CLI/Runner.php
if [ -f "$file" ]; then
  nl -ba "$file" | sed -n '1880,1975p'
fi

printf '\n== inspect feature scenario around lines 45-70 ==\n'
file=features/cli-check-update.feature
if [ -f "$file" ]; then
  nl -ba "$file" | sed -n '40,75p'
fi

Repository: wp-cli/wp-cli

Length of output: 11171


🏁 Script executed:

#!/bin/bash
set -euo pipefail

printf '\n== locate version command implementation ==\n'
rg -n "class .*Version|function .*version|subcommand.*version|cli version" php -S || true

printf '\n== map WP_CLI command classes related to cli ==\n'
fd -a "cli" php || true
fd -a "Version" php || true

Repository: wp-cli/wp-cli

Length of output: 1852


🏁 Script executed:

#!/bin/bash
set -euo pipefail

printf '\n== auto_check_update call sites ==\n'
rg -n "auto_check_update\s*\(" php features -S || true

printf '\n== help/version related registrations ==\n'
rg -n "cli version|version" php/WP_CLI features/cli-check-update.feature -S || true

printf '\n== inspect Runner around call sites ==\n'
file=php/WP_CLI/Runner.php
if [ -f "$file" ]; then
  nl -ba "$file" | sed -n '1880,1975p'
fi

printf '\n== inspect feature scenario around lines 40-75 ==\n'
file=features/cli-check-update.feature
if [ -f "$file" ]; then
  nl -ba "$file" | sed -n '40,75p'
fi

Repository: wp-cli/wp-cli

Length of output: 11171


🏁 Script executed:

#!/bin/bash
set -euo pipefail

printf '\n== CLI_Command::version ==\n'
file=php/commands/src/CLI_Command.php
if [ -f "$file" ]; then
  awk 'NR>=1 && NR<=140 { printf "%5d  %s\n", NR, $0 }' "$file"
fi

printf '\n== Runner around auto_check_update call sites ==\n'
file=php/WP_CLI/Runner.php
if [ -f "$file" ]; then
  awk 'NR>=1888 && NR<=1960 { printf "%5d  %s\n", NR, $0 }' "$file"
fi

printf '\n== Runner around parse / dispatch to see where help branch is selected ==\n'
if [ -f "$file" ]; then
  awk 'NR>=1400 && NR<=1460 { printf "%5d  %s\n", NR, $0 }' "$file"
fi

Repository: wp-cli/wp-cli

Length of output: 10648


🏁 Script executed:

#!/bin/bash
set -euo pipefail

printf '\n== outline CLI_Command ==\n'
ast-grep outline php/commands/src/CLI_Command.php --view expanded || true

Repository: wp-cli/wp-cli

Length of output: 1154


🏁 Script executed:

#!/bin/bash
set -euo pipefail

file=features/cli-check-update.feature
printf '\n== relevant feature window ==\n'
awk 'NR>=45 && NR<=70 { printf "%5d  %s\n", NR, $0 }' "$file"

printf '\n== request-consumption assertions in this feature ==\n'
rg -n "request|consum|HTTP 403|latest version|auto_check_update|check-update" "$file" -n -S || true

Repository: wp-cli/wp-cli

Length of output: 2241


Use a command that hits the auto-update branch wp cli version only prints the version string, so this scenario can pass without consuming the 403 stub and still miss the regression. Switch to a help path or assert that the mocked GitHub request was made.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@features/cli-check-update.feature` around lines 61 - 64, Update the scenario
around the `wp cli version` commands to exercise the auto-update code path, such
as using a help command that triggers the update check, or add an assertion
confirming the mocked GitHub request was made. Preserve the return-code
assertions while ensuring the 403 stub is consumed and the regression cannot
pass without executing the auto-update branch.

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

3 participants