Repository navigation
Studio desktop: leave the startup screen on server-port instead of at the next 500 ms poll - #15673
Merged
Merged
Conversation
danielhanchen
marked this pull request as ready for review
October 28, 2026 09:20
Member
Author
|
@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. |
Member
Author
|
@codex review |
|
Codex Review: Didn't find any major issues. Can't wait for the next one! 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". |
wasimysaid
added a commit
to wasimysaid/unsloth
that referenced
this pull request
Oct 28, 2026
danielhanchen
added a commit
that referenced
this pull request
Oct 28, 2026
#15745) ## Summary `Repo tests (CPU, rest)` fails on main with three guard failures. It shows on every staging CI run of recent PRs (#15613, #15615, #15673 and others), whatever the PR changes: ``` tests/test_rendezvous_port_everywhere.py::test_distributed_tests_take_their_port_from_the_shared_helper tests/test_gc_skip_auto_dist_cells.py: _free_port does not use tests._rendezvous_port tests/test_gc_skip_auto_dist_gloo.py: _free_port does not use tests._rendezvous_port tests/test_source_read_encoding.py::test_checked_in_file_reads_name_an_encoding[5] tests/test_mamba_fused_lora_adapters.py:464: read_text() tests/test_source_read_encoding.py::test_checked_in_file_reads_name_an_encoding[13] tests/test_refresh_moved_layer_devices.py:81: read_text() ``` These tests landed around the same time as the guards that now catch them: - 570b9b8 added the two `gc_skip_auto_dist` gloo tests with their own `bind(("127.0.0.1", 0))` port picker. That is the ephemeral-range race that #15679 moved every distributed test off, which produces `EADDRINUSE`. - 986558e and 7f3c5a1 read checked-in source with the platform default encoding, which breaks on Windows once the file gains a non-ASCII byte. The guards are right in all three cases, so the tests change, not the guards. ## Change - `tests/test_gc_skip_auto_dist_cells.py`, `tests/test_gc_skip_auto_dist_gloo.py`: `_free_port()` delegates to `tests._rendezvous_port.free_port()`, the same three lines every other distributed test uses. The now-unused `import socket` is dropped. - `tests/test_mamba_fused_lora_adapters.py:464`, `tests/test_refresh_moved_layer_devices.py:81`: `read_text(encoding = "utf-8")`. ## Testing - `tests/test_source_read_encoding.py` + `tests/test_rendezvous_port_everywhere.py`: 3 failed on main, 22 passed with this change. - The four touched test files under `-n 4`: 43 passed, 4 skipped.
danielhanchen
added a commit
that referenced
this pull request
Oct 28, 2026
…ashing it (#15763) ## Summary The macOS `Chat UI, API, Update and GGUF inference` job fails on unrelated PRs (seen on #15696 and #15673 today) after 50 to 75 minutes in Studio setup: ``` [node-prebuilt] downloading https://nodejs.org/dist/v24.22.1/node-v24.22.1-darwin-arm64.tar.gz Downloading node-v24.22.1-darwin-arm64.tar.gz: 12.1% (6.1 MiB/50.6 MiB) at 1.6 KiB/s [node-prebuilt] node-v24.22.1-darwin-arm64.tar.gz checksum mismatch 1/2: expected=89c6... actual=8014... ... [node-prebuilt] prebuilt unavailable: node-v24.22.1-darwin-arm64.tar.gz checksum mismatch after retry error studio setup failed (exit code 1) ``` 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: 1. **Truncated bodies are accepted.** `http.client.HTTPResponse.read(amt)` returns `b""` when the server closes before `Content-Length` bytes arrive, without raising `IncompleteRead` (CPython leaves this as a known compatibility trade-off). The copy loops in `install_node_prebuilt.download_file`, `prebuilt_core.download_file` and `prebuilt_core.download_bytes` stop 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. 2. **A trickle never times out.** The 120 s socket timeout is per read, so a connection that keeps delivering a few bytes a second holds an attempt open indefinitely (1.6 KiB/s above, over 30 minutes per attempt). ## Change - `prebuilt_core.copy_response_body`: one body-copy helper used by all three loops. - Raises `TruncatedDownload` (a subclass of `http.client.IncompleteRead`) when the body ends short of `Content-Length`. - Raises `StalledDownload` (a `TimeoutError`) when a 60 s window brings under 256 KiB, about 4 KiB/s, and the body is not yet complete. - Reads a real `http.client.HTTPResponse` with `read1`, 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. - Both exceptions are already classified as retryable by `is_retryable_url_error` in both modules, so the existing retry loops reconnect instead of hashing a partial file or waiting on a dead connection. Bodies without `Content-Length` (chunked) keep their current behaviour; http.client already raises on a cut chunked body. ## Testing - New `tests/studio/install/test_download_truncation_and_stall.py` (11 tests) runs against a real local HTTP server, because the `read(amt)` EOF behaviour is what is under test and a `BytesIO` double cannot reproduce it: - a body closed at 25% raises a retryable `TruncatedDownload`; - `download_file` (Node and llama.cpp paths) and `download_bytes` reconnect and finish with the full payload; - a server that truncates every attempt is refused with no partial file left behind; - a trickling body is abandoned, a slow but moving one is not, and a window closing on the final byte is not a stall. - a real server sending the full `Content-Length` then one byte every 50 ms is abandoned within the (shortened) window, and `download_file` reconnects past it on both paths. - Sabotage: with only the truncation check removed, 5 tests fail; with only the stall check removed, the trickle test fails; with plain `read` instead of `read1`, the three real-trickle tests fail (the call blocks until the server gives up). - `tests/studio/install` base 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). - Real download through the new path: `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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When the desktop app starts its managed backend, the frontend waits for the validated port in
waitForManagedServerPort, which checkedportRefand then slept a fixed 500 ms. Theserver-portlistener set the port at once, but the startup screen only switched to the app at the next poll tick, 0 to 500 ms later. This PR lets theserver-portlistener wake that wait, so the switch happens as soon as the port is known.What changes
studio/frontend/src/hooks/managed-server-port.ts(new): the startup loop moves here unchanged, pluscreatePortWakeSignal(), whosewait(ms)sleeps like before but can be cut short bynotify().studio/frontend/src/hooks/use-tauri-backend.ts: the hook passes the signal'swaitto the loop and callsnotify()in theserver-portlistener, right aftersetApiBase(port).setApiBase(port)in the listener, thensetApiBaseandsetRunningStatusinstartManagedServer. Anotify()with nobody waiting is a no-op, and an aborted start still returnsaborted.server-crashedandserver-start-timeoutare not wired to the wake: their listeners already set the error and clearstartingRef, so waking the loop early would change nothing on screen.Results
Linux x86_64, release desktop build under Xvfb with a real managed backend, interleaved launches. Time from the
server-portemit to the UI'srunningstatus: 358.9 ms [97..467] on main vs 4.7 ms [3..11] here (n=6 each), and 170.4 ms [10..422] vs 2.7 ms [2..5] in a second interleaved set (n=5 each). Every run of both arms showed the same state sequence (Checking...,Starting Unsloth...,Loading models...,Nearly done..., then the app).Tests
studio/frontend/tests/managed-server-port-wake.test.ts(new, 5 tests):server-portends the wait well under the poll interval; without a notify the wait still polls; a known port skips the wait and an aborted start reports aborted; a notify with nobody waiting does not cut short a later wait; the hook callsnotifyfrom itsserver-portlistener. It fails on main (no module) and passes here.use-tauri-backend.ts(74 tests) pass here; on main the 9 existing files pass (69 tests).node scripts/typecheck.mjs --testsis clean. eslint onuse-tauri-backend.tsshows the same 2 errors as main (TauriInvokeunused,set-state-in-effect).Not covered