Skip to content

Studio: let the download transport be picked in Settings > General - #9272

Merged
danielhanchen merged 14 commits into
mainfrom
default-downloads-to-https
Aug 25, 2026
Merged

danielhanchen merged 14 commits into
mainfrom
default-downloads-to-https

Conversation

@shimmyshimmer

@shimmyshimmer shimmyshimmer commented Aug 19, 2026 •

Copy link
Copy Markdown
Member

What this changes

Which transport a download runs on is a real setting now: Settings > General > Downloads > Download transport, offering HTTPS, Xet and Auto.

Before this, the only place to pick one was a small toggle on the Hub page. That put the choice in a single browser's localStorage, so it did not follow the install, it was invisible to anyone who never opened the Hub, and nothing in the UI said what the two transports actually differ on.

What it does not change

No default moves. An install where nobody has touched the row still runs on Auto, exactly as before, and the download request path is untouched: a request that states neither transport_mode nor use_xet resolves the same way it did on main. The only behaviour that changes is the behaviour someone asks for.

The copy

The row explains the trade-off rather than just naming the two, since the difference matters and is not guessable:

  • HTTPS is plain TLS. Every network, proxy and VPN allows it, a cancelled or dropped transfer resumes from the bytes already on disk, and memory use stays flat.
  • Xet fetches deduplicated chunks, so a repo sharing data with one you already have can arrive much faster. It needs hf_xet, uses more RAM, and a cancel discards the file in flight.
  • Auto asks the machine: it weighs free RAM and whether Xet has been stalling here, and falls back to HTTPS.

Xet with no hf_xet installed is shown disabled with the reason, rather than as a selected option that silently downloads over HTTPS. Under Auto the row says which transport is in force on this machine and why.

How it is stored

download_transport_mode in app_settings, read and written through GET/PUT /api/settings/download-transport. Unset reads as Auto and nothing is written until someone picks.

The preference resolves as: this browser's own choice, then the install's setting, then Auto. A download start awaits the install setting rather than reading whatever is cached, so a browser that has never chosen still follows a transport picked elsewhere on the same install.

Tests

  • studio/backend/tests/test_download_transport_setting.py: the default, junk on disk, an unreadable db, validation, and both routes.
  • studio/frontend/tests/download-transport-setting.test.ts: the resolution order, the default staying Auto, the download start awaiting the setting, the row's options and status line, and that the copy explains the difference.
  • studio/frontend/tests/transport-mode-auto.test.ts: updated for the constant now being a floor rather than the whole answer.

12 locales carry the new strings and the parity check passes.

Note: the branch name predates the scope change and no longer describes the PR.

@shimmyshimmer

Copy link
Copy Markdown
Member Author

Rebased onto main. The three reds on the previous run were all main's, and each is fixed in the new base:

The revert in #9293 lands in the same files this branch edits (poll-loop.ts, hub/schemas/downloads.py, the model and dataset download services), so I checked the result rather than trusting a clean rebase: typecheck clean, 4033 frontend tests pass, and the backend download and settings suites pass, including the 13 new transport tests and test_scoped_download_job.py.

Local runs also show three tests/test_video_routes.py failures and five in tests/test_hf_cache_settings.py, both macOS only and both reproducing on plain origin/main with this branch checked out nowhere near them.

@danielhanchen

Copy link
Copy Markdown
Member

Confirmed the default today is Auto in download-manager/constants.ts and Auto resolves to Xet in download_registry.py, so every new install downloads on a transport it never picked, and the grandfathering seed keeps existing installs on Auto. One small thing: transport-mode-auto.test.ts now refers readers to transport-preference-order.test.ts, which does not exist on this branch.

@shimmyshimmer
shimmyshimmer force-pushed the default-downloads-to-https branch from 4668adf to fb4d8a8 Compare August 20, 2026 11:02
@shimmyshimmer

Copy link
Copy Markdown
Member Author

Right on both counts, thanks.

The cross-reference was stale: transport-preference-order.test.ts was an earlier name for the file and never landed under it. The decision logic lives in download-transport-setting.test.ts, which imports pickTransportMode from constants.ts and reads transport-preference.ts as source for the parts a .tsx barrel keeps out of node's loader. The comment in transport-mode-auto.test.ts points there now.

I also swept every file name the diff mentions in an added line against the tree, and that was the only one that did not resolve.

Rebased while I was in there. 4095 frontend tests pass, typecheck clean, and the backend transport and scoped-download suites pass on the new base.

@danielhanchen

Copy link
Copy Markdown
Member

The stale cross-reference is gone, grep -rn "transport-preference-order" is empty on the branch. Reproduced your numbers on Linux too: 4095/4095 frontend tests, i18n:check clean across all 12 overlays, and the 13 new backend transport tests pass. The two macOS failures you called out do not appear here, which fits your read of them. The branch is 129 commits behind but git merge-tree against today's main is conflict-free.

I checked the parts I thought could bite and most of them are fine. The use_xet tri-state is threaded correctly: the only two read sites are hub/services/models/downloads.py:221 and hub/services/datasets/downloads.py:169, both pass Optional[bool] straight through, there is no truthiness check anywhere, and resolve_requested_use_xet(None, False) correctly stays HTTP instead of falling through to the setting. HF_HUB_DISABLE_XET goes into the per-spawn env dict at download_lifecycle.py:206, never os.environ, so concurrent downloads cannot leak into each other. The new routes match the /helper-precache auth tier. And the resolution order really is browser then install then HTTPS, with the start-before-resolve race closed by the awaits at poll-loop.ts:586 and transport-conflict.ts:147.

One blocking problem though.

The grandfather check reads a table almost anything can write

_PRIOR_USE_TABLES at utils/download_transport_settings.py:27 includes app_settings, and line 58 counts any row in it as prior use. But app_settings is the generic key value store, written by around fifteen unrelated subsystems. The seed is lazy, so whatever touches app_settings first decides the transport.

Your verification is right that a full boot leaves all three tables empty. The problem is what happens after boot. I drove three pristine installs through a real studio.db, no stubbing of the predicate:

a brand-new install that rows in app_settings _has_prior_studio_use() seeded
boots, then downloads 0 False http
boots, opens the Images page, then downloads 1 True auto
boots, picks a dark theme, then downloads 1 True auto

Opening Images needs no user edit at all. use-media-generation-presets.ts:281-292 autosaves with no dirty check, so 400ms after the page mounts it PUTs the presets, and that lands in app_settings via utils/media_generation_preset_settings.py:69. The hook is mounted unconditionally by images-page.tsx:1417 and video-page.tsx:1253, and those pages stay mounted once visited. So a new user who clicks Images once, changes nothing, and then downloads their first model gets Xet, permanently, and the log line says the install was grandfathered.

Chatting with an API model before the first download does the same thing through chat_threads.

The reason the suite is green on this is that every seed test stubs _has_prior_studio_use (test_download_transport_setting.py:52 and :64), so the predicate under test is the one thing never exercised. The manifest branch is the only real evidence in there.

Two ways out that both look clean to me. Seed eagerly in the lifespan hook at main.py:627, where you have already shown the tables are empty and no route can have run yet. Or drop app_settings from the evidence list and lean on the manifests check, which is the only signal that actually means "this install downloaded something before". The first is the smaller change and it makes the ordering a property of the code rather than of what the user clicks.

The Hub toggle now writes install-wide

catalog/transport-toggle.tsx:41-45 auto-corrects xet to http when hf_xet is missing. That effect predates this PR, but setMode does not: after this branch it also PUTs /api/settings/download-transport (transport-preference.ts:124). So on an install whose resolved mode is xet and whose hf_xet has since broken or been removed, merely loading the Hub models page silently rewrites the install-wide setting for every other browser and every scripted caller, with no user action and nothing shown.

Worth noting DownloadTransportRow deliberately does not auto-correct: it keeps Xet selected and surfaces the reason instead, and the comment at download-transport-row.tsx:64 says why. The two controls now disagree about what "Xet selected but unavailable" means, and the Hub one wins because it is the one that writes. Making the Hub effect write only localStorage would keep its old browser-local behaviour.

Smaller things

download-transport-row.tsx:53-55 swallows a failed GET, which leaves settings null, so xetUnavailable at line 59 is false and the Xet button stays enabled on a machine that cannot run it. The user picks it, it is persisted both places, and the downgrade only surfaces as a toast at download time. download-transport.ts:61 passes xet_available through unvalidated for the same end state, where its sibling transport-capabilities.ts:59-92 validates every field and explains in its header why.

A failed PUT is console.warn only (transport-preference.ts:124-129), after localStorage and setMode have already landed, so the row shows the choice as saved while the install setting did not move. Five lines up the localStorage failure path does toast.error, which is the behaviour I would expect here too.

cachedTransport (download-transport.ts:35) is never invalidated or refetched, so a tab that was open when a script PUT the setting keeps the old one for the life of the page, and installing hf_xet while Studio is open leaves the Xet button disabled until a reload.

The new await at poll-loop.ts:586 has no AbortSignal (download-transport.ts:77 sets none) and sits outside the try/catch that calls teardownRuntime at :591. Every other transport call in that module is bounded, transport-conflict.ts:70 included. If the settings endpoint hangs, the job is already in the runtime registry with no poll and no error.

core/inference/openai_auto_download.py:861 states no transport, so OpenAI-compatible auto-downloads move from Xet to the install setting. That is the intent of the change rather than a bug, but it is the one caller that changes behaviour without anyone editing a request, and no test covers it.

Last one on tests. download-transport-setting.test.ts:53-76 asserts the two claims the PR leans on hardest, that a download waits for the setting and that a choice is saved install-wide, by regexing and indexOf-ing the source files rather than by running anything. The first would pass on a resolveTransportMode that returned HTTPS immediately, and the row assertions at :78-91 never render the component, which is why the disabled-Xet gap above is invisible to them.

@danielhanchen

Copy link
Copy Markdown
Member

Pushed the fixes to this branch in ae4bff0. Answering the questions I was left with after the review, in order.

Is this a real problem or a fake one

Real, and I reproduced it rather than argued it. Before this PR the transport preference defaulted to auto, and auto resolves to Xet on any machine whose hf_xet looks healthy, so practically every install downloaded over a transport it never picked. That part of the diagnosis holds.

What did not hold was the fix. The seed was lazy, and its only triggers were the first download or the first settings GET. _has_prior_studio_use() counts any row in app_settings, and app_settings is the generic key value store around fifteen subsystems write to. So a brand-new install was grandfathered onto Xet by anything that got there first. The cleanest path needs no user edit at all: use-media-generation-presets.ts:281-292 autosaves with no dirty check, so opening Images or Video PUTs the presets 400ms after mount, and utils/media_generation_preset_settings.py:69 lands it in app_settings.

Before and after, same simulation, real studio.db, nothing about the predicate stubbed:

a brand-new install whose user before after
downloads straight away http http
opens the Images page first auto http
opens the Video page first auto http
picks a dark theme first auto http
sets a VRAM budget first auto http
chats with an API model first auto http

Five of the six ordinary paths were wrong. The fix seeds in the lifespan, before any route can serve, which is the only point where the tables still describe the install rather than what the user has clicked since.

Does merging break anything

Old installs, no. Every one of them was already writing to app_settings, so they were being grandfathered onto auto before and still are, and the seed now runs at boot rather than at the first download, which is earlier but reaches the same verdict. An install that already stored a choice keeps it: startup reads the stored value and returns without writing. Same matrix as above, run for four install ages:

install seeded
brand new http
used before this change auto
downloaded before this change, manifests only auto
already chose Xet xet

All four are stable across every one of the six first actions, so no ordering can move them.

Scripted callers, no. The use_xet change from bool = True to Optional[bool] = None is the one API semantic change, so I enumerated the whole product of transport_mode (8 values including junk and odd casing) times use_xet (None, True, False) times the install setting (http, xet, auto) and diffed every cell against the resolver reconstructed from origin/main. 72 shapes, 67 bit-identical. The 5 that move are exactly the requests that state neither field, which is the intended change. An explicit transport_mode or an explicit use_xet is never touched, including use_xet=False against an install set to Xet.

The one caller worth naming is core/inference/openai_auto_download.py:861, which states no transport, so OpenAI-compatible auto-downloads now follow the setting instead of always Xet. That is the intent of the change rather than a regression, but it is the only caller that moves without anyone editing a request.

New hardware paths, none added. The transport decision reads hf_xet health and free RAM and nothing else. I asserted that rather than assumed it: after driving the seed and the resolver, no torch, pynvml, cupy or pyamdgpuinfo module has been imported.

Simulations

Ten suites, all green, run from temp/pr9272_sim/run_all.sh. Highlights beyond the tables above:

The real startup path, not a stand-in. Each case runs the actual main.lifespan against its own studio.db in its own Studio home. A fresh install has http on disk once startup finishes, an install with history has auto, and an install that already chose Xet still has xet after a reboot.

[Windows, Linux, WSL, macOS] x [NVIDIA, AMD, CPU only], 12 cells, all new=http old=auto. Two axes are inert and the suite proves it rather than asserting it: the accelerator axis because nothing on the path imports a GPU module, and the platform axis because the transport decision contains no sys.platform, os.name or platform.system() branch at all. Code that never asks cannot answer differently. Each cell still runs under that platform's real Studio home layout, including a path with spaces. The two sys.platform reads that do exist in download_lifecycle.py are the pre-existing start_new_session and the Windows cancellation exit code, neither on this path nor touched here. Real Windows and macOS runs stay CI's job.

Robustness: a db held under BEGIN EXCLUSIVE by a sibling Studio, a read-only db, 32 threads racing the very first read, and a Studio home with spaces in it. The thread race is what turned up the write-once problem: 32 threads produced 19 identical seed writes, now 1.

Browser engines. The repo already drives chromium, firefox and webkit in studio-ui-smoke.yml, which covers Chrome and Edge through Chromium and Safari through WebKit, and those shards are green here. What that cannot vary is the capability profile of older builds, which is what the new timeout depends on, so I ran the real modules under five profiles: Chrome/Edge 124 and Firefox 125, Safari 17.0, Safari 16 and WebKitGTK 2.40, Safari private browsing, and Firefox with storage blocked. All five behave identically. AbortSignal.timeout is only Baseline as of April 2024 and Safari was the last engine to ship it, which is exactly why the new read goes through disposableTimeoutSignal rather than calling it directly. A storage engine that throws still resolves the preference and still reports a refused write instead of half-applying it.

Dependency weight. The startup seed runs in a clean uv venv whose only package is structlog, importing no torch, fastapi, pydantic or numpy, so it adds nothing to boot.

What I changed

main.py seeds in the lifespan. download_transport_settings.py no longer persists a seed decided from evidence it could not read, so a locked db at boot cannot freeze an old install onto HTTPS, and it persists once under the lock.

transport-toggle.tsx keeps its automatic xet to http correction browser-local via a new installWide: false. The row falls back to the Hub's capabilities when its own read fails, so Xet is no longer offered on a machine without hf_xet, and xet_available is read as a strict true. The settings read is bounded, since a download start awaits it outside the try that tears the runtime down. A failed install-wide write now toasts. transport-preference.ts imports the settings module directly rather than through the barrel that imports this feature back.

Three things I deliberately left. cachedTransport still never expires, so a tab open across a scripted PUT stays stale until reload; fixing that properly means cross-tab invalidation and it is a separate change. The junk transport values in the matrix resolve to HTTPS rather than falling through to the setting, which is unreachable through the API because the schema is a Literal, and HTTPS is the safe end of that fallback anyway. And openai_auto_download.py still states no transport, which is correct, but it is worth a test of its own.

One note on the tests. download-transport-setting.test.ts asserted the row's behaviour with assert.match(ROW, /xetAvailable === false/) over the component source, and my change broke it while preserving the behaviour it names, which is the failure mode I flagged. That rule is now a pure function with a real test over all four states. Backend coverage now runs the real predicate against a real db instead of stubbing it, and I mutation-checked the unreadable-install guard to confirm the test fails without the fix.

Locally: 4096 frontend tests, typecheck clean, i18n:check clean across all 12 overlays, and the backend transport and scoped-download suites pass.

@danielhanchen

Copy link
Copy Markdown
Member

One more, and it goes at the copy rather than the code. CI on ae4bff0 is green, all checks, no failures.

HTTP does not resume on the huggingface_hub this branch ships against

The new Settings copy states, in all 12 locales, that HTTPS resumes:

  • transportDescription: "HTTPS resumes where it stopped"
  • transportHint: "a cancelled or dropped transfer resumes from the bytes already on disk"
  • httpsHint: "Resumes after a cancel, works on any network, steady memory use."

huggingface_hub 1.18 moved the writer from a shared <etag>.incomplete to a process-unique <etag>.<nonce>.incomplete, opened "wb" and unlinked in a finally (huggingface/huggingface_hub#4228, reported downstream as huggingface/huggingface_hub#4196). The nonce is fresh every run, so a partial can never be matched and continued. It was a deliberate trade for correctness on filesystems where flock silently succeeds for every caller, and the cost is refetching from zero.

Studio delegates to huggingface_hub and has no Range writer of its own, and the runtime pin is:

studio/backend/requirements/no-torch-runtime.txt:49
huggingface_hub>=1.23.0,<2.0; python_version >= "3.10"
huggingface_hub==0.36.2;      python_version <  "3.10"

So the claim holds only on a Python 3.9 install. Everywhere else it is false:

hf_hub hf_partials_are_resumable()
0.34.0, 0.36.2, 1.17.0 True
1.18.0, 1.23.0, 1.28.0 False

1.28.0 is current on PyPI.

The tree already knows this. _LAST_RESUMABLE_PARTIAL_VERSION = (1, 17) in hub/utils/hf_cache_state.py:51, the comment at download_registry.py:107 is "huggingface_hub >= 1.18, so the UI stops offering a byte-resume no writer can honour", download_registry.py:780 is "there is no resumer left to trust a partial for", and there is a dedicated hub/tests/test_process_unique_incomplete_repro.py.

The download cards handle it correctly today: downloadStopMode() in use-download-card-state.ts:39-52 labels the button Pause only when transport === "http" && partialsResumable, and Cancel otherwise, fed by useHttpPartialsResumable(). That hook's own comment says it exists so a card "never flashes a resume promise it may have to take back". The new Settings row is the one surface that makes the promise anyway; it never reads partials_resumable.

Why it matters beyond the wording

Resume is the load-bearing argument in the PR description. "A cancelled or dropped transfer starts the file again instead of resuming from the bytes already on disk" is listed first among Xet's drawbacks, but on the pinned hf_hub that is true of HTTPS as well, so the two are level there and the sentence reads as a distinction that does not exist.

The rest of the case is untouched and still good: HTTPS works through any proxy, VPN or inspected network, memory stays flat, there is no hf_xet dependency, and there is no stall-and-retry ladder. I still think HTTPS is the right default. It just is not the right default for this reason.

Suggested shape

I have not touched the copy, because rewording it correctly in 12 languages is your call and i18n:check only proves key parity, not meaning. Two options that both work:

  1. Gate the resume clause on the capability the app already computes. Split it out of the three strings into its own short key with a resumable and a non-resumable variant, and have DownloadTransportRow pick with useHttpPartialsResumable(), the same hook and the same rule the cards use. Costs two short keys per locale, and stays true if the pin ever moves back.
  2. Drop the resume claim from those three strings and describe only what holds on every supported hf_hub. Simpler, no runtime branch, and it gives up an accurate note on the 3.9 pin.

I would take the first. Happy to push either if you tell me which, including the locale edits.

Separately, partials_resumable is not on DownloadTransportResponse, so if you would rather the row not depend on the Hub capabilities call, adding the field to that response is the smaller wiring.

@danielhanchen

Copy link
Copy Markdown
Member

Opened #9602 for the resume problem, so the copy decision here can wait on it rather than be walked back.

Short version: the claim in this branch's copy is false today and true again if #9602 lands. huggingface_hub 1.18 stopped resuming HTTP partials, and no-torch-runtime.txt pins >=1.23.0,<2.0 on Python 3.10+, so every current install is past the cutoff. #9602 restores the 1.17 append-mode writer where it can prove flock actually excludes a second writer, and falls back to stock where it cannot.

Measured on an 800MB GGUF against 1.28.0, killed 8s in and restarted:

first attempt after restart
stock 1.28.0 346.0 MB in <hash>.b6fc75c1.incomplete 220.2 MB in <hash>.8aed49c6.incomplete, from zero, and the 346.0 MB orphaned
with #9602 262.1 MB in <hash>.incomplete 367.0 MB in the same file, resumed

Interrupted twice and then allowed to finish, the completed 807.7 MB file's sha256 matches the blob name, so the resumed bytes are correct and not just continuous.

If #9602 goes in first, nothing here needs changing: transportDescription, transportHint and httpsHint all become accurate as written, and the resume argument in the PR description holds again.

If it does not, the three strings need the distinction, because a network drop and a cancel behave differently even on 1.18+: the retry loop inside http_get does resume a dropped connection from an open handle, up to five times. It is the cancel and the killed process that lose everything. Something like "resumes after a network drop, restarts the file if you cancel" would be true on either version.

One correction to what I wrote earlier in this thread: I said flatly that HTTP does not resume on 1.18+. That is right for cancel and for a killed process, which is the case the copy is about, but too broad, since transient network errors within a single run still resume.

rhsCZ pushed a commit to rhsCZ/unsloth that referenced this pull request Aug 24, 2026
…ked for

Fixes for PR unslothai#9272.

Seed the transport in the lifespan, before any route can serve. The seed
counted any row in app_settings as prior use, and app_settings is shared by
around fifteen subsystems, so on a genuinely new install a single unrelated
write decided the transport. Opening the Images page was enough: its preset
autosave has no dirty check and PUTs 400ms after mount, so a new user who
looked at Images once and then downloaded a model got Xet, permanently.
Deciding at startup makes the ordering a property of the code rather than of
what the user clicked first.

Do not persist a seed decided from evidence that could not be read. An
unreadable install answers HTTPS for that process, as before, but no longer
writes it, so a locked db at boot cannot freeze an old install onto HTTPS.
Persist the seed once under the lock as well: concurrent first reads all saw
no stored value and each wrote it.

Keep the Hub toggle's automatic xet to http correction browser-local. It
predates this branch, but setMode now also PUTs the install setting, so
loading the Hub models page on a machine without hf_xet silently rewrote the
transport for every other browser and every scripted caller.

Fall back to the Hub's capabilities when the settings read fails, so Xet is
not offered on a machine that cannot run it, and read xet_available as a
strict true. Bound that read with the WebView-safe timeout ponyfill: a
download start awaits it, outside the try that tears the runtime down, so a
hung settings endpoint left a registered job with no poll and no error. Toast
when the install-wide write fails instead of only warning to the console, and
import the settings module directly rather than through the barrel that
imports this feature back.

Tests: the real predicate against a real studio.db rather than a stub, the
unreadable-install case, and the Xet availability rule as behaviour instead of
a regex over the component source.
Which transport downloads run on was a toggle on the Hub page, so the choice
lived in one browser's localStorage and most people never found it. It is a
row in Settings > General now, saved for the install through
/api/settings/download-transport, with the difference between HTTPS, Xet and
Auto spelled out in the copy.

No default changes. An install nobody has opened the row on still runs on
Auto, and the download request path is untouched: a caller that states nothing
gets exactly what it got before.
@shimmyshimmer
shimmyshimmer force-pushed the default-downloads-to-https branch from 5531c74 to 9be63ee Compare August 25, 2026 05:30
@shimmyshimmer shimmyshimmer changed the title Default new installs to HTTPS downloads, with an explicit transport toggle in Settings Studio: let the download transport be picked in Settings > General Aug 25, 2026
@shimmyshimmer

Copy link
Copy Markdown
Member Author

Rescoped: the HTTPS default is out, and what is left is the Settings row on its own.

Removed:

  • the seeding module that decided a default per install, along with the prior-use evidence (app_settings/chat_threads/training_runs rows, download manifests) it rested on
  • DEFAULT_TRANSPORT_MODE moving to HTTPS in download-manager/constants.ts, now back to Auto
  • the request-path changes in hub/schemas/downloads.py and hub/services/download_lifecycle.py, both reverted to main, so use_xet is still bool = True and a request that states nothing resolves exactly as it did before
  • the unused default_mode field on the settings response
  • "New installs use HTTPS" from the copy, in all 12 locales

Kept: the row itself, the download_transport_mode setting behind GET/PUT /api/settings/download-transport, the resolution order (this browser's choice, then the install's setting, then Auto), and the copy explaining what HTTPS, Xet and Auto actually differ on.

An install nobody has opened the row on now behaves identically to main. Verified: 4095 frontend tests, typecheck and build clean, 8 backend transport tests, and the wider backend download and settings suites at 783 and 752 passing. Locale parity passes.

Title and description updated. The branch name is left alone, since renaming it would detach this PR.

chatgpt-codex-connector[bot]

This comment was marked as resolved.

@danielhanchen

Copy link
Copy Markdown
Member

Before/after from two isolated installs, so the panel is built from each tree rather than one Studio with a checkout in between. BEFORE is this PR's merge base 7266f1b29, not main, which has moved a long way since.

Settings > General, before and after

BEFORE goes straight from "Documents & RAG" to "Uploads". AFTER inserts a "Downloads" section between them with the transport row.

BEFORE AFTER
Downloads section absent present
Transport options none HTTPS, Xet, Auto
Selected none Auto
Status line none Auto is using Xet on this machine.

Everything else in the panel is byte-for-byte the same neighbourhood on both halves (sidebar, Uploads, Helper LLM, Danger zone), which is what makes the one inserted section readable as the change rather than as two different scroll positions. The scene requires the untouched "Uploads" heading to be present on BOTH sides before it will report anything, so a BEFORE with no transport row is an absence rather than a click that missed.

The status line is also a useful confirmation of the default: with nothing configured the setting is Auto, and Auto resolved to Xet on this host, which matches download_registry's optimistic TRANSPORT_XET starting point before the health and free-RAM gates get a say.

Two notes, neither about the screenshots:

The branch is named default-downloads-to-https, but the code no longer does that. DEFAULT_DOWNLOAD_TRANSPORT = TRANSPORT_AUTO, and the comment says so explicitly. The name looks like a leftover from an earlier version of the idea.

pickTransportMode(stored, installed) puts this browser's localStorage choice ahead of the install setting. Since the stated point is that the choice should follow the install rather than one browser, that ordering is worth another look: a browser that has ever touched the Hub transport pill will keep ignoring the install setting. It also interacts with what just landed in #9660, whose Xet notice is gated on the resolved transport, so a browser pinned to HTTP would never see that explanation regardless of what the install is set to. I have not tested that interaction.

This branch is 197 commits behind main and currently conflicting, so the head builds but does not merge; the pair above photographs the head as pushed.

Two conflicts, both in studio/backend/routes/settings.py and both additive: this
branch's download-transport models and routes against the xet-notice ones from
#9660. Kept both.

The download manager auto-merged onto #9660's start-toast work: startJob and
requestStart now await resolveTransportMode(), so the install setting is honoured,
and the route each start toast is held against is still captured before that
await rather than after it.
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Aug 25, 2026
chatgpt-codex-connector[bot]

This comment was marked as resolved.

danielhanchen and others added 2 commits August 25, 2026 08:55
- the Hub's automatic Xet to HTTP fallback ran through the same setter, so merely
  opening the Hub without hf_xet rewrote the install-wide choice for every browser,
  permanently; it stays local now
- a download re-reads the install setting instead of trusting a cache held for the
  life of the tab, which is the whole point of an install-level setting
- install-wide writes are serialized, so two quick selections cannot leave the
  database on the mode the user did not pick
- the settings row asks for the free-RAM half of the Auto verdict, which the
  download path applies and this row skipped, so it no longer says Auto is using
  Xet on a machine whose next download picks HTTP
- HTTPS no longer promises a resume on an install whose huggingface_hub cannot do
  one; the row reads the capability it already has
- the Xet-unavailable reason uses the translated string rather than the backend's
  English prose, which made the new translations unreachable
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Aug 25, 2026
@unslothai unslothai deleted a comment from shimmyshimmer Aug 25, 2026
chatgpt-codex-connector[bot]

This comment was marked as resolved.

…ur ordering fixes

- the Hub toggle only falls back to HTTP once Xet is KNOWN unavailable; gating both
  that and the disabled state on the same flag showed HTTP for a stored Xet during
  the capability check, with nothing to put it back
- the hydration wrapper no longer memoizes past the refresh flag, so the API layer
  can apply its own freshness rule
- a completed write advances the request generation, so a read taken before it
  cannot land after and republish the replaced mode
- the settings row re-reads the install setting on mount
- the browser's transport override joins the local preference reset, since it
  outranks the install-wide setting
chatgpt-codex-connector[bot]

This comment was marked as resolved.

…stale one

A GET that a PUT or a newer refresh has superseded was kept out of the cache
but still resolved with its own payload. Both callers write that value into
their own state, so on a browser with localStorage unavailable the late
response visibly reverted the mode the user had just picked.
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Aug 25, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Aug 25, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Aug 25, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Aug 25, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Aug 25, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Aug 25, 2026
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Delightful!

Reviewed commit: 3af3e6616e

ℹ️ 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".

danielhanchen added a commit to Datta0/unsloth-staging-3 that referenced this pull request Aug 25, 2026
danielhanchen added a commit to Datta0/unsloth-staging-3 that referenced this pull request Aug 25, 2026
danielhanchen added a commit to Datta0/unsloth-staging-3 that referenced this pull request Aug 25, 2026
chatgpt-codex-connector[bot]

This comment was marked as resolved.

A download started before the first settings load answers overtakes it with a
refresh. When that refresh failed, the catch returned a still-null installMode
and the download ran on Auto, even though the request it overtook was about to
deliver the install's explicit choice.
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Aug 25, 2026
chatgpt-codex-connector[bot]

This comment was marked as resolved.

Hydrating from the cache on mount showed the old mode in the toggle while the
download path, which refreshes, already ran on the one another browser had set.
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Swish!

Reviewed commit: d095554fa4

ℹ️ 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".

@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Aug 25, 2026
@danielhanchen
danielhanchen merged commit 1e06ca0 into main Aug 25, 2026
28 of 52 checks passed
@danielhanchen
danielhanchen deleted the default-downloads-to-https branch August 25, 2026 10:50
danielhanchen added a commit to Datta0/unsloth-staging-3 that referenced this pull request Aug 25, 2026
danielhanchen added a commit that referenced this pull request Aug 25, 2026
…9272)

* Studio: let the download transport be picked in Settings > General

Which transport downloads run on was a toggle on the Hub page, so the choice
lived in one browser's localStorage and most people never found it. It is a
row in Settings > General now, saved for the install through
/api/settings/download-transport, with the difference between HTTPS, Xet and
Auto spelled out in the copy.

No default changes. An install nobody has opened the row on still runs on
Auto, and the download request path is untouched: a caller that states nothing
gets exactly what it got before.

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Fix six review findings on the download transport setting

- the Hub's automatic Xet to HTTP fallback ran through the same setter, so merely
  opening the Hub without hf_xet rewrote the install-wide choice for every browser,
  permanently; it stays local now
- a download re-reads the install setting instead of trusting a cache held for the
  life of the tab, which is the whole point of an install-level setting
- install-wide writes are serialized, so two quick selections cannot leave the
  database on the mode the user did not pick
- the settings row asks for the free-RAM half of the Auto verdict, which the
  download path applies and this row skipped, so it no longer says Auto is using
  Xet on a machine whose next download picks HTTP
- HTTPS no longer promises a resume on an install whose huggingface_hub cannot do
  one; the row reads the capability it already has
- the Xet-unavailable reason uses the translated string rather than the backend's
  English prose, which made the new translations unreachable

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Save the setting when localStorage is blocked, and stop mixing languages in the Auto line

- a browser with storage blocked returned before the install-wide write, so it
  could not change the transport at all; only a failure at both ends toasts now
- the Xet health reason is free-form English from the backend, so it goes on its
  own line instead of being interpolated into a translated sentence, and the key
  that interpolated it is removed rather than left unreachable

* Fix four follow-on findings on the download transport setting

- a failed per-download refresh kept the install mode already loaded instead of
  falling back to Auto
- adopting a job no longer waits on the settings route: that branch ignores the
  result, and suspending there let two concurrent adoptJob callers replace each
  other's runtime and leave duplicate poll timers
- ram_gate loads the health verdict rather than reading a cache that is empty on
  a fresh backend, still without the live probe
- Xet cannot be selected before its availability is known, and nothing claims
  hf_xet is missing while that is still pending

* Keep the automatic fallback out of storage, report failed install writes, index the row

- the Hub's Xet to HTTP fallback wrote localStorage before the opt-out was checked,
  and a local value outranks the install one, so the browser stayed pinned to HTTP
  after hf_xet was installed; it is reflected and stored nowhere now
- a settings PUT that fails is said out loud even when the local write worked: the
  row calls this install-wide, and only the console knew otherwise
- the Downloads section and its options join SETTINGS_SEARCH_INDEX, so searching
  Settings for transport, HTTPS or Xet finds the row this PR exists to expose

* Do not share a stale settings request, gate Hub Xet on hydration, index with targets

- a refreshing caller could ride on a hydration GET already answered with the old
  mode, which is the value it went to replace; refreshes share only with refreshes
  now, and a request generation stops an older response caching last
- the Hub toggle waits to know whether Xet can run, like the settings row: clicking
  it first stored a preference every later download quietly ignored
- the indexed HTTPS, Xet and Auto labels carry data-settings-label, so a search
  result has somewhere to scroll to instead of just opening General

* Separate 'cannot choose Xet yet' from 'Xet does not run here', and four ordering fixes

- the Hub toggle only falls back to HTTP once Xet is KNOWN unavailable; gating both
  that and the disabled state on the same flag showed HTTP for a stored Xet during
  the capability check, with nothing to put it back
- the hydration wrapper no longer memoizes past the refresh flag, so the API layer
  can apply its own freshness rule
- a completed write advances the request generation, so a read taken before it
  cannot land after and republish the replaced mode
- the settings row re-reads the install setting on mount
- the browser's transport override joins the local preference reset, since it
  outranks the install-wide setting

* Hand a superseded settings read the current value instead of its own stale one

A GET that a PUT or a newer refresh has superseded was kept out of the cache
but still resolved with its own payload. Both callers write that value into
their own state, so on a browser with localStorage unavailable the late
response visibly reverted the mode the user had just picked.

* Shorten the comments added by this PR

* Keep the hydration a failed refresh overtook as its fallback

A download started before the first settings load answers overtakes it with a
refresh. When that refresh failed, the catch returned a still-null installMode
and the download ran on Auto, even though the request it overtook was about to
deliver the install's explicit choice.

* Mount the transport controls on a refreshed install mode

Hydrating from the cache on mount showed the old mode in the toggle while the
download path, which refreshes, already ran on the one another browser had set.

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Daniel Han <[email protected]>
danielhanchen added a commit that referenced this pull request Oct 15, 2026
…se the first zoo import with the media import window (#13738)

### 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.

`requestStart` runs 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, so
`hub/utils/download_registry.py` asks `xet_health`, and that imports the
whole `unsloth_zoo` package 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 initialised
`torchao.kernel`. That left `unsloth_zoo.hf_xet_health unavailable (...
partially initialized module 'torchao.kernel')` memoised as "no verdict"
for the rest of the process, plus `torchao is unusable: KeyError:
'torchao'`, in 2 of 5 cold clicks.

### What

**Frontend: feedback within a frame of the click.**

- `hub/download-manager/pending-starts.ts` is a small display store.
`runWithPendingStartGuard` publishes the start after its
busy/already-started early returns and retires it in `finally`; 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.
- The downloads panel shows a pending start at once: 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; a start with no row gets its own row. Both
decisions come from one visible set, which hides a start when its job is
already active or when a queued plan already shows the same transfer.
That match is by job key, so a different quant or a companion plan of
the same repo does not hide the feedback, and the queued-entry producers
now carry the variant the key needs. The header count includes pending
starts and the panel no longer hides itself while one exists.
- Measured in the real UI on a cold backend: "Starting…" 0.2 s after the
click, instead of nothing until the preflight finished (4.8 s with the
backend pinned to two CPUs, ~10 s on a slower warm).

**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 under
`UNSLOTH_STUDIO_DISABLE_DYNAMO_IMPORT_GATE=1`.
- `utils/hf_xet_fallback.py` takes that window around its `unsloth_zoo`
imports in both loaders, after the dynamo gate and outside `_load_lock`
(nested, so the window-outer / lock-inner order is explicit):
`child_environment_for_spawn` holds `_load_lock` around 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 to `threading.TIMEOUT_MAX`: an
unbounded setting (`inf`) made `Lock.acquire` raise out of the loaders
and silently skipped the existing dynamo gate.
- Measured: 0 of 4 cold clicks hit the partially initialised
`torchao.kernel` afterwards; 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.ts` recognises
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 when
`torch_warmup` is 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`.
- On this tree: frontend suite 12,116 passing, typecheck and ESLint
unchanged against `main`; backend shim/warm/hub tests pass in a full
venv, with only the pre-existing environment failures elsewhere.

### Notes

- Nothing platform-specific: `threading.Lock`, `get_ident`,
`perf_counter` and a zustand store, so Windows, macOS, Linux, browsers
and the desktop WebView behave the same.
- Left as is: there is no Cancel during a preflight (before there was no
row at all); a cancelled row's 6 s linger can expire during a cold
preflight, in which case its "Starting…" row moves to the bottom where
the job row lands anyway; the background side of the window keeps its
unbounded wait, so a wedged zoo import would delay the post-warm tail
rather than deadlock it.
- Follow-up: the companion unsloth-zoo PR "Import the Hub download
helpers without unsloth_zoo's package init" moves these helpers to an
init-free `unsloth_zoo_downloads` package (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.


<!-- studio-ui-evidence:start -->
### 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 on
`unsloth/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.

![Downloads panel 1.5 s after the click, before vs
after](https://raw.githubusercontent.com/danielhanchen/unsloth-staging-2/pr-media/pr/13738/pr13738_pair_01-8c7068373089.png)

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):

![Model hub page 1.5 s after the click, before vs
after](https://raw.githubusercontent.com/danielhanchen/unsloth-staging-2/pr-media/pr/13738/pr13738_pair_00-89a9cb9249a0.png)
<!-- studio-ui-evidence:end -->

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Daniel Han <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants