Skip to content

fix: retry preflight HEAD and prefer catalog size when downloading models (ATO-302)#182

Open
worthant wants to merge 2 commits into
mainfrom
worthant/ato-302-preflight-head-pri-zahruzke-modeli-bez-retraev-odinochnii
Open

fix: retry preflight HEAD and prefer catalog size when downloading models (ATO-302)#182
worthant wants to merge 2 commits into
mainfrom
worthant/ato-302-preflight-head-pri-zahruzke-modeli-bez-retraev-odinochnii

Conversation

@worthant

Copy link
Copy Markdown
Collaborator

Problem

The preflight HEAD request that resolves a model's file size before download ran exactly once, while the download stream itself retries up to 5 times (MAX_STREAM_RETRIES, exponential backoff). A single transient network blip during HEAD — TLS handshake EOF, connection reset, timeout — produced an immediate, unrecoverable "Download failed", even though the actual download would have succeeded after a retry.

Models are served from huggingface.co, so this hit anyone with a flaky path to HF (DPI, VPN, HTTPS-inspecting antivirus, flapping ISP). Origin: Discord report (Windows 11, qwen35) with unexpected EOF during handshake in the logs.

Fixes ATO-302.

Changes

src-tauri/src/core/downloads/helpers.rs:

  • Skip the HEAD entirely when the catalog already provides the size (item.size) — no network round-trip at preflight, so nothing to fail.
  • When the size is unknown, retry the HEAD with the same policy as the stream: 5 attempts, exponential backoff, cancel-aware. Transport errors and HTTP 408/429/5xx are classified as retryable; 4xx are not retried.
  • A preflight failure is no longer fatal: fall back to an unknown size (0) and let the GET path — which has its own retries — either download the file or surface the real error. Only user cancellation aborts the preflight.

Tests

Six new tests in src-tauri/src/core/downloads/tests.rs, all against real local HTTP/TCP servers:

  • download_succeeds_when_preflight_head_always_fails — end-to-end regression test through _download_files_internal: HEAD returns 500 on every attempt, download still completes via GET. Verified to fail on pre-fix main with the exact bug (Failed to get file size: HTTP status 500).
  • preflight_head_retries_dropped_connections — server tears down the first two TCP connections before responding (the handshake-EOF failure class from the report); size resolves on the third attempt.
  • preflight_head_retries_transient_failures — two 500s, then success.
  • preflight_uses_catalog_size_without_a_head_request — known catalog size ⇒ zero requests to the server.
  • preflight_head_failure_is_not_fatal — permanent 500s ⇒ falls back to size 0 after 6 attempts, no error.
  • preflight_head_does_not_retry_fatal_status — 404 is not retried.

Full crate suite: 157 passed, 0 failed.

worthant added 2 commits July 15, 2026 18:14
…dels (ATO-302)

The preflight HEAD request that resolves a model's file size ran exactly
once, while the download stream itself retries up to 5 times. A single
transient network blip (TLS handshake EOF, timeout) during HEAD therefore
produced an immediate, unrecoverable 'Download failed'.

- Skip the HEAD request entirely when the catalog already provides the
  file size (item.size), so it cannot fail the download at all.
- When the size is unknown, retry the HEAD with the same policy as the
  stream (5 attempts, exponential backoff, cancel-aware), classifying
  transport errors and 408/429/5xx as retryable.
- Make a preflight failure non-fatal: fall back to an unknown size and
  let the GET path (which has its own retries) surface the real error.
… ATO-302

- preflight_head_retries_dropped_connections: the server tears down the
  first two TCP connections before responding (the 'unexpected EOF during
  handshake' class of failure from the original report) and the preflight
  still resolves the size on the third attempt.
- download_succeeds_when_preflight_head_always_fails: full
  _download_files_internal regression test — HEAD returns 500 on every
  attempt, yet the download completes via GET. Fails with 'Failed to get
  file size: HTTP status 500' on the pre-fix code.
@worthant
worthant requested a review from Vect0rM as a code owner July 15, 2026 15:39
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.

1 participant