Repository navigation
fix(studio): show a download start the moment it is requested, and ke… - #13738
Conversation
…ep its unsloth_zoo import off the post-warm torchao imports A chat picker download ran its whole preflight (install transport setting, Auto probe, sibling and partial checks, the start itself) with nothing on screen. Right after launch the first two requests import unsloth_zoo for the Xet health verdict, which competes with the torch warm, so the click looked dead for several seconds before the download panel and toast appeared. The download manager now publishes every start it is running to a small display store for the duration of the preflight, and the downloads panel shows it at once unless a queued plan already shows the same transfer (matched by job key, so a different quant or companion plan of the same repo does not hide it): a row whose key is already listed (a retry inside a finished row's linger) reads "Starting…" in place, with its outcome icon hidden and Dismiss disabled until the job exists, and a start with no row of its own gets one. Feedback lands within a frame on every surface that calls requestStart. The same zoo import overlapped the post-warm worker's torchao and diffusers imports from a different entry point, which left a half-built torchao.kernel and a memoised "health unavailable" for the rest of the process. The shim now holds the media import window around its zoo imports (bounded like the load-side claim, pass-through for the owning thread and under the dynamo gate kill switch), taken outside the env-var lock so a worker spawn never waits behind a background import. The gate timeout setting is clamped to what a lock can wait, so an unbounded value no longer raises out of the loaders or skips the dynamo gate.
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. |
This comment was marked as resolved.
This comment was marked as resolved.
A scoped download that starts while a terminal row with the same key is still lingering reuses that row for its "Starting…" state. The documents and decision API settings pages start file sets of one repo directly under one scope key, so a second selection within the linger showed the previous transfer's label, filename, asset note and installation details under "Starting…" until the new job replaced the row. The row now renders the pending start's own metadata while it is starting and keeps the previous job's installation details out of it.
|
@codex review |
|
Codex Review: Didn't find any major issues. You're on a roll. 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". |
|
@codex review |
1 similar comment
|
@codex review |
|
@codex review |
1 similar comment
|
@codex review |
|
Codex Review: Didn't find any major issues. Chef's kiss. 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". |
|
@codex review |
1 similar comment
|
@codex review |
|
Codex Review: Didn't find any major issues. What shall we delve into next? 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". |
Why
Right after launch, picking a quant to download in the chat model picker showed nothing for several seconds, up to ~10 s on a slow torch warm, until the download panel and the Xet toast suddenly appeared. The app stayed responsive; there was just no sign the click had landed.
requestStartruns the whole preflight with no UI: the install transport setting (GET /api/settings/download-transport, forced when the browser has no saved choice), the Auto probe (GET /api/studio/download-transport-capabilities?probe=1), the sibling and partial checks, then the start itself. The first two compute the transport row with the RAM gate and the probe on, sohub/utils/download_registry.pyasksxet_health, and that imports the wholeunsloth_zoopackage on the request thread: about 5,400 modules, ~3 s idle and +312 MB RSS. Right after launch that import competes with the startup torch warm (7-13 s on the machine this was measured on), neither request has a client timeout, and the only feedback was the panel plus toast, which appear once a job exists. Context: #7742 put the zoo-backed health verdict on the start path, #8564 deliberately dropped the startup zoo warm (312 MB, "optional GPU consumers stay cold"), #9272 added the serial settings request, and #12472 makes the import wait on the warm's dynamo import. A startup prewarm was not an option for the same 312 MB reason.The same import also raced the post-warm worker from a second entry point: the request thread imports triton then
torchao.kernel, the post-warm worker imports torchao then diffusers, and CPython's import deadlock detector handed one side a partially initialisedtorchao.kernel. That leftunsloth_zoo.hf_xet_health unavailable (... partially initialized module 'torchao.kernel')memoised as "no verdict" for the rest of the process, plustorchao is unusable: KeyError: 'torchao', in 2 of 5 cold clicks.What
Frontend: feedback within a frame of the click.
hub/download-manager/pending-starts.tsis a small display store.runWithPendingStartGuardpublishes the start after its busy/already-started early returns and retires it infinally; retire removes only the entry that guard published, so a session reset mid-preflight plus a re-click cannot drop the second start's feedback. The store resets with the rest of the download manager state.Backend: one import at a time for the torch compile stack.
torch_warmup.hold_media_import_window(reason)holds the existing media import window around a foreground import: non-blocking acquire, then a wait bounded by the dynamo gate timeout with the same info/warning logs as the load-side claim; an expired wait still imports; pass-through for the thread that owns the window and underUNSLOTH_STUDIO_DISABLE_DYNAMO_IMPORT_GATE=1.utils/hf_xet_fallback.pytakes that window around itsunsloth_zooimports in both loaders, after the dynamo gate and outside_load_lock(nested, so the window-outer / lock-inner order is explicit):child_environment_for_spawnholds_load_lockaround every worker spawn, so a spawn never waits behind a background import, and the post-warm worker's torchao and diffusers imports now wait behind the zoo import instead of interleaving with it. Each load opens one window, so a failed first attempt keeps the window for its retry rather than waiting twice._dynamo_gate_timeout()clamps tothreading.TIMEOUT_MAX: an unbounded setting (inf) madeLock.acquireraise out of the loaders and silently skipped the existing dynamo gate.torchao.kernelafterwards; a request that lands during the post-warm imports waits for them (1-9 s here) rather than poisoning them.Tests
tests/download-pending-start.test.ts: the entry is visible from the first held preflight request until the backend accepts; a second click returns busy without a second entry; an unreachable backend and a rejected start (accepted: false, error row) both leave no entry; a restart inside a cancelled row's linger keeps that row and marks it starting; the visible set yields to an active job and to a queued plan for the same transfer but not to another plan of the same repo; retire removes only the published entry; the panel derives both row kinds from the same visible set.download-panel-not-permanent.test.tsrecognises the new list local in the panel's null guard.studio/backend/tests/test_xet_import_window.py(15 tests): both loaders import inside the window as its owner; a load waits for a background media import in flight and still runs when the wait expires; a failed first attempt keeps the window for its retry; an expired wait logs and releases nothing; a failure inside the window releases it; the kill switch and the owner thread pass through; an unbounded timeout setting waits instead of raising; the loaders run unguarded whentorch_warmupis unavailable; AST pins that every zoo import in the shim sits inside a window, that each loader opens exactly one, and that the gate runs before the window and the window wraps_load_lock.main; backend shim/warm/hub tests pass in a full venv, with only the pre-existing environment failures elsewhere.Notes
threading.Lock,get_ident,perf_counterand a zustand store, so Windows, macOS, Linux, browsers and the desktop WebView behave the same.unsloth_zoo_downloadspackage (20 ms, 119 modules). Once a zoo with it ships, the shim can import that first and fall back to the old names, which removes the init from the first download entirely; the pending-start row then covers a preflight of milliseconds.Before / after
Two isolated Studio installs, BEFORE = merge base
daab3bcd8, AFTER = this PR. The download preflight is held for 10 s so its window is the same on both sides; the shot is taken 1.5 s after clicking Download onunsloth/SmolLM2-135M-Instruct-GGUF(F16), and the start request is aborted so nothing is fetched.Downloads panel corner: BEFORE shows nothing while the preflight runs; AFTER shows the panel with a "Starting…" row for the repo.
Full Model hub page at the same moment (the quant card's own "Starting…" button is unchanged on both sides; only the Downloads panel differs):