Skip to content

Fix Hub On Device Selection Across Refresh and Download Changes - #9922

Merged
danielhanchen merged 23 commits into
unslothai:mainfrom
Sneakr:split/pr9599-02-hub-on-device-selection
Aug 31, 2026
Merged

danielhanchen merged 23 commits into
unslothai:mainfrom
Sneakr:split/pr9599-02-hub-on-device-selection

Conversation

@Sneakr

@Sneakr Sneakr commented Aug 28, 2026

Copy link
Copy Markdown
Collaborator

Fixed

  • The selected model no longer disappears when a download changes between a local Hugging Face cache row and a cached Hub row.
  • Selection remains attached during download resume, cancellation, completion, inventory refresh, and deduplication.
  • Models first reported with an unknown format remain selected after being classified as GGUF or safetensors.
  • On Device details update immediately with the resolved selection instead of temporarily showing a removed row.
  • Cached model IDs now use consistent URL encoding.
  • Existing raw legacy IDs remain supported.
  • Model formats and cache source types remain isolated when a transition is ambiguous.
  • Dataset-like unknown cache entries cannot be selected as model replacements.
  • Filtered selections retain their correct hidden state.
  • Malformed selection IDs fail safely.

The implementation uses local inventory data only. It adds no network dependency, filesystem behavior, or platform-specific logic.

Sneakr added 4 commits August 28, 2026 12:15
Keep cached and local HF-cache identities resolvable while resume and cancellation swap the inventory row source. Canonicalize optimistic IDs, preserve legacy raw-ID links, and keep On Device details attached to the current row.
@danielhanchen

Copy link
Copy Markdown
Member

Confirmed this hits selection-resolution.ts where the downloaded selection is matched by exact row id, so the On Device selection is dropped when a download transitions between the local cache row and the hub cache row. Will get this reviewed.

@mahiatlinux
mahiatlinux self-requested a review August 29, 2026 04:54
@mahiatlinux

Copy link
Copy Markdown
Contributor

The reported problem is real and in scope. On merge base 5be8f37d, selecting an hf_cache:unknown: On Device row and starting or resuming a GGUF download replaces that row with a download:gguf: row. The detail pane then loses the selection because the old ID no longer exists. The base Playwright job reproduced that exact transition.

I found and fixed these concrete gaps in the original implementation:

  1. Legacy HF cache responses may omit inventory_id and expose a raw Org/Repo ID. Exact lookup could not attach that selection after deduplication or a live-row transition. The resolver now accepts only well-formed two-segment raw repo IDs and moves them to the unique current inventory row. See selection-resolution.ts and the regression at hub-selection-resolution.test.ts.
  2. Unknown HF cache partials were suppressed only when the classified sibling was GGUF. An unknown local partial plus a live safetensors, adapter, or checkpoint row produced duplicate rows and left selection on stale inventory. Deduplication now treats every known format consistently. See inventory-dedupe.ts.
  3. Optimistic live rows reused final cache IDs. A model download that later classified as adapter or checkpoint could not move from its provisional safetensors identity because that looked like a known-to-known format change. Live jobs now use a distinct download:<format>: identity, and the resolver moves it to the single final format. See view-models.ts and selection-resolution.ts.
  4. Every scoped @scope model download was inferred as GGUF. That mislabeled diffusion and other safetensors scopes in live rows and completion hints, and the bad hint could remain visible until expiry. Download requests now carry an explicit inventory class; unclassified scoped variants default to model, while real GGUF scopes stay GGUF. See download-manager-types.ts, use-staged-download.ts, and download-manager-state.ts.
  5. Backend-adopted scoped downloads dropped their file list, so hydration could not recover whether the scope contained GGUF or model files. Adoption and persisted hydration now retain the scoped files and inferred inventory class. See hydration.ts and download-inventory-kind.test.ts.
  6. A resolved unknown-to-known identity was not committed to the URL. If another format appeared on a later inventory refresh, the stale unknown ID became ambiguous and the detail pane disappeared. URL sync now replaces the stale ID with the resolved canonical ID. See hub-page.tsx and selection-resolution.ts.
  7. Row selection updated local selection state before router navigation landed. The URL synchronization effect could restore the previous URL model during that intermediate render. Row and split-view selections now route first, and the selection hook adopts the landed URL. See hub-page.tsx.

Focused validation:

  • A/B focused CI passed. The merge-base negative control reproduced the disappearing selection. The repaired head passed the lifecycle, resolver, deduplication, format, raw-ID, malformed-ID, and inventory-kind tests.
  • Merge-base Playwright job reproduced the empty detail pane after the download row replaced the selected HF cache row.
  • Repaired-head Playwright job passed against an exact Studio install. It verified selection through download start, pause/cancel, resume, completion, 40 inventory requests, deduplication, cache-row transitions, unknown-to-GGUF, unknown-to-safetensors, legacy raw IDs, malformed IDs, filtered selections, and ambiguous identities. It also exercised the visible Resume and Pause controls and confirmed one start request and two cancel requests.
  • No full local suite was run. All PR code execution stayed in focused fork CI.

On Device selection before and after

@mahiatlinux

Copy link
Copy Markdown
Contributor

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Aug 29, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-08-31T13:24:46.141390Z 65c12a7 Manual request
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@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: 9cb3efd1b5

ℹ️ 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 +36 to +41
if (
!isDiscoverTab &&
resolvedSelectedId &&
resolvedSelectedId !== urlModel
) {
return { action: "replace", selectedId: resolvedSelectedId };

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Preserve a cleared URL on the downloaded tab

When the downloaded tab has inventory rows but no model query parameter, resolveDownloadedSelection still resolves the first row while selectionInputId and urlModel are both null. This branch then returns replace, repopulating the URL and opening the detail overlay; after “Back to Hub” clears the URL, the same sequence immediately reopens a model. Only rewrite the URL when resolving an existing non-null selection identity, leaving the explicit null state intact.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The premise does not hold: resolveDownloadedSelection returns null when selectedId is null because all three transition resolvers reject a null id. The only first-row fallback is the split-view preview effect, and Back to Hub exits split view before clearing the URL.

@mahiatlinux

Copy link
Copy Markdown
Contributor

Post-push review and CI update

Fixed in 71e474b6b:

  • documents-rag-section.tsx now marks scoped embedding transfers as GGUF, so their live row and completion hint use the format returned by the embedding resolver.
  • use-hub-inventory.ts now protects observed keys with downloadInventoryHintKind(..., job.inventoryKind), matching the classification used when a job starts and completes.
  • Focused assertions cover both call sites.
  • The URL-clear review comment was rejected after tracing resolveDownloadedSelection: a null selection returns null through every resolver. The only first-row selection is the split-view preview effect, which is disabled after Back to Hub exits split view.

Verification:

chatgpt-codex-connector[bot]

This comment was marked as resolved.

@mahiatlinux

Copy link
Copy Markdown
Contributor

Pass 2 found and fixed two additional selection bugs in 7e487aa:

  • GGUF identity canonicalization cleared the file query parameter, so completion could discard the requested quantization. URL synchronization now preserves the file for GGUF and unclassified GGUF cancel transitions, while stale files are still cleared for non-GGUF results.
  • Provisional download IDs could cross from GGUF to safetensors, or the reverse, when another installation of the same hybrid repository remained. Resolution now stays within the encoded format family, retains the unclassified partial fallback used by cancel and resume, and keeps the intended safetensors to adapter or checkpoint reclassification.

Exact-head verification passed:

Both review threads were answered and resolved. The single full fork suite was already completed before this focused pass; its ten failures were proven unchanged or outside the PR diff.

chatgpt-codex-connector[bot]

This comment was marked as resolved.

@mahiatlinux

Copy link
Copy Markdown
Contributor

Pass 3 found and fixed the remaining scoped adoption gap in cab2a4f. Persisted pre-change scoped jobs and probeAndAdopt now infer inventory kind from their backend file list through the same startJob path. Explicit caller classification still wins.

Exact-head verification passed:

The review thread was answered and resolved.

danielhanchen added a commit to Datta0/unsloth-staging-3 that referenced this pull request Aug 31, 2026
danielhanchen added a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Aug 31, 2026
@danielhanchen

Copy link
Copy Markdown
Member

Before/after evidence for the On Device selection fix, from two isolated Studio installs: the merge base b1cc76d1e and the current head 071e703bd. Separate UNSLOTH_STUDIO_HOMEs, separate ports, and an isolated HF cache on both sides (HF_HOME, HF_HUB_CACHE, HF_XET_CACHE and XDG_CACHE_HOME all redirected, since this box scans a shared cache alongside HF_HOME).

On Device selection before and after

The scenario is the one this PR is about. On Device holds a single unclassified partial of unsloth/Qwen3-0.6B-GGUF (hf_cache:unknown:unsloth%2FQwen3-0.6B-GGUF, model_format: unknown, partial_transport: null). It is selected, a BF16 GGUF download of the same repo starts, and the page reloads. That kills the selected ID: the unclassified local row is deduplicated behind a partial GGUF row.

Fact Merge base Head
selected_id_before_transition hf_cache:unknown:unsloth%2FQwen3-0.6B-GGUF same
selected_id_after_transition null download:gguf:unsloth%2FQwen3-0.6B-GGUF
selection_survived false true
selected_rows_after 0 1
row_count_after 1 1
list_row_text Qwen3-0.6B-GGUF unsloth GGUF 0.6B 1.2 GB identical

The last two rows are the control. The row list and the running BF16 job are identical on both halves, and so is inventory_after, so the only thing that differs is whether the selection survived. An empty pane beside an empty list would prove nothing, so the scene refuses to shoot that case.

One detail worth recording for anyone reproducing this. Cancelling a download through the Hub API does not leave an unclassified row: the cancel writes a variant-keyed state file that local_inventory reads as has_gguf_variant_state and stamps model_format: "gguf" on. The row's ID then does not change at the merge base, so the two sides come out identical and the run reads as "this PR changed nothing". The partial here is seeded by interrupting a plain hf_hub_download, which is the state another tool leaves behind and which Studio holds no variant state for, and the scene raises rather than shooting if the row comes back classified.

Cross-platform and cross-engine runs on the current head, all green:

  • Full frontend suite (6127 tests) on ubuntu-latest, macos-15 and windows-latest.
  • The selection resolver executed inside Chromium, Firefox and WebKit against a real Vite server. That covers Edge and Safari by engine. It is worth running in a browser rather than only in Node because this code percent-decodes an ID that comes straight from the URL bar, and decodeURIComponent raises URIError on malformed input.

@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Aug 31, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Aug 31, 2026
@unslothai unslothai deleted a comment from mahiatlinux Aug 31, 2026
@unslothai unslothai deleted a comment from mahiatlinux Aug 31, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Aug 31, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Aug 31, 2026
@unslothai unslothai deleted a comment from mahiatlinux Aug 31, 2026
@unslothai unslothai deleted a comment from mahiatlinux Aug 31, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Aug 31, 2026
@unslothai unslothai deleted a comment from mahiatlinux Aug 31, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Aug 31, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Aug 31, 2026
@unslothai unslothai deleted a comment from mahiatlinux Aug 31, 2026
@unslothai unslothai deleted a comment from mahiatlinux Aug 31, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Aug 31, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Aug 31, 2026
@unslothai unslothai deleted a comment from mahiatlinux Aug 31, 2026
@unslothai unslothai deleted a comment from mahiatlinux Aug 31, 2026
@unslothai unslothai deleted a comment from mahiatlinux Aug 31, 2026
@unslothai unslothai deleted a comment from mahiatlinux Aug 31, 2026
@unslothai unslothai deleted a comment from mahiatlinux Aug 31, 2026
@unslothai unslothai deleted a comment from mahiatlinux Aug 31, 2026
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. More of your lovely PRs please.

Reviewed commit: 071e703bdc

ℹ️ 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 and others added 2 commits August 31, 2026 10:49
The comment pass removed 100 lines from hub-page.tsx, which overlaps the
hunks fe76559 changed on main, so the branch stopped merging cleanly.
The other fifteen files keep their reduction.
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Can't wait for the next one!

Reviewed commit: 65c12a766a

ℹ️ 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
danielhanchen merged commit 3574e20 into unslothai:main Aug 31, 2026
34 of 73 checks passed
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.

3 participants