Skip to content

Build/test tools: retry incomplete Gutenberg build downloads - #12700

Closed
lancewillett wants to merge 1 commit into
WordPress:trunkfrom
lancewillett:fix/gutenberg-download-retry
Closed

Build/test tools: retry incomplete Gutenberg build downloads#12700
lancewillett wants to merge 1 commit into
WordPress:trunkfrom
lancewillett:fix/gutenberg-download-retry

Conversation

@lancewillett

@lancewillett lancewillett commented Jul 26, 2026

Copy link
Copy Markdown
Contributor

Trac ticket: https://core.trac.wordpress.org/ticket/65720

Summary

Make the Gutenberg build download survive an interrupted transfer.

  • Download the archive to a temporary file before extraction, rather than streaming straight into it.
  • Validate the manifest-declared archive size, then extract.
  • Retry interrupted network or stream transfers up to two more times.
  • Log each attempt: HTTP response, expected vs received bytes, elapsed time.
  • Remove temporary files afterward, on success and on failure.

Non-transient HTTP failures still stop immediately. Workflow structure, caching, and artifact sharing are unchanged.

Why

PHPUnit jobs sometimes fail before a single test runs, with Download/extraction failed: Premature close. The prebuilt Gutenberg archive is streamed from the GitHub Container Registry directly into extraction, so a stream that closes early corrupts the extraction with no clean boundary to retry from. Writing to a temporary file first creates that boundary, and validating the declared size means a short read is caught before it can look like a successful download.

Follow up to the Gutenberg artifact-fetching work in #64393.

Testing

New unit tests cover the retry path, size validation, temp-file cleanup, and the non-transient failure case. Run them with:

npm run test:tools

or directly:

node --test tools/gutenberg/tests/download.test.js

Related

Interim, focused retry fix. The larger download-once and cache work (Trac https://core.trac.wordpress.org/ticket/65721, PRs #12701 and #12702) reworks the same downloader and reimplements bounded retries more fully, so it can supersede this once it lands. This smaller change is safe to land first for immediate relief; the other then rebases and keeps its own implementation. Both add tools/gutenberg/tests/download.test.js and a test:tools script.

Some PHPUnit jobs fail before tests start when the prebuilt Gutenberg archive
download from the GitHub Container Registry closes early ("Premature close").
The downloader streams directly into extraction, leaving no clean retry
boundary. Download to a temporary file first, validate the manifest-declared
size, and retry interrupted transfers up to two more times. Log each attempt
and clean up temporary files. Non-transient HTTP failures still stop
immediately; workflow structure, caching, and artifact sharing are unchanged.

See #65720.

Props lance.willett@automattic.com
Copilot AI review requested due to automatic review settings July 26, 2026 23:47
@github-actions

Copy link
Copy Markdown

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

Core Committers: Use this line as a base for the props when committing in SVN:

Props lancewillett.

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

Copilot AI 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.

Pull request overview

This PR improves the robustness of the Gutenberg artifact fetch used by the WordPress develop tooling by adding a retryable, size-validated download step that writes to a temporary archive file before extraction, making interrupted transfers recoverable.

Changes:

  • Add downloadArchive() with bounded retries, linear backoff + jitter, and manifest-size validation before extraction.
  • Update tools/gutenberg/download.js to download the blob to a temp archive, then extract from disk (and clean up the temp file afterward).
  • Add Node test coverage for retry, size mismatch, cleanup, and non-retryable failures, plus a new npm run test:tools entry point.

Reviewed changes

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

File Description
tools/gutenberg/download.js Implements retrying, size-checked archive download to a temp file and disk-based extraction.
tools/gutenberg/tests/download.test.js Adds unit + subprocess tests validating retry/backoff, size validation, and cleanup behavior.
package.json Adds test:tools script to run the new Node tests.

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

/** @type {import('stream/web').ReadableStream} */ ( response.body )
),
meter,
fs.createWriteStream( archivePath )
Comment on lines 283 to 291
} catch ( error ) {
console.error( '❌ Download/extraction failed:', /** @type {Error} */ ( error ).message );
process.exit( 1 );
process.exitCode = 1;
return;
} finally {
if ( archivePath ) {
fs.rmSync( archivePath, { force: true } );
}
}
@github-actions

Copy link
Copy Markdown

Test using WordPress Playground

The changes in this pull request can previewed and tested using a WordPress Playground instance.

WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser.

Some things to be aware of

  • All changes will be lost when closing a tab with a Playground instance.
  • All changes will be lost when refreshing the page.
  • A fresh instance is created each time the link below is clicked.
  • Every time this pull request is updated, a new ZIP file containing all changes is created. If changes are not reflected in the Playground instance,
    it's possible that the most recent build failed, or has not completed. Check the list of workflow runs to be sure.

For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation.

Test this pull request with WordPress Playground.

@lancewillett lancewillett changed the title Build/Test Tools: Retry incomplete Gutenberg build downloads Build/test tools: retry incomplete Gutenberg build downloads Jul 27, 2026
@lancewillett

Copy link
Copy Markdown
Contributor Author

Closing in favor of #12701 (download the Gutenberg build once per run). That change already ships its own bounded retry with SHA-256 verification for the single remaining fetch, and it removes about 176 of the 177 per-run downloads this PR only hardened. So this retry is redundant once #12701 lands.

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.

2 participants