Skip to content

Fix model picker stuck on "Loading variants" - #7767

Merged
Imagineer99 merged 17 commits into
mainfrom
fix/model-picker-variant-listing-hang
Aug 3, 2026
Merged

Imagineer99 merged 17 commits into
mainfrom
fix/model-picker-variant-listing-hang

Conversation

@shimmyshimmer

Copy link
Copy Markdown
Member

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.

Model hub Chat model picker
endpoint /api/hub/gguf-variants /api/models/gguf-variants
timeout 30s abort none
abort on unmount yes no
offline handling asks for the cached listing always goes remote

listGgufVariants in features/chat/api/chat-api.ts issued the request with no signal at all, so if the backend did not answer, loading never 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 a TimeoutError.

That also covers the rest of the report. Chat auto-load awaits the same untimed call per repo (chat-adapter.ts:1903 and :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, plus offline and prefer_local_cache forwarding.
  • chat-api.ts: listGgufVariants now 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 accepts offline for parity with /api/hub/gguf-variants. Verified live, both routes now answer identically instead of the picker going remote anyway.
  • The native context cache walk is bounded at 5s. It only pre-fills a context field on a row that is already selectable, so it should never hold the quant rows back.

Testing

  • 6 new frontend cases in tests/gguf-variants-request-bounds.test.ts, 2 new backend cases in tests/test_cached_gguf_routes.py. The walk bound test is non-vacuous: unbounded it visits all 200 paths in 2.4s.
  • 306 frontend tests and 310 backend tests in the touched suites pass. npm run typecheck and npm run build are clean.
  • Two failures in the wider backend sweep, test_resolve_cached_repo_id_case_variant_hit and test_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.

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
@shimmyshimmer

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment on lines +2751 to +2753
if time.monotonic() >= deadline:
logger.debug("native context read for '%s' out of budget", repo_id)
return None

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@/tmp/r1

..., description = "HuggingFace repo ID (e.g. 'unsloth/gemma-3-4b-it-GGUF')"
),
prefer_local_cache: bool = False,
offline: bool = False,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@/tmp/r2

…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.
@shimmyshimmer

Copy link
Copy Markdown
Member Author

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 simulated

Three isolated sandboxes, none of them touching the repo:

  • Backend, in a dedicated uv venv importing the real routes.models: 37 checks over the context-read budget, the offline parameter and concurrency, plus HTTP-level checks that mount the real router so FastAPI itself does the parameter coercion.
  • Client, in Node against real HTTP servers that stall in different ways: silence after accept, slow headers, a body that trickles forever, connection reset, 500, 404, malformed JSON, empty body. 41 checks, each run on four engine capability tiers.
  • Browsers, via Playwright: chromium (Chrome and Edge), firefox (Gecko) and webkit (what Safari ships and what Tauri embeds as WKWebView on macOS and WebKitGTK on Linux). Each engine run twice, once as-is and once with AbortSignal.timeout and AbortSignal.any deleted before any app code loads, which is how older builds of those same engines behave. 121 assertions, all passing.

Finding 1: WebKit does not report TimeoutError

Measured, not assumed:

engine timed-out fetch rejects with
chromium TimeoutError
firefox TimeoutError
webkit AbortError

The first patch classified only TimeoutError, so on Safari and inside the desktop app's own webview the row would have fallen through to the generic "Failed to load variants" instead of the timeout message with the Hub hint. That is exactly the platform this bug was reported on, so it would have shipped half-working for the people who reported it.

Classification now covers both names and reads them by property rather than instanceof, since DOMException does not inherit from Error in older WebKit. It moved into its own module so it can be tested outside JSX, with a committed test.

Finding 2: the context-read budget did not bind on tree size

_iter_gguf_paths yields only .gguf files. A cache full of blobs walks for a long time yielding nothing, so a budget checked once per yield never got checked at all. A slow yield-less walk ran to completion regardless of the budget, and a repo present in several caches restarted the budget per cache.

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

  • Ponyfill paths work: with both natives removed, timeouts still fire, caller aborts still propagate, and 100 create/dispose cycles leak zero listeners in every engine.
  • Windows paths (C:\models\qwen, UNC \\server\share), and paths containing &, ?, #, +, %, spaces, CJK and emoji all survive URLSearchParams and arrive byte-identical at the route. A repo_id carrying &offline=true cannot inject a parameter.
  • FastAPI bool coercion accepts true/false/1/0/yes/no/on/off, rejects garbage with 422, defaults to False, and unknown parameters return 200, so a newer frontend against an older backend degrades rather than errors.
  • A React StrictMode style remount does not let the discarded mount paint an error over the live one.
  • 64 concurrent listings all answer, and bounded context reads overlap rather than serialising.
  • Success, 500, reset, malformed JSON and empty body all settle promptly instead of waiting out the bound.

Test counts

312 backend and 309 frontend tests pass, typecheck and build clean. The two failures in the wider backend sweep (test_resolve_cached_repo_id_case_variant_hit, test_xet_only_override_keeps_model_cache_editable) fail identically on a clean checkout and are unrelated.

Still open

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

@shimmyshimmer

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@/tmp/r3

Comment on lines +1058 to +1060
const response = await authFetch(`/api/models/gguf-variants?${params}`, {
headers: hubTokenHeader(hfToken),
signal: abort.signal,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@/tmp/r4

Unsloth and others added 4 commits August 3, 2026 00:16
…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.
@shimmyshimmer

Copy link
Copy Markdown
Member Author

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 exit

A ThreadPoolExecutor's workers are non-daemon and get joined by concurrent.futures' atexit handler. Since the point of that commit was to abandon a read that will not return, abandoning one meant the process could not exit until it did:

main done, exiting now
process exit took 20s        # for a 20s stranded read

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:

returned None in 0.20s with the read still running
main done, exiting now
process exit took 1s

Capping concurrency threw away context lengths

The cap used a non-blocking acquire, so anything beyond four overlapping reads gave up instead of waiting. On a healthy cache with fast reads:

  4 concurrent healthy reads -> 4/4 kept a context length
  8 concurrent healthy reads -> 4/8
 16 concurrent healthy reads -> 4/16
 64 concurrent healthy reads -> 4/64

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:

   4 concurrent healthy reads -> 4/4 kept a context length in 0.00s
  64 concurrent healthy reads -> 64/64 in 0.06s
 200 concurrent healthy reads -> 200/200 in 0.20s

Against a hung mount the behaviour is unchanged: gives up inside the bound, and the thread count stays at the cap.

hung read -> None in 0.20s
all slots stranded -> None in 0.20s
native-ctx threads alive: 4      # after 7 calls

Tests

Three 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).

@shimmyshimmer

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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)}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@/tmp/r5

Unsloth and others added 2 commits August 3, 2026 01:34
…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.
@shimmyshimmer

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment thread studio/backend/routes/models.py Outdated
Comment on lines +2993 to +2995
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

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@/tmp/r6

Unsloth and others added 2 commits August 3, 2026 02:31
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.
@shimmyshimmer

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment on lines +2993 to +2996
context_model = (
answer.context_source
or hub_gguf_variants.pinned_snapshot_for_request(repo_id, local_path)
or repo_id

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +1070 to +1076
inflight_key = (
repo_id,
bool(prefer_local_cache),
bool(offline),
local_path or "",
hf_cache_scan.token_fingerprint(hf_token),
)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Unsloth and others added 2 commits August 3, 2026 03:23
…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.
@shimmyshimmer

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 🎉

Reviewed commit: f291399ddd

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

@Imagineer99

Copy link
Copy Markdown
Member

I was able to repro the original loading hang on main, and confirmed this PR fixes it.

One small thing: should we set answered_from here before returning the cached result? If the Hub request fails, it stays None, so the context length may be read from a different cache copy

@Imagineer99
Imagineer99 merged commit aa9ca85 into main Aug 3, 2026
46 of 53 checks passed
@Imagineer99
Imagineer99 deleted the fix/model-picker-variant-listing-hang branch August 3, 2026 14:07

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants