Skip to content

Studio: keep the scan-folder copy listed when an incomplete download left a weightless skeleton in the cache - #12803

Open
VTplus wants to merge 35 commits into
unslothai:mainfrom
VTplus:studio-scan-folder-catalog
Open

VTplus wants to merge 35 commits into
unslothai:mainfrom
VTplus:studio-scan-folder-catalog

Conversation

@VTplus

@VTplus VTplus commented Oct 6, 2026

Copy link
Copy Markdown
Contributor

Same use case (custom scan folders) as #12253/#12254/#12258: models neither visible in the picker nor listed via API.

This PR fixes the catalog side — the walk GET /v1/models and GET /models/local share.

What

collect_local_models re-attributes a cache-layout copy found in a registered scan folder outside the configured HF caches as the user's custom row, so the repo-id dedupe no longer collapses it into the same-repo active-cache entry. The servability stage then keeps whichever copy actually has weights.

A folder registered over a configured cache keeps the hf_cache attribution (#9986). A repo cached completely and parked lists both rows locally; /v1/models still dedupes them to one id.

Why

refs/main and the snapshot dir appear before any blob lands, so a download that never completes leaves a ~1 KB skeleton behind — from a repo-id load that resolved remotely (the load side #12254 fixes), a pinned variant the parked copy does not carry, or an abort mid-flight.

The skeleton scans as complete (nothing ever named a quant, the ref resolves), so the dedupe prefers the active-cache row, discards the parked copy, and the servability check then drops the skeleton for holding no servable GGUF.

In these cases, the repo disappears from the catalog although a loadable copy is on disk.

active/models--org--Model-GGUF/
  refs/main            -> "<sha>"
  snapshots/<sha>/      (empty; no blobs)
parked/models--org--Model-GGUF/        <- registered scan folder
  snapshots/<sha>/Model-Q4_K_M.gguf    (complete weights)

GET /v1/models omits org/Model-GGUF until the skeleton is deleted by hand.

Tests

  • test_cached_gguf_routes.py: skeleton + parked copy yields both rows (cache keeps the repo id, parked copy keyed by its path) with only the parked one servable; folders over the active or a known cache keep the hf_cache label and dedupe to one row.
  • test_local_model_format.py: a registered HF home lists as custom (mirroring the Hub inventory promotion in Studio: show HF-cache-layout models from registered scan folders in the chat picker #12258; plain files, no symlink privilege needed).

Known limitations

…as no weights

A download that never completes leaves a weightless refs/snapshot skeleton in the active cache - from a repo-id load that resolved remotely, a pinned variant the parked copy does not carry, or an abort mid-flight.

The skeleton scans as complete, so the catalog dedupe collapsed the parked scan-folder copy into it and the servability stage dropped the row: the model vanished from /v1/models and /models/local although a loadable copy existed. Key the parked copy by its own path so it is listed again whatever left the skeleton behind.
@VTplus
VTplus requested a review from danielhanchen as a code owner October 6, 2026 02:08
@danielhanchen

Copy link
Copy Markdown
Member

Confirmed that collect_local_models in studio/backend/routes/models.py collapses the parked scan-folder copy into an empty skeleton left by an aborted download, so a loadable repo disappears from the list. Will get this reviewed alongside #12254 and #12258.

VTplus added 7 commits October 6, 2026 23:05
…talog

# Conflicts:
#	studio/backend/routes/models.py
…tudio-scan-folder-catalog

# Conflicts:
#	studio/backend/routes/models.py
…s new ComfyUI scan helper

Upstream inserted _with_comfy_compat_rows right where this branch defines _merge_scan_folder_row; the merge keeps both. Resolves the routes/models.py conflict; catalog suites re-run green (231/5/35 passed).
…g - sync branch with upstream before re-cutting the patch

No changes to the three patch files (empty ^1 diff); pure upstream sync ahead of the patch re-cut.
…dress the branch review before re-cutting the patch

Pin omlx_model_dirs like Ollama/Hermes, or a machine with oMLX adds roots and rows the exact-equality assertions fail on. The new test pins the known limit: a parked copy whose newest snapshot holds no quant is listed in the picker but not in /v1/models, until the resolver keys on the layout, not the source.
@Etherll Etherll self-assigned this Oct 11, 2026
A cache-layout copy parked in a scan folder now lists as a custom row. Two
consumers still keyed on the old hf_cache label:

- local_model_resolver skipped the newest-complete-snapshot selection for it,
  so /v1/models advertised a split quant that was missing a shard, or dropped
  a parked copy whose newest snapshot held no quant. Apply that selection to
  custom rows with a cache layout too.
- the relabel cleared model_id on every parked row, so a parked-only image
  model no longer resolved by repo id in the media index. Clear it only when
  another row already answers to that repo id; the first parked copy keeps it.
The previous commit applied the newest-complete-snapshot selection to every
custom row under a models--*/snapshots layout. A scan folder registered at a
models--* repo dir lists each snapshot as its own row, so an older snapshot
then advertised the newer snapshot's quant and a pin on it missed. Redirect a
custom row only when it is the snapshot the cache scan itself names (the
relabeled parked copy); every other snapshot row keeps its exact directory.
@Etherll

Etherll commented Oct 11, 2026

Copy link
Copy Markdown
Collaborator

When an aborted download leaves a weightless skeleton in the active HF cache and a complete copy sits in a registered scan folder, the parked copy now stays servable: /v1/models lists unsloth/Qwen3-0.6B-GGUF again, and the Unsloth Studio API usage example names it. On main the repo drops out of the catalog.

Unsloth Studio Settings, API usage examples: before and after
Settings → API → Usage examples with "Switch model by request" on, same fixture on both sides (weightless skeleton in the active HF cache, complete test GGUF copy in a registered scan folder). BEFORE: main 264eec55 (merge base). AFTER: PR head fbc6c118.

What changed

  • A parked copy relabeled as a custom row skipped the newest-complete-snapshot selection, so /v1/models could advertise a split quant that is missing a shard, or drop a copy whose newest snapshot holds no quant. The resolver now applies that selection to the parked row. Other snapshot rows of a folder registered at a models--* repo directory keep their own directory.
  • Clearing model_id on every parked row meant a parked-only image model no longer resolved by repo id in the media index. The repo id is now cleared only when another row already answers to it, and only the first parked copy keeps it.

Still open

Each of these is a regression compared with main, reproduced on fbc6c118, and they are why this is not ready yet:

  1. A complete copy in the active cache plus a newer complete parked copy: /v1/models advertises the parked copy's quant (for example Q4_K_M) under the repo id, but a load by repo id resolves the active-cache copy (Q8_0), so pinning the advertised quant fails. On main both agree on Q8_0.
  2. A partial or weightless active-cache row still claims the repo id, so the complete parked copy loses it and a media request by repo id finds nothing. Main resolves it.
  3. The Export page's default GGUF output folder for a parked row is now the <snapshot>_gguf sibling inside models--*/snapshots/, which the next scan reads as the repo's newest snapshot. This comes from the code path and a simulated write; the browser flow was not run.

All three come from the catalog relabeling parked rows to custom while the resolver and other consumers still treat them as cache rows. A smaller fix for the original bug would keep parked copies as hf_cache rows and make the collect_local_models dedupe prefer the copy that has weights over a weightless or partial one. That avoids all three, but it drops the separate Custom Folders row for the parked copy that this PR and #12258 aim for, so the choice of direction is the author's.

The two touched backend test files pass at fbc6c118 (330 passed, 1 skipped), and the new regression tests fail on the earlier head. The wider dependent suites show the same 19 pre-existing, environment-related failures on the original head and on fbc6c118. Fork CI is running: Etherll#240.

@VTplus

VTplus commented Oct 11, 2026

Copy link
Copy Markdown
Contributor Author

Thanks @Etherll for the thorough review — and for the two commits you added to the branch; I will build on them. I aim to solve the three highlighted regressions while keeping the separate Custom Folders row for the parked copy, which is what this PR and #12258 aim for. The rework will keep the catalog consistent with the resolver order introduced by #13034 (merged), which this branch already includes. As a first step, I will sync the forked branches to current main before the rework.

…g - sync branch with upstream before re-cutting the patch

190 upstream commit(s) since the branch base; see git log for the range.
VTplus and others added 6 commits October 12, 2026 21:05
…g - sync branch with upstream before re-cutting the patch

125 upstream commit(s) since the branch base; see git log for the range.
…g - sync branch with upstream before re-cutting the patch

100 upstream commit(s) since the branch base; see git log for the range.
… claim

A quant pin resolves to the row holding that quant (alternates beside the cache-first key, per the unslothai#13034 chosen-artifact ordering), /v1/models advertises the row a bare id loads, and only a row with weights claims a repo id.
A save folder inside models--*/snapshots/ would read back as the repo's newest revision; the default now falls back to the exports root.
@VTplus

VTplus commented Oct 13, 2026

Copy link
Copy Markdown
Contributor Author

@Etherll — Thanks again, all three regressions are addressed now (f32bc681c7, 2db0805e3f, plus review hardening in f4708d65fd), built on your two commits and keeping the separate parked row.

1) Quant race — a pin names the exact artifact, so the row holding that quant answers it. The resolver keeps caches first for a bare id (the #13034 ordering, unchanged) but holds later rows of the same repo as alternates of the key: a repo:QUANT pin resolves to the row that actually has the quant instead of falling through to a remote download.
On the listing side, /v1/models now advertises the quant of the row that owns the repo id — the one a bare id loads — instead of newest-row first-wins, and the <id>:<quant> pin rows now merge quants across rows of the repo instead of first-row-wins, so every advertised pin is loadable.

2) Repo id claimed by a weightless/partial cache row — a row claims its repo id only when it holds weights. A weightless skeleton or a partial download keeps its row but no longer takes the id away from the loadable parked copy, so the media index resolves the id again (the skeleton itself throws no picks, so the id stays unambiguous).

3) Export default inside snapshots/ — the save-dir default now refuses any path under models--*/snapshots/ and falls back to the exports root, so an export can no longer become the repo's "newest revision" that the cache scans read back.

Each case has a test on the reported scenario (not just the mitigations): pinned quant and listing takeover, weightless and partial claims, and a frontend test for the save-dir guard. The existing anchors (newest-complete snapshot selection, complete-quants-only advertisement, one-id-per-parked-copy) are unchanged and green. Verified on top of current main — the branch merges clean and the suites stayed green across the last upstream commits, three of which touch the same files.

Known limitation:

  • a <sha>_gguf directory already sitting in snapshots/ is still read as a snapshot by the mtime selectors — this PR stops the export default from creating one
  • Minor cosmetic: the exports-root fallback names the folder after the sanitized source path.

Could you re-run the CI staging when you have a moment?

…g - sync branch with upstream before re-cutting the patch

65 upstream commit(s) since the branch base; see git log for the range.
VTplus and others added 11 commits October 14, 2026 12:15
…g - sync branch with upstream

27 upstream commit(s) since the branch base; see git log for the range.
…g - sync branch with upstream

72 upstream commit(s) since the branch base; see git log for the range.
…g - sync branch with upstream

92 upstream commit(s) since the branch base; see git log for the range.
…sable

A partial cache row whose older revision is complete still serves, so it
keeps the repo id and the listing follows the load; companions and shard
fragments no longer count as weights, the miss message names the pinnable
legacy spellings, and the GGUF save-dir default refuses cache-shaped
destinations. The media index admits such a row and picks from its newest
complete snapshot.
…g - sync branch with upstream

29 upstream commit(s) since the branch base; see git log for the range.
…uping

Merge origin/main (e795149, 102 upstream commits) and combine both
index features in _LocalGgufEntry: parked scan-folder copies stay listed
as alternates beside an incomplete cache skeleton, and the resolver now
also groups every GGUF build that shares a quant in a custom folder
(unslothai#13957).
The serving correction re-targeted partial rows to the newest complete
snapshot only when the row named a repo dir. A parked scan-folder copy
names the snapshot itself, so the media index listed the torn revision
only and dropped the offer while chat kept serving the older complete
revision. Resolve the cache-layout claim dir for both shapes and
re-target the picks, by path for a parked copy -- its repo id belongs
to the active cache, not to the copy.
…g - sync branch with upstream

1077 upstream commit(s) since the branch base; see git log for the range.
@VTplus

VTplus commented Oct 26, 2026

Copy link
Copy Markdown
Contributor Author

Updated the PR branch.

The fix addresses a catalog case where an incomplete download leaves a cache entry without model weights: deduplication prefers that entry over a complete GGUF copy in a registered scan folder, so /v1/models and /models/local omit the model even though Model Hub shows it.

Together, #12258, #12803, and #13343 improve support for complete model copies stored in registered Custom Folders.

…g - sync branch with upstream

331 upstream commit(s) since the branch base; see git log for the range.
…g - sync branch with upstream

33 upstream commit(s) since the branch base; see git log for the range.
…g - sync branch with upstream

284 upstream commit(s) since the branch base; see git log for the range.
…g - sync branch with upstream

1052 upstream commit(s) since the branch base; see git log for the range.

This branch has not been deployed

No deployments
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