Repository navigation
Fix model picker stuck on "Loading variants" - #7767
Conversation
The chat picker's GGUF variant listing was issued with no abort signal, no timeout and no offline handling, so a request that never came back left the expander spinning forever with no quant to click. Chat auto-load awaits the same call per repo, so a stall there blocks loading too. The Model hub was unaffected because its own client bounds the identical listing. - bound the chat-side listing to 30s and give it an abort signal, matching the Hub client - forward offline/prefer_local_cache so an unreachable Hub answers from cache - abort the request when the expander's row collapses - surface a timeout with a Retry button instead of a permanent spinner - accept offline on /api/models/gguf-variants, for parity with the Hub route - bound the native context cache walk so slow disk work cannot hold the quant rows back
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 568eb629a8
ℹ️ 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".
| if time.monotonic() >= deadline: | ||
| logger.debug("native context read for '%s' out of budget", repo_id) | ||
| return None |
There was a problem hiding this comment.
Enforce the deadline around blocking filesystem operations
On a slow or hung cache volume, this check does not enforce the advertised five-second budget: _iter_gguf_paths() advances Path.rglob() before control reaches this line, and read_gguf_context_length() performs blocking stat/open/read work after it. Cache-root discovery also completes before the deadline is initialized. If any of those operations blocks, the already-computed variant listing remains unavailable until the frontend's 30-second timeout, and retrying can start another blocked scan; the filesystem/header operations need a genuinely bounded execution path rather than a check only between yielded files.
Useful? React with 👍 / 👎.
| ..., description = "HuggingFace repo ID (e.g. 'unsloth/gemma-3-4b-it-GGUF')" | ||
| ), | ||
| prefer_local_cache: bool = False, | ||
| offline: bool = False, |
There was a problem hiding this comment.
Treat offline requests as local when selecting context metadata
When an API caller sends offline=true with an ordinary local directory in local_path but leaves prefer_local_cache at its default, the shared service treats the request as local-only and can return variants from that directory, while the route's later context_model selection only considers prefer_local_cache and therefore scans repo_id instead. For an offline model available only at that path, the response loses its native context_length despite the selected GGUF being readable; include offline in the local metadata-source condition (the frontend currently sends both flags, but the newly exposed backend flag independently permits this combination).
Useful? React with 👍 / 👎.
…ions Two real gaps found by simulating the change rather than only unit testing it. WebKit rejects a timed-out fetch with AbortError, not TimeoutError. Measured in Playwright across chromium, firefox and webkit, current and with AbortSignal.timeout/any removed. WebKit is what the desktop app embeds on macOS and Linux, so matching only TimeoutError left exactly the reporting platform on the generic message. Classification now covers both names, reads them by property since DOMException does not inherit from Error in older WebKit, and moves to its own module so it is testable outside JSX. The context-read budget did not bind on tree size. _iter_gguf_paths yields only .gguf files, so a large cache walks a long time yielding nothing and a budget checked per yield never ran. The walk now takes the deadline itself, and the budget is checked between caches so a repo in several caches cannot restart it.
|
Pushed a hardening commit. Rather than only unit testing this, I simulated it, and the simulations turned up two real gaps in the original patch. Both are fixed here. What was simulatedThree isolated sandboxes, none of them touching the repo:
Finding 1: WebKit does not report TimeoutErrorMeasured, not assumed:
The first patch classified only Classification now covers both names and reads them by property rather than Finding 2: the context-read budget did not bind on tree size
The walk now takes the deadline itself and gives up mid-walk, and the budget is checked between caches. Two committed regression tests, both verified to fail against the previous code. Also confirmed by simulation
Test counts312 backend and 309 frontend tests pass, typecheck and build clean. The two failures in the wider backend sweep ( Still openSimulations were run on macOS arm64. Linux and Windows are covered at the engine and logic level, not natively, so CI on those runners is still worth watching. Nobody has clicked through the picker in the real UI yet either. |
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 78d8eda99e
ℹ️ 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".
| visited.append(index) | ||
| yield Path(root) / f"model-{index}.gguf" | ||
|
|
||
| monkeypatch.setattr(models_route, "_iter_gguf_paths", dragging_walk) |
There was a problem hiding this comment.
Accept the deadline in the dragging walker
This test never exercises the intended timeout behavior because production now calls _iter_gguf_paths(root, deadline), while dragging_walk accepts only root. The resulting TypeError is swallowed by _read_native_context_length's broad exception handler, so the test returns immediately with visited empty and passes even if the between-file deadline check is broken; make the fake accept the deadline argument so it actually performs the slow walk.
Useful? React with 👍 / 👎.
| const response = await authFetch(`/api/models/gguf-variants?${params}`, { | ||
| headers: hubTokenHeader(hfToken), | ||
| signal: abort.signal, |
There was a problem hiding this comment.
Bound the session-refresh wait with the request signal
When this request receives a 401 while refreshSession() is already stalled (or its signal-free /api/auth/refresh fetch stalls), the 30-second signal only aborts the original fetch: authFetch awaits the shared refresh promise without observing this signal, so listGgufVariants can still remain pending indefinitely and leave the picker on “Loading variants…”. Apply the abort bound to the entire authFetch operation, including its authentication refresh path, rather than only passing it to the endpoint fetch.
Useful? React with 👍 / 👎.
…line when picking the copy to read Both P2 comments reproduce. Each fix has a regression test verified to fail without it. Cache discovery ran before the deadline existed, so a slow enumeration handed the walk a full fresh budget on top of its own cost. The deadline is now taken first. A single syscall that never returns cannot be interrupted from inside the walk, so the route now bounds the read and reports no context length rather than holding the variant listing. The read moves to its own small pool, so a stranded read cannot starve the shared executor the rest of the app uses. offline alone makes the shared service local-only, but the route still picked the context source on prefer_local_cache, so variants came from local_path while the length was read from repo_id, reporting another copy's context or none. Both flags now count.
… walk test Both comments reproduce. The dragging-walk test stopped exercising anything once production started calling _iter_gguf_paths(root, deadline): the stub took only root, the TypeError was swallowed by the broad handler, and the test passed in 0.000s having walked nothing. Measured, then fixed, with an assertion that the walk ran so signature drift cannot make it vacuous again. Handing the signal to fetch left a hole: on a 401 authFetch awaits a shared session refresh whose own fetch carries no signal, so the listing could still hang there. The listing now settles on the bound whatever the request is doing. Verified against the previous shape, which stays pending forever where this rejects.
…er load Self-review of the previous commit, which nobody had reviewed yet. Two problems with the dedicated thread pool it introduced, both measured. A pool's workers are non-daemon and are joined at interpreter exit, so a read abandoned on a hung mount held up process exit for the full length of the read: measured 20s for a 20s read. The read now runs on a daemon thread, and exit takes 1s with four reads still stranded. Capping concurrency with a non-blocking acquire dropped most context lengths whenever reads overlapped at all: on a healthy cache, 4 of 64 concurrent reads kept theirs. The wait for a slot is now awaited rather than skipped, sharing one budget with the read, so 200 concurrent reads all keep their length in 0.2s while a hung mount still gives up inside the bound and starts no extra threads.
|
No new review comments since the last round, so I audited the two unreviewed commits myself. That turned up two problems with the dedicated thread pool I had introduced in response to comment 1. Both are measured, both are fixed in the latest commit. A stranded read blocked process exitA On a genuinely hung mount that is an indefinite hang on quit, which for the desktop app is worse than the symptom this PR set out to fix. The read now runs on a daemon thread instead: Capping concurrency threw away context lengthsThe cap used a non-blocking acquire, so anything beyond four overlapping reads gave up instead of waiting. On a healthy cache with fast reads: That would have silently dropped the native context on most rows whenever requests overlapped, to defend against a case that is rare. The wait for a slot is now awaited rather than skipped, and shares one budget with the read so the hard bound still holds end to end: Against a hung mount the behaviour is unchanged: gives up inside the bound, and the thread count stays at the cap. TestsThree new ones: the read runs on a daemon thread, retries against a stranded mount start nothing new and give up inside the bound, and 64 concurrent healthy reads all keep their length. The daemon and cap tests were verified to fail against the pool version. One needed a drain step first, because reads abandoned by an earlier test outlive it and were being counted; the suite is stable over repeated runs now. 318 backend and 312 frontend tests pass, typecheck and build clean, and the three simulation suites still pass unchanged (43 backend, 41 client across four engine tiers, 121 browser assertions across chromium, firefox and webkit). |
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: b57c18ec3c
ℹ️ 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".
| <span>{error}</span> | ||
| <button | ||
| type="button" | ||
| onClick={() => setRefreshKey((key) => key + 1)} |
There was a problem hiding this comment.
Avoid retrying while the server scan is still running
When the timeout is caused by a hung local/cache filesystem scan, this button immediately starts another scan even though aborting the HTTP request cannot stop the original asyncio.to_thread(_compute_with_cleanables) in hub/services/models/gguf_variants.py:1020. The remaining production scanner calls list_local_gguf_variants and list_gguf_variants_from_hf_cache without a deadline (lines 665–700), which is fresh evidence beyond the now-bounded native-context reader; repeated retries or reopening rows can therefore strand the default executor's workers and eventually block unrelated offloaded work or shutdown. Deduplicate/bound that server-side scan, or prevent retry until it has actually settled.
Useful? React with 👍 / 👎.
…cutor Aborting the HTTP request cannot stop the scan already running in its thread, so the Retry button this PR adds, and reopening a row, each started another against a filesystem that was not answering. Measured against a wedged scan: 23 retries created 20 threads, filling the whole default executor, after which unrelated offloaded work no longer ran at all. An identical request now joins the scan already in flight instead of starting another. Same measurement afterwards: 1 thread, and unrelated offloaded work runs immediately. Joining costs at most the running scan's own duration in staleness, well inside the client's existing cache window. The waiter is shielded, so one caller giving up leaves the scan for the others, and a failed scan is not retained, so the next request tries again. Note the scan itself is still unbounded, so one wedged scan still holds one worker and delays exit. That is unchanged by this PR and wants its own fix.
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: ffd3362dbe
ℹ️ 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".
| local_only = prefer_local_cache or offline | ||
| context_model = hub_gguf_variants.pinned_snapshot_for_request(repo_id, local_path) or ( | ||
| local_path | ||
| if prefer_local_cache and local_path and is_local_path(local_path) | ||
| else repo_id | ||
| local_path if local_only and local_path and is_local_path(local_path) else repo_id |
There was a problem hiding this comment.
Match the context source to the returned cache
When offline=true is combined with a normal local_path and the repo also exists in the HF cache, this always reads context metadata from local_path, although the service returns the HF-cache result first. Fresh evidence beyond the earlier offline finding is the actual fallback order in hub/services/models/gguf_variants.py:719-737: list_gguf_variants_from_hf_cache wins before list_local_gguf_variants(local_path). The response can therefore attach a missing or unrelated context_length to variants from another copy; select the metadata source based on which local branch produced the response rather than merely on offline.
Useful? React with 👍 / 👎.
The local-only path tries the HF cache before local_path, so picking the context source from the request flags alone attached a length from one copy to variants from another, or none at all. Selecting on offline made that reachable in a second combination. The service now reports the directory it answered from and the route follows it, falling back to the pin and then the repo. Reported with the answer rather than read afterwards, so coalesced callers all see the copy their listing came from. get_gguf_variants_response keeps its shape for callers that only want the listing. The route takes the new answer form, so a stub left on the old name fails loudly instead of quietly not intercepting.
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: e4af52973e
ℹ️ 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".
| context_model = ( | ||
| answer.context_source | ||
| or hub_gguf_variants.pinned_snapshot_for_request(repo_id, local_path) | ||
| or repo_id |
There was a problem hiding this comment.
Return the exact cached snapshot as context source
When prefer_local_cache or offline uses a local_path under a non-active Hugging Face cache and the repository also exists in another cache root, the cached branch in hub/services/models/gguf_variants.py:737-743 leaves answered_from unset even though its listing is scoped to the root derived from local_path. This fallback consequently performs a repo-wide, active-root-first metadata walk and can attach the context_length from a different cached copy than the returned variants. Fresh evidence beyond the earlier comment is that the current cached branch still returns context_source=None; return the selected snapshot or cache location from that branch.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Confirmed, and fixed in 88304be.
Reproduced it first. With offline=true and local_path pointing at <legacy>/hub/models--org--repo, the cached branch answers from that root but leaves the source unset, so the route falls back to repo_id and walks every cache root, active one first:
assert context_calls == [(str(legacy_repo), True)]
E AssertionError: assert [('org/repo', False)] == [('/.../legacy/hub/models--org--repo', True)]
The branch now reports the cache it read, guarded on the directory actually being there so a mismatch falls back to the old behaviour rather than handing the route a path that does not exist:
if repo_cache_dir is not None and repo_cache_dir.is_dir():
answered_from[0] = str(repo_cache_dir)Regression test: test_offline_context_follows_the_cache_the_variants_were_read_from. It fails on the parent commit and passes on this one.
test_offline_context_follows_the_hf_cache_when_it_answers still passes unchanged: there local_path is an ordinary directory rather than a repo cache, the fallback repo cache dir does not exist, and the route keeps reading against repo_id.
| inflight_key = ( | ||
| repo_id, | ||
| bool(prefer_local_cache), | ||
| bool(offline), | ||
| local_path or "", | ||
| hf_cache_scan.token_fingerprint(hf_token), | ||
| ) |
There was a problem hiding this comment.
Include the active cache root in the scan key
When a local-only scan is stuck on the current cache volume and the user switches the configured Hugging Face cache to a healthy location, a new request with the same arguments still matches this key and joins the old scan indefinitely. The actual cache root is resolved later by _repo_cache_dir_for_request, so it is answer-affecting state missing from the coalescing key; include a snapshot of the selected cache root so switching storage can recover without waiting for the hung filesystem operation.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Confirmed, and fixed in 88304be.
Reproduced with a scan wedged on one cache volume, then switching the configured cache home mid-flight. Before the fix the second request never got its own scan:
scanned = ['/.../wedgedvol/hub']
E AssertionError: the new request waited on the scan stuck against the old cache
After, both scans run and the second answers immediately:
scanned = ['/.../wedgedvol/hub', '/.../healthyvol/hub']
I deliberately did not put _repo_cache_dir_for_request(...) in the key. It calls Path(local_path).expanduser().resolve(strict=False), which is exactly the kind of call that blocks on the volume the user is trying to move off, and doing that on the event loop would make the recovery path worse than the bug. The key uses a new configured_cache_key() in utils/hf_cache_settings.py that reads the explicit env override or the stored setting and returns it unresolved:
def configured_cache_key() -> str:
"""The configured cache location, for keying caches and in-flight work.
Deliberately unresolved: resolve() can block on the very volume a caller is
trying to move off. Only equality matters here, not the real path.
"""Only equality matters for coalescing, so skipping resolution costs nothing. Two different configured locations give different keys, which is the property needed.
Regression test: test_switching_cache_storage_does_not_join_a_stuck_scan. It fails on the parent commit and passes on this one. test_variant_scans_for_different_requests_do_not_share and test_identical_variant_scans_in_flight_run_once both still pass, so the key did not become too coarse or too fine.
…t scans on cache storage The cached-variants branch scopes its listing to the cache the request names, but did not report which one, so the route fell back to a repo-wide walk that starts at the active cache and could attach another copy's context length. In-flight scan coalescing also keyed only on the request, so switching cache storage joined a scan already stuck on the old volume instead of starting a fresh one. The new key reads the configured location without resolving it, since resolve() can block on that same volume.
|
@codex review |
|
Codex Review: Didn't find any major issues. 🎉 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". |
|
I was able to repro the original loading hang on main, and confirmed this PR fixes it. One small thing: should we set |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 3872b937a7
ℹ️ 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".
| # This listing is scoped to one cache, so name it: a repo-wide walk starts at | ||
| # the active cache and could read a different copy's context length. | ||
| if repo_cache_dir is not None and repo_cache_dir.is_dir(): | ||
| answered_from[0] = str(repo_cache_dir) |
There was a problem hiding this comment.
Return the selected snapshot instead of its parent
When this cache contains multiple snapshots, list_gguf_variants_from_hf_cache returns variants from one specifically selected snapshot (hub/utils/gguf.py:332-340), but this records only the repository directory. _read_native_context_length subsequently searches that parent with rglob and uses the first GGUF encountered, whose traversal order need not match the snapshot-selection order, so revisions with different context metadata can produce an incorrect context_length. Fresh evidence beyond the earlier cross-cache-root issue is this mismatch between snapshots within the same cache root; propagate the snapshot actually selected by the lister.
Useful? React with 👍 / 👎.
The bug
Some users on the macOS and Windows desktop app cannot open the model picker's quantization dropdown. It sits on "Loading variants..." indefinitely, so no model can be downloaded or loaded. The Model hub works fine for the same users, which is the clue: the picker and the hub call different endpoints through different clients, and only the hub's client is bounded.
/api/hub/gguf-variants/api/models/gguf-variantslistGgufVariantsinfeatures/chat/api/chat-api.tsissued the request with no signal at all, so if the backend did not answer,loadingnever flipped and the row stayed on the spinner. Confirmed against a server that accepts the connection and then goes quiet: the unsignalled fetch was still pending at 35s, where the bounded one ends at 30.0s with aTimeoutError.That also covers the rest of the report. Chat auto-load awaits the same untimed call per repo (
chat-adapter.ts:1903and:1976), which is why loading stalls as well, and with no abort on collapse the stalled requests keep occupying the browser's per-host connections and starve everything else the picker needs.It reproduces on a slow or blocked Hub link and on a large or slow model cache, which is why it does not show up on a machine with a warm cache and a fast connection.
Changes
Frontend
features/chat/api/gguf-variants-request.ts(new): request shaping split out so it is testable without the auth barrel behind it. 30s bound matching the hub client, plusofflineandprefer_local_cacheforwarding.chat-api.ts:listGgufVariantsnow carries a signal, the caller's abort folded together with the timeout, and asks for the cached listing when the Hub is known to be unreachable.pickers.tsx: the expander aborts its request when the row collapses, and a failed listing renders a readable message with a Retry button instead of a dead end.Backend
routes/models.py: the route acceptsofflinefor parity with/api/hub/gguf-variants. Verified live, both routes now answer identically instead of the picker going remote anyway.Testing
tests/gguf-variants-request-bounds.test.ts, 2 new backend cases intests/test_cached_gguf_routes.py. The walk bound test is non-vacuous: unbounded it visits all 200 paths in 2.4s.npm run typecheckandnpm run buildare clean.test_resolve_cached_repo_id_case_variant_hitandtest_xet_only_override_keeps_model_cache_editable, fail identically on a clean checkout. Pre-existing and unrelated.Note
This makes the failure end rather than hang. If the Hub link is genuinely stalling, the row now shows a timeout and a Retry. Falling back to cached quants on timeout, the way the hub page does, would be a follow up if we want it.