Repository navigation
Installer downloads: retry a body cut short or trickling instead of hashing it - #15763
Conversation
…ashing it http.client's read(amt) returns b"" when the server closes before Content-Length, so the Node and llama.cpp prebuilt download loops accepted a truncated archive and reported it as a checksum mismatch (or, with no published digest, handed it to the extractor). A body trickling in at a few KiB/s never trips the per-read socket timeout, so one stalled connection held macOS setup for over an hour. copy_response_body in prebuilt_core now raises TruncatedDownload (an IncompleteRead) when the body ends short and StalledDownload (a TimeoutError) when a 60 s window brings under 256 KiB; both are already retryable, so the existing loops reconnect.
|
@codex review |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 6d8e0062d6
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| window_start = time.monotonic() | ||
| window_bytes = 0 | ||
| while True: | ||
| chunk = response.read(chunk_size) |
There was a problem hiding this comment.
Let the stall watchdog run before a full chunk arrives
For a real HTTP response, read(65536) waits for the entire requested amount (or EOF), rather than returning each available fragment as the _Trickle test double does. A server delivering one byte per second therefore blocks this call for roughly 18 hours while continually resetting the socket timeout, so the new 60-second stall check cannot run and installation still hangs. A local HTTP-server reproduction with a shortened watchdog window confirms that the check only executes after the server closes. Use an available-data read such as read1, with appropriate deadline handling, and exercise the stall test against a real streaming response.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Right, the _Trickle double returned whatever it had, which a real HTTPResponse.read(65536) does not: it waits for the full 64 KiB, so a slow sender kept the watchdog from ever running.
Fixed in a229b16: a real http.client.HTTPResponse is now read with read1, which returns what one receive brings, so the window check runs at least once per socket timeout. Other bodies (file:// mirrors, test doubles) keep plain read.
Added a stall test against a real local server that sends the full Content-Length header and then one byte every 50 ms, plus download_file (Node and llama.cpp paths) reconnecting past it. With the old read all three fail: the call blocks until the server gives up after 10 s and reports 200 bytes in the last 10s. With read1 it is abandoned within the 0.3 s test window and the retry completes. A real nodejs.org download through the new path still verifies (55.6 MiB in 0.24 s).
HTTPResponse.read(n) waits for all n bytes, so a connection sending one byte a second blocked a 64 KiB read for hours and the window check never ran. read1 returns what one receive brings. Adds a stall test against a real trickling server; with plain read it blocks until the server gives up.
|
@codex review |
|
Codex Review: Didn't find any major issues. Nice work! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
) ## Summary #15763 broke `tests/python/test_windows_setup_download_progress.py` on main (seen on the #15693 staging run; reproduces locally wherever `pwsh` is installed): ``` test_windows_real_download_reports_progress_while_active[node|llama|whisper] E assert [0.3, 5.2, 10.0, 15.0, 20.0] == [5, 10, 15, 20] ``` To let the new stall window fire on a trickling connection, #15763 reads real HTTP responses with `read1`, which returns what one receive brings. It also moved the progress update onto every receive, so the first percent line now appears at 0.3% and the milestones print at whatever receive crosses them (5.2%) instead of at the whole 1 MiB reads the installers used before. The progress text the Windows setup scripts relay changed shape, which is what this test pins. ## Change `prebuilt_core.copy_response_body`: - the chunk size is back to 1 MiB; - on the `read1` path each read asks only for the bytes up to the next 1 MiB boundary, and progress is reported when the boundary is reached, so the updates land exactly where whole-chunk reads put them; - the stall window is still checked after every receive, so a trickle is still abandoned within the window; - plain `read` bodies (file:// mirrors, test doubles) read whole chunks and report each one, as before #15763. ## Testing - All 23 test files that touch the installer downloaders, main vs this branch: the only difference in failing IDs is the three `test_windows_real_download_reports_progress_while_active` cases, which now pass. The 21 `tests/studio/install/test_dependency_pass_skips.py` failures and the `tests/utils/aime_eval.py` collection error are on both sides on this host. - New `test_progress_on_a_real_response_lands_on_whole_chunks`: a real local server streams 4 MiB in 48 KiB writes and progress must be updated at exactly 1, 2, 3 and 4 MiB. It runs without `pwsh`, so Linux CI covers the shape too. - Sabotage: reporting progress on every receive again fails the new test and all three PowerShell cases. - The trickle tests from #15763 still pass (the stall is detected within the shortened window), and a real nodejs.org download verifies (55.6 MiB in 0.27 s).
Summary
The macOS
Chat UI, API, Update and GGUF inferencejob fails on unrelated PRs (seen on #15696 and #15673 today) after 50 to 75 minutes in Studio setup:The archive was never tampered with: it was 6.1 MiB of a 50.6 MiB body. Two installer bugs turn a flaky connection into that:
http.client.HTTPResponse.read(amt)returnsb""when the server closes beforeContent-Lengthbytes arrive, without raisingIncompleteRead(CPython leaves this as a known compatibility trade-off). The copy loops ininstall_node_prebuilt.download_file,prebuilt_core.download_fileandprebuilt_core.download_bytesstop at the first empty read, so a short file is written out and hashed. For Node that surfaces as a misleading checksum mismatch; for a llama.cpp asset with no published digest the short archive goes straight to the extractor.Change
prebuilt_core.copy_response_body: one body-copy helper used by all three loops.TruncatedDownload(a subclass ofhttp.client.IncompleteRead) when the body ends short ofContent-Length.StalledDownload(aTimeoutError) when a 60 s window brings under 256 KiB, about 4 KiB/s, and the body is not yet complete.http.client.HTTPResponsewithread1, which returns what one receive brings.read(n)waits for all n bytes, so on a trickle it would block for hours and the window check would never run.is_retryable_url_errorin both modules, so the existing retry loops reconnect instead of hashing a partial file or waiting on a dead connection. Bodies withoutContent-Length(chunked) keep their current behaviour; http.client already raises on a cut chunked body.Testing
tests/studio/install/test_download_truncation_and_stall.py(11 tests) runs against a real local HTTP server, because theread(amt)EOF behaviour is what is under test and aBytesIOdouble cannot reproduce it:TruncatedDownload;download_file(Node and llama.cpp paths) anddownload_bytesreconnect and finish with the full payload;Content-Lengththen one byte every 50 ms is abandoned within the (shortened) window, anddownload_filereconnects past it on both paths.readinstead ofread1, the three real-trickle tests fail (the call blocks until the server gives up).tests/studio/installbase vs head on this host: identical failing test IDs (21, all pre-existing on main here), 10274 passed at base and 10282 with this change (the 8 new tests).node-v24.22.1-linux-x64.tar.gz(55.6 MiB) from nodejs.org verified against the pinned sha256 at 378 MiB/s, so the smaller reads cost nothing.