[PR #2287] [CLOSED] [Other] use published size when download length probes fail #3963

Closed
opened 2026-11-07 15:32:03 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Niko1221/Strata/pull/2287
Author: @KeyanHu-git
Created: 10/13/2026
Status: ❌ Closed

Base: main ← Head: fix/1915-download-length


📝 Commits (4)

  • 958882c setup: resume downloads when HEAD omits Content-Length
  • 5b049a6 merge current main and complete serial downloads from response metadata
  • 4acfcbf Use published size in the existing download completion path
  • 7527e00 Test published-size recovery and download verification boundaries

📊 Changes

2 files changed (+112 additions, -1 deletions)

View changed files

📝 setup.py (+3 -1)
➕ tools/test_setup_download_length.py (+109 -0)

📄 Description

Problem and result

When HEAD and the one-byte range probe both fail to provide a length, download() treats an early EOF as completion even if Strata already has the file's published size. A short file is renamed out of .part, and verification either stops with a size error or, without a published hash, marks the fragment as finished.

Use the published size for transfer completion as well as verification. The existing downloader then resumes an interrupted transfer, keeps partial bytes when retries run out, and publishes the file only after receiving the expected length.

#1915. Version 0.2 added a range probe, which covers missing HEAD length when that probe succeeds. This fix covers the remaining case where both probes lack a size. The original ModelScope URL supplied Content-Length when checked on October 22; the regression below reproduces the remaining condition with a local HTTP server.

Approach

After the transport probes, fall back to the repository pin's size, or ModelScope's published size when there is no pin. Reuse the existing metadata lookup for hash verification.

HEAD size → range-probe size → published size → existing download/resume logic
                                                    ↓
                                          size check → rename → hash check

The production diff moves the metadata lookup and adds a two-line fallback. Serial retries, parallel transfers, source identity and checksum verification retain their existing implementations.

Validation

Base: 011c9e60 (0.2.2 / engine 0.1.47). Final revision: 7527e00f. Python 3.12 on macOS and Windows.

python -m unittest tools.test_setup_download_length tools.test_setup_download -v

Passed: all 8 focused tests on both systems. They cover early EOF with a pin, metadata with and without a hash, exhausted retries preserving .part, parallel transfer after a failed initial probe, an already complete .part, a transport/pin size conflict and a wrong hash. Six of these fail on the unmodified base; the size-conflict and hash checks pass on both.

The early-EOF fixture supplies 262,144 of 2,633,785 bytes before closing. The patched serial transfer resumes at byte 262,144 and produces the exact original bytes. Exhausting retries preserves those 262,144 bytes without a final file or .done mark.

Failed: the combined suite passes 36/37 on both macOS and Windows. The shared redirect test counts the first piece twice ([0, 0, 1, …, 40] instead of [0, 1, …, 40]). It uses a successful HEAD length, so this fallback is not entered. The production code for that path is unchanged. The same 37 tests on unmodified main report 4 failures and 3 errors on both systems, including the six focused regressions above.

Not run: another multi-gigabyte transfer through the original reporter's network. All transfer tests above use real HTTP requests to a local server; published metadata is supplied by the fixture.

Limits

If neither transport probes nor published metadata provide a size, the existing unknown-length behavior remains. The fallback does not replace hash verification or change which model files Strata accepts.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/Niko1221/Strata/pull/2287 **Author:** [@KeyanHu-git](https://github.com/KeyanHu-git) **Created:** 10/13/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `fix/1915-download-length` --- ### 📝 Commits (4) - [`958882c`](https://github.com/Niko1221/Strata/commit/958882ccb763d87415e3ee18cf179eda8966090f) setup: resume downloads when HEAD omits Content-Length - [`5b049a6`](https://github.com/Niko1221/Strata/commit/5b049a6883f4ab141a4bd05d0a97a001769191f1) merge current main and complete serial downloads from response metadata - [`4acfcbf`](https://github.com/Niko1221/Strata/commit/4acfcbf639ae2764f7125feced2332a048f1412c) Use published size in the existing download completion path - [`7527e00`](https://github.com/Niko1221/Strata/commit/7527e00f0259f77d33766be7939b7370d41b5216) Test published-size recovery and download verification boundaries ### 📊 Changes **2 files changed** (+112 additions, -1 deletions) <details> <summary>View changed files</summary> 📝 `setup.py` (+3 -1) ➕ `tools/test_setup_download_length.py` (+109 -0) </details> ### 📄 Description ## Problem and result When HEAD and the one-byte range probe both fail to provide a length, `download()` treats an early EOF as completion even if Strata already has the file's published size. A short file is renamed out of `.part`, and verification either stops with a size error or, without a published hash, marks the fragment as finished. Use the published size for transfer completion as well as verification. The existing downloader then resumes an interrupted transfer, keeps partial bytes when retries run out, and publishes the file only after receiving the expected length. ## Related discussion #1915. Version 0.2 added a range probe, which covers missing HEAD length when that probe succeeds. This fix covers the remaining case where both probes lack a size. The original ModelScope URL supplied Content-Length when checked on October 22; the regression below reproduces the remaining condition with a local HTTP server. ## Approach After the transport probes, fall back to the repository pin's size, or ModelScope's published size when there is no pin. Reuse the existing metadata lookup for hash verification. ```text HEAD size → range-probe size → published size → existing download/resume logic ↓ size check → rename → hash check ``` The production diff moves the metadata lookup and adds a two-line fallback. Serial retries, parallel transfers, source identity and checksum verification retain their existing implementations. ## Validation Base: `011c9e60` (0.2.2 / engine 0.1.47). Final revision: `7527e00f`. Python 3.12 on macOS and Windows. ```sh python -m unittest tools.test_setup_download_length tools.test_setup_download -v ``` **Passed:** all 8 focused tests on both systems. They cover early EOF with a pin, metadata with and without a hash, exhausted retries preserving `.part`, parallel transfer after a failed initial probe, an already complete `.part`, a transport/pin size conflict and a wrong hash. Six of these fail on the unmodified base; the size-conflict and hash checks pass on both. The early-EOF fixture supplies 262,144 of 2,633,785 bytes before closing. The patched serial transfer resumes at byte 262,144 and produces the exact original bytes. Exhausting retries preserves those 262,144 bytes without a final file or `.done` mark. **Failed:** the combined suite passes 36/37 on both macOS and Windows. The shared redirect test counts the first piece twice (`[0, 0, 1, …, 40]` instead of `[0, 1, …, 40]`). It uses a successful HEAD length, so this fallback is not entered. The production code for that path is unchanged. The same 37 tests on unmodified main report 4 failures and 3 errors on both systems, including the six focused regressions above. **Not run:** another multi-gigabyte transfer through the original reporter's network. All transfer tests above use real HTTP requests to a local server; published metadata is supplied by the fixture. ## Limits If neither transport probes nor published metadata provide a size, the existing unknown-length behavior remains. The fallback does not replace hash verification or change which model files Strata accepts. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-07 15:32:03 +07:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Niko1221/Strata#3963
No description provided.