Skip to content

http_client: Fully download archives before extracting them - #62653

Open
morgankrey wants to merge 2 commits into
mainfrom
morgankrey/download-archives-before-extract
Open

http_client: Fully download archives before extracting them#62653
morgankrey wants to merge 2 commits into
mainfrom
morgankrey/download-archives-before-extract

Conversation

@morgankrey

@morgankrey morgankrey commented Aug 14, 2026

Copy link
Copy Markdown
Contributor

Installing an external agent (or a language server) from an archive that ships without a SHA-256 checksum used a fragile code path: Zed unpacked the archive directly from the network stream, without ever saving the complete file to disk. If the connection dropped partway through the download, the unpacker saw the data stop mid-file and failed with an archive-extraction error that looks identical to a corrupt package. Users hit this with the Cursor agent, whose ACP registry entry has no checksum and whose package is a 71 MB download: any network hiccup produced a confusing "Failed to Install" error with no hint that the download was the problem.

This change makes both paths behave the same way: every archive is now fully downloaded to a temporary file first, and only then unpacked. The checksum verification still runs when a checksum is available, exactly as before; when none is available it is simply skipped. This removes no protection that exists today, since the streaming path performed no verification either. A failed download now reports a download error ("saving archive contents into the temporary file for ") instead of a misleading extraction error.

The second commit fixes the reason these failures were undiagnosable: agent connect and session-creation errors were flattened with to_string, which keeps only the outermost message of an error chain. The underlying cause (invalid gzip, unexpected end of file, connection reset) never reached the panel, the log, or telemetry. Errors are now formatted with the full context chain for display, logged with their debug representation, and session errors are downcast to LoadError first so typed variants keep their specific handling.

The trade-offs are small: the archive briefly occupies temporary disk space, and installation finishes slightly later because unpacking waits for the download to complete.

Intentionally out of scope, as follow-ups: deduplicating concurrent installs of the same version, and cleaning up staging directories left behind by cancelled installs.

Testing:

  • Added a test covering the new no-checksum path (download completes, archive extracts correctly).
  • Added a test simulating a connection dropped mid-download, asserting the error names the download rather than the extraction, and that the staging directory is cleaned up.
  • cargo nextest run -p http_client --features github-download: 8 tests, all passing.
  • cargo nextest run -p agent_ui load_error: 4 tests, all passing.
  • cargo fmt --check and script/clippy pass.

Release Notes:

  • Improved installation of external agents and language servers: archives are now fully downloaded before being unpacked, so an interrupted download produces a clear error instead of a confusing extraction failure, and install errors now show the underlying cause.

Archives without a SHA-256 digest were extracted directly from the
network stream, so an interrupted download surfaced as an opaque
archive-extraction error, indistinguishable from a corrupt asset.
Buffer every archive to a temporary file first, matching what the
digest-verifying path already did, and only then extract.
@cla-bot cla-bot Bot added the cla-signed The user has signed the Contributor License Agreement label Aug 14, 2026
@zed-community-bot zed-community-bot Bot added the staff Pull requests authored by a current member of Zed staff label Aug 14, 2026
Connect and session-creation failures were flattened with
`to_string`, which keeps only the outermost anyhow context and hides
the root cause (e.g. a truncated download) from the panel, the log,
and telemetry. Format with `{:#}` to keep the chain, log the debug
form, and downcast session errors to LoadError so typed variants
survive.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla-signed The user has signed the Contributor License Agreement staff Pull requests authored by a current member of Zed staff

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant