Skip to content

fix: recover resumable downloads after HTTP 416 - #265

Open
NgoQuocViet2001 wants to merge 1 commit into
Anil-matcha:mainfrom
NgoQuocViet2001:fix/resume-download-http-416
Open

fix: recover resumable downloads after HTTP 416#265
NgoQuocViet2001 wants to merge 1 commit into
Anil-matcha:mainfrom
NgoQuocViet2001:fix/resume-download-http-416

Conversation

@NgoQuocViet2001

@NgoQuocViet2001 NgoQuocViet2001 commented Jul 11, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Recover resumable model downloads when a stale or already-complete .part file triggers HTTP 416.
  • Validate strong ETags and Content-Range before appending to a partial download.
  • Restart through a temporary file when the remote object no longer matches, without deleting the old partial first.
  • Close response and file streams before cleanup so retries work reliably on Windows.

Why

Hugging Face/Xet can return HTTP 416 when a saved range starts at or beyond the current end of the object. Previously that left the model download stuck until the partial artifacts were removed manually.

The old downloader also appended any HTTP 206 response without validating that it belonged to the same remote object. This change records a strong ETag beside the partial and only resumes when both the validator and returned range match.

Safety properties

  • A partial is promoted only after a canonical HEAD request confirms the same ETag and exact size.
  • A mismatched or legacy partial is preserved until a fresh replacement finishes successfully.
  • Redirects share one bounded retry budget.
  • Response and file streams are closed before cleanup, including failure paths that are sensitive on Windows.
  • Deleting a model also removes the resume metadata and temporary fresh-download artifact.

Validation

Rebased onto current main on 2026-07-23, then reran:

  • node --test tests/localInferenceDownload.test.js — 11/11 passed
  • node --check electron/lib/localInferenceDownload.js
  • node --check electron/lib/localInference.js
  • npm run build:packages
  • npm run build — production Next.js build passed

The tests use local HTTP servers and real files to cover matching resume, Xet-style 416 recovery, redirects/retry exhaustion, ETag/range mismatches, interrupted replacements, output-stream failures, and response cleanup.

@NgoQuocViet2001
NgoQuocViet2001 force-pushed the fix/resume-download-http-416 branch from 63c1c6a to 7deedb9 Compare July 23, 2026 06:54
@NgoQuocViet2001

Copy link
Copy Markdown
Contributor Author

Rebased this onto the current main and reran the downloader suite (11/11), package builds, and the full production build. The head is merge-clean. @Anil-matcha, this is ready for review when you have a moment.

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