Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Oct 30, 2025

Implementation Complete: Add automatic retries to download paths

Properly rebased onto latest main branch using git rebase

Rebase Details

  • Base commit: 5aa34009 (Merge pull request Fix new PHPStan errors #6163 from wp-cli/fix/phpstan-errors)
  • Clean rebase with proper conflict resolution
  • Integrated latest SSL error handling improvements from main
  • All commits cleanly applied on top of main

Implementation Summary

Successfully implemented automatic retry mechanism for HTTP requests in WP-CLI with a hardcoded 3 retry threshold.

Key Features

  1. Hardcoded 3 retries - Simple, non-configurable retry mechanism
  2. Smart retry logic - Only retries on transient network errors (timeouts, connection issues)
  3. Exponential backoff - Uses 1s, 2s, 4s, 8s, 10s (max) delays between retries
  4. Clear debug logging - Shows retry 1/3, 2/3, 3/3 when --debug=http is enabled
  5. Backward compatible - No breaking changes, works transparently with existing code
  6. PHP 8.5+ compatible - Handles curl_close deprecation
  7. Properly integrated with main - Clean rebase onto latest main with improved SSL error handling

Transient Errors Handled

  • CURLE_OPERATION_TIMEDOUT (28) - Operation timeout
  • CURLE_COULDNT_RESOLVE_HOST (6) - Couldn't resolve host
  • CURLE_COULDNT_CONNECT (7) - Failed to connect
  • CURLE_PARTIAL_FILE (18) - Partial file transfer
  • CURLE_GOT_NOTHING (52) - Server returned nothing
  • CURLE_SEND_ERROR (55) - Send error
  • CURLE_RECV_ERROR (56) - Receive error

Files Changed

  • php/utils.php - Implemented retry logic and helper function with proper integration
  • tests/UtilsTest.php - Added unit test for transient error detection

Benefits

  • Improved reliability for downloads (themes, plugins, core, language files)
  • Better automated test stability
  • Reduced impact of transient network failures
Original prompt

This section details on the original issue you should resolve

<issue_title>Add automatic retries to download paths</issue_title>
<issue_description>For operations like downloading a theme or a language file, or latest Core code, we should have an automatic retry mechanism with a configurable threshold (defaulting to 3 as a good compromise).

This would not only make general scripting with WP-CLI more reliable but also drastically increase the reliability of our automated tests, which constantly fail due to random timeouts when doing downloads.</issue_description>

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


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

@codecov
Copy link

codecov bot commented Oct 30, 2025

Codecov Report

❌ Patch coverage is 78.00000% with 11 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
php/utils.php 78.00% 11 Missing ⚠️

📢 Thoughts on this report? Let us know!

Copilot AI and others added 2 commits October 30, 2025 17:00
…eshold

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 automatic retries for downloading files Add automatic retry mechanism for HTTP requests with configurable threshold Oct 30, 2025
Copilot AI requested a review from swissspidy October 30, 2025 17:15
@swissspidy

This comment was marked as resolved.

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

This comment was marked as resolved.

Copilot AI changed the title Add automatic retry mechanism for HTTP requests with configurable threshold Add automatic retry mechanism for HTTP requests Oct 30, 2025
@swissspidy

This comment was marked as resolved.

@swissspidy

This comment was marked as resolved.

Copilot stopped work on behalf of swissspidy due to an error October 31, 2025 00:42
@swissspidy

This comment was marked as resolved.

…annotation

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

This comment was marked as resolved.

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 implements an automatic retry mechanism for HTTP requests in WP-CLI to improve reliability when downloading themes, plugins, core files, and language packs. The implementation adds exponential backoff retry logic that triggers on transient network failures (timeouts, connection issues) with a hardcoded limit of 3 retries.

Key changes:

  • Added is_transient_http_error() helper function to identify retryable network errors
  • Modified http_request() to automatically retry on transient failures with exponential backoff (1s, 2s, 4s delays)
  • Added basic test coverage for transient error detection

Reviewed changes

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

File Description
php/utils.php Implements retry loop with exponential backoff in http_request() and adds is_transient_http_error() helper to detect retryable curl errors
tests/UtilsTest.php Adds test for is_transient_http_error() function with timeout error scenario and PHP 8.5+ curl_close handling

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

@swissspidy

This comment was marked as resolved.

This comment was marked as resolved.

@swissspidy

This comment was marked as resolved.

This comment was marked as resolved.

@swissspidy swissspidy force-pushed the copilot/add-automatic-retries-downloads branch from e9cc891 to ac7cbf1 Compare December 10, 2025 10:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add automatic retries to download paths

2 participants