Repository navigation
Studio: keep GGUF variant listings off the default thread pool so a stalled Hub cannot block downloaded models - #14134
Conversation
…talled Hub cannot block downloaded models
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: ceb19f0cc0
ℹ️ 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".
| answer = await _shared_variants_scan( | ||
| inflight_key, _compute_with_cleanables, offline = bool(offline) | ||
| ) |
There was a problem hiding this comment.
Keep cache-first hits out of the Hub pool
When a downloaded-model caller sets prefer_local_cache=true without offline=true, this routes the scan to _HUB_LISTING_POOL even though _compute treats prefer_local_cache as local-first and returns immediately from the cached snapshot (local_only = prefer_local_cache or offline). This is the request shape used by the local catalog card (local-on-device-card.tsx lines 317-322), so once stalled remote listings fill the Hub pool, expanding that downloaded model still queues and times out. Split the cache probe from its optional remote fallback, or otherwise run a provably local/cache-hit scan on the disk pool.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Not changing here: a prefer_local_cache scan can still reach the Hub in the same thread (the token probe before the cache read, and the remote fallback on a cache miss), so running it on the disk pool would let Hub stalls into the pool that has to stay Hub-free, and splitting the probe changes that response's readiness fields. That surface behaves exactly as on main; this PR targets the offline listing the chat picker's On Device expander sends.
|
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". |
…disk pool (unslothai#14829) unslothai#14134 gave disk-only GGUF listings their own thread pool so they never queue behind stalled Hub listings. The audio.cpp branch (`_audio_cpp_variants_answer`) still ran the managed-account preflight with `listing_thread(False, require_model_access, ...)`: on the Hub pool and without `offline`, even for an offline request. With the Hub pool held by stalled listings, an offline audio.cpp listing for a managed account waited for them before it reached its disk-only resolver, and the grant check itself could ask the Hub. ## Change - `network` is computed first; the preflight then runs on the disk pool with `offline=True` when the listing is offline (request flag or Hub offline mode), the same way the generic listing path already passes `offline` to `require_model_access`. - Online listings are unchanged. ## Tests - `tests/test_gguf_listing_threads.py::test_an_offline_audio_preflight_does_not_queue_behind_stalled_hub_listings`: holds the only Hub pool worker, then lists an audio.cpp repo offline as a managed account. It fails on main (the preflight waits for the stalled worker) and passes here; it also checks the grant check got `offline=True` and the resolver `network=False`. - The rest of `test_gguf_listing_threads.py` plus the GGUF variant and account access suites: 198 passed. --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Fixes #14038
Problem
When Hugging Face stops responding, the chat model picker can no longer expand a downloaded GGUF on the On Device tab: the row sits on "Loading variants..." and then shows "Timed out listing quantizations. Check your connection to Hugging Face, then retry.", even though the quant is on disk.
The On Device expander already asks for the disk-only listing first (#12460), and that listing alone answers in about 0.1 s. The problem is where it runs. Every GGUF variant listing, disk-only or Hub-bound, ran through
asyncio.to_thread, i.e. the event loop's default executor. A remote listing against a Hub that accepts the connection but keeps the response trickling never hits the per-read timeout, so it holds its worker until the Hub answers. Once enough of those are in flight (one per On Device repo checked for updates, every Recommended row, every retry), the default executor is full and:asyncio.to_threadcaller in Studio (model load, chat routes) queues too.Fix
GGUF variant listings get their own thread pools instead of the default executor:
gguf-hub-listing, so stalled Hub calls can no longer starve the rest of Studio.offline=true) listings run ongguf-disk-listing, so the On Device answer never queues behind Hub-bound work.Both pools use the default executor's sizing, context variables are carried into the worker exactly as
asyncio.to_threaddoes, and the in-flight sharing of identical listings is unchanged. The same routing applies to the audio.cpp and MLX precision listings in the same module, and to the managed-account access preflights the listing runs first (route and service), which can ask the Hub for an ungranted repo. No frontend, API or UI change.Evidence
Backend repro against a Hub endpoint that accepts and trickles one header byte every 2 s (
PYTHON_CPU_COUNT=4, so 8 default workers), 12 concurrent remote listings in flight, then the disk-only listing the On Device expander sends for a downloaded repo:['Q8_0', 'UD-Q4_K_XL']asyncio.to_threadcall (what load / chat use)Same result through both
/api/models/gguf-variantsand/api/hub/gguf-variants.New tests in
studio/backend/tests/test_gguf_listing_threads.py: a disk-only listing answers while the default executor is saturated, a stalled Hub listing leaves the default executor free, and a stalled managed-account preflight leaves it free too. All three fail on main and pass here. They pass on ubuntu-latest, macos-15 and windows-latest (31 passed on each, with the MLX precision listing tests).