Skip to content

Fix on-device GGUF image/video picks asking for a quantization - #8149

Merged
danielhanchen merged 7 commits into
mainfrom
fix/diffusion-gguf-repo-pick-filename
Aug 8, 2026
Merged

danielhanchen merged 7 commits into
mainfrom
fix/diffusion-gguf-repo-pick-filename

Conversation

@shimmyshimmer

@shimmyshimmer shimmyshimmer commented Aug 8, 2026 •

Copy link
Copy Markdown
Member

A GGUF pick can still reach the diffusion load carrying only a repo id and never a concrete .gguf filename. The backend requires one, so the pick dead-ends on a model the picker just advertised as one click loadable.

Scope

This is a follow up to #8053, which fixed the collapsed On Device row by making it forward ggufFilename. Two sibling paths still send a repo id with no filename, and one of them produces the same error message that #8053 removed.

What is still broken on main

1. A pinned diffusion quant, clicked in the Images or Video picker. renderPinnedQuantRow sends ggufVariant (a label like Q4_K_S) with no ggufFilename and no isGguf. The pages read the label only meta as a curated repo and ask for a pipeline load:

{"detail":"'unsloth/Z-Image-Turbo-GGUF' is a single-file GGUF repo; load it with model_kind 'gguf' and a .gguf filename, not as a full pipeline."}

Reachable from a normal flow: the collapsed On Device row has a pin control, so pinning a diffusion quant and then clicking it is enough.

2. The same pinned quant, clicked in the chat picker. The diffusion routing forwards quant: meta.ggufFilename ?? undefined, which is undefined here, so the Images page falls to the catalog spec. loadSpecFor() returns {kind: "gguf"} with no filename, because the catalog lists repos and not their files:

$ node --experimental-strip-types verify.ts
catalog spec for unsloth/Z-Image-Turbo-GGUF = {"kind":"gguf"}
route load posts: {"kind":"gguf"}
  -> backend needs a filename for kind 'gguf': MISSING = hard error
{"detail":"a single-file checkpoint name is required for a 'gguf' load."}

Fix

A resolver that turns a repo level pick into a real filename using the repo's own listing, read through the cache the picker rows already use, so the row just clicked usually costs no extra request.

Resolution order: exact filename, then quant label (favouring the copy on disk), then a sole downloaded file, then a sole file.

Two deliberate non-behaviours:

  • A genuinely ambiguous repo (several quants on disk) returns null and keeps the existing prompt, since only the expander can say which.
  • A stale label that matches nothing does not fall back to the sole file, so a pin left from a deleted quant prompts rather than quietly loading a different quant.

Wired into handleModelSelect and the route arrival effect on both images-page.tsx and video-page.tsx, plus isGguf: true on the pinned row.

The existing meta.isGguf branch now resolves instead of showing the toast. That branch is not reachable from a local GGUF directory today (those expand rather than select), so this part is defensive: it is the exact shape that regressed before #8053, and it now resolves rather than dead ends.

Split into two modules so the selection logic is testable on its own: gguf-filename-pick.ts is the pure pick with no app deps, diffusion-gguf-filename.ts is the request.

Compatibility

Frontend TypeScript only. No backend, Python, kernel or hardware paths touched, and no API or payload shape changed.

The isGguf: true added to the pinned row is a no op for chat, which already derived the same value:

const isGguf = explicitIsGguf ?? (ggufVariant != null || nativePathToken != null || model?.isGguf === true);

The pinned row always sets ggufVariant, so that expression was already true. Passing it explicitly produces the identical result.

The new branch in handleModelSelect sits after the existing curated, expander, direct .gguf and .safetensors branches, so every pick that worked before still takes its original branch. It only catches picks that previously fell through to the pipeline load, which the backend rejected.

Testing

Verified against a live Studio on macOS/MPS using unsloth/Z-Image-Turbo-GGUF, a repo holding one quant (z-image-turbo-Q4_K_S.gguf).

  • Both failures above reproduce against the running server before the change.
  • The resolver picks z-image-turbo-Q4_K_S.gguf, and the load the fixed code posts is accepted and the model actually loads: loaded: true, model_kind: gguf, family: z-image. Unloaded afterwards.
  • 8 new unit tests: sole quant, label to filename, downloaded preference, stale label, filename passthrough and case normalisation, ambiguous repos, malformed listings.
  • Full suite passes (946 tests), tsc -b and the test project both clean, catalog:check passes, vite build succeeds.
  • ESLint on the touched files stays at the 49 pre-existing problems, none added.

Verified through the API and unit tests rather than a browser click through, so a manual pass on the pinned row in the Images picker is worth doing before merge.

An on-device GGUF pick could reach the diffusion load carrying only a repo
id and never a concrete .gguf filename, so it dead-ended even though the row
had just shown itself as one-click loadable.

Three paths fed this:

- The pinned quant row sent its quant label with no ggufFilename and no
  isGguf, so the pages read it as a curated repo and asked for a pipeline
  load, which a single-file GGUF repo rejects.
- A curated GGUF artifact resolves to kind "gguf" with no filename, since
  the catalog lists repos and not their files.
- A GGUF directory failed the .gguf extension check and hit the "Pick a
  quantization for this model to load it" toast.

Add a resolver that turns a repo-level pick into a real filename using the
repo's own listing, through the cache the picker rows already use. It
prefers an exact filename, then a quant label (favouring the copy on disk),
then a sole downloaded file, then a sole file. An ambiguous repo still
returns null and keeps the prompt, and a stale label that matches nothing
does not fall back to the sole file, so a pin left from a deleted quant
prompts instead of loading a different quant.

Wire it into handleModelSelect and the route arrival effect on both the
Images and Video pages, and mark the pinned row as a GGUF pick.
chatgpt-codex-connector[bot]

This comment was marked as resolved.

Two gaps in the repo-level GGUF resolution.

A pinned row carries a quant label and no filename, and the chat picker
forwards only the filename, so the label was dropped at the URL boundary
and the target page saw a bare repo id. A curated repo still resolved
through the catalog; every other task-tagged on-device GGUF repo read as
a pipeline, which the backend rejects. The label now rides its own
`ggufQuant` param, since `quant` is consumed verbatim as a filename, and
both pages resolve it against the listing whatever the catalog says.

Resolving is a listing request and staging is a plan request, and
neither sets `busy`, so the user can pick again or switch pages while one
is in flight. The late continuation loaded anyway: `handleLoad` clears
the newer load's poll and overwrites `lastLoad`, and `quantRevert` is one
slot, so a stale rollback restored the superseded label over the current
one. A pick now claims the page and does nothing at all once something
else holds it, including the "pick a quantization" prompt, which would
otherwise blame a model the user had moved on from. A page switch, an
unload and an adapter deploy release the page too.

The pick itself moves into lib/diffusion-gguf-pick.ts so both pages share
one copy and the ordering is testable; the two page-specific halves
(images keys defaults on the repo, video on repo/filename) stay in the
pages. Local directory picks now pass their path to the listing instead
of asking it to resolve a filesystem path as a hub repo.

13 new tests: routed filename vs label vs neither, and superseded,
released, out-of-order and stale-rollback picks. Suite is 959 passing,
tsc -b and the test project clean, vite build clean, catalog:check and
i18n:check:strict pass, and eslint on the touched files stays at the 49
pre-existing problems.
@danielhanchen

danielhanchen commented Aug 8, 2026 •

Copy link
Copy Markdown
Member

Reviewed and pushed a follow-up commit on top.

Two P1s from the review reproduce on read, and one more gap alongside them:

Routed pinned pick outside the catalog. onSelect forwarded only meta.ggufFilename, which a pinned row deliberately does not have, so the label was dropped at the URL boundary. loadSpecFor recognises the repo only for the 12 image and 1 video curated GGUF ids, while routing is driven by the cached repo's task, so every other on-device diffusion GGUF repo still reached the pipeline branch. The label now rides a ggufQuant param (quant stays filename-only, since the page uses it verbatim) built by a new pure diffusionRouteSearch, and both pages resolve a ggufQuant arrival ahead of diffusionRoutePick.

Stale resolution. Nothing sets busy for the listing, so a second pick or a page switch could land mid-flight and the late continuation still loaded: it cleared the newer load's poll, overwrote lastLoad, and rolled quantRevert back over the newer label. Each page now owns a PickGuard; a pick continues past an await only while it still holds the page and is still mounted, and does nothing at all otherwise, prompt included. The download plan inside loadOrStage had the same window and takes the same check.

Local directory picks now pass their path as localPath, rather than asking the listing to resolve a filesystem path as a hub repo.

The resolve-then-load ordering moved into src/lib/diffusion-gguf-pick.ts so Images and Video share one copy; the two deliberate differences (images keys defaults on the repo, video on repo/filename) stay in the pages as callbacks.

Verification, in studio/frontend:

npm run typecheck   tsc -b and the test project, clean
npm test            959 passed (946 before this PR, 13 added here)
npm run build       vite build clean
npm run catalog:check / i18n:check:strict   pass
npx eslint <touched files>   49 problems, unchanged from the pre-change baseline
biome check on the new files   no errors

Not covered here: the manual pass on a live Studio, in particular a pinned non-catalog diffusion GGUF picked from Chat, and a throttled listing with a second pick or a page switch on top of it.

chatgpt-codex-connector[bot]

This comment was marked as resolved.

@danielhanchen danielhanchen self-assigned this Aug 8, 2026
@danielhanchen

Copy link
Copy Markdown
Member

Ran the PR through a simulation harness before and after, on three trees side by side: origin/main, the PR head (db01780b2), and the branch as it stands. Pushed one more fix that came out of it (3c52a72).

Is the issue real

Yes, and on main the first shape is worse than a prompt. Same click, three trees:

pinned diffusion quant, Images picker
  main    -> POST load {kind: "pipeline"}      "is a single-file GGUF repo; load it with model_kind 'gguf'"
  PR head -> POST load {kind: "gguf", filename: "z-image-turbo-Q4_K_S.gguf"}
  branch  -> same

the same pin, routed from Chat, repo NOT in the catalog
  main    -> POST load {kind: "pipeline"}      same rejection
  PR head -> POST load {kind: "pipeline"}      still broken: loadSpecFor only knows the 13 curated ids
  branch  -> POST load {kind: "gguf", filename: "some-diffusion-Q6_K.gguf"}

How the harness works

The page decision code is not re-implemented, it is executed. handleModelSelect, loadOrStage,
loadGgufRepoPick, runStagedLoad, the route-arrival effect and each route's validateSearch are pulled out
of the real .tsx with the TypeScript AST, type-stripped, and run in a vm context whose globals are the
page's state and fakes for the network, the toaster and the router. Swapping FE_ROOT points the same
scenarios at another checkout, which is how the before/after table above is produced. Ran in its own sandbox
with its own typescript, under temp/.

What was run

Area Cases Result
Before/after, both shapes, both pages 5 x 3 trees pass
Regressions: curated pipeline, curated single_file, expander GGUF, local .gguf, local .safetensors, trust gate, plain pipeline, routed arrivals, marker lifecycle 24 x 3 trees identical on all three
Ownership: supersede, page switch, unload, unmount, staged handoff, plan window, busy gate, out-of-order, repeats, rollback 30 pass (20 of them fail on the PR head)
URL layer: 15 label shapes through URLSearchParams and the real validateSearch, precedence, blanks, marker keys 19 pass
Cross platform paths: Linux, macOS, Windows, WSL, UNC, \\?\, spaces, unicode, trailing separators, bare filename, uppercase .GGUF 66 pass
Browser reach: post-baseline API scan on sources and on the emitted bundle, no DOM globals in the new libs, exact URLSearchParams wire forms 5 pass
Exhaustive interleavings of 11 events 1331 of length 3, 2092 of length 4 pass (fails on the PR head)
Resolver fuzz 25000 random listings pass
Old installs 5 pass

What the simulation found

An arrival with a quant label in ?quant= posted it verbatim as a filename, which is a guaranteed backend
error, and a URL carrying both quant and ggufQuant took the label rather than the exact filename. Neither
is reachable from the picker today, but a hand-built or shared link is. Fixed in 3c52a72: two pure helpers,
routedGgufFilename and routedGgufLabel, give one rule (a .gguf value is a filename and short-circuits,
anything else is a label and gets resolved), used by both pages and covered by 5 new tests.

Two other reported failures were artifacts of my own scenarios, not the code: diffusionRouteSearch trims a
label on purpose, and a pick made on a hidden page is not a reachable input because a hidden page renders no
picker. The model now says so explicitly.

Merging it

Nothing else moves. No Python, kernel, CUDA or ROCm path is touched, so there is no hardware matrix to run;
the OS dimension reduces to local path handling, which is covered above for all four shapes. No new endpoint,
no payload change, no persisted key, no storage schema bump: the only field a pick now sends that it did not
before is localPath on the variant listing, which that route already accepted before this PR, so a new
frontend against an older backend asks for nothing new. validateSearch gains one optional field, so links
without it validate exactly as before, and the router runs non-strict so nothing else in the URL is disturbed.
The 24 regression scenarios above behave identically on main, on the PR head and on this branch.

Browsers: Vite builds to the modules baseline (Chrome 87, Edge 88, Firefox 78, Safari 14). The changed
sources use nothing past ES2022, hold no DOM or platform globals in the new pure modules, and the emitted
chunk introduces no API the tree did not already ship. The URL work goes through URLSearchParams, which is
one spec across all four engines, asserted against exact wire forms.

Repo gate

npm run typecheck   clean, both TS projects
npm test            965 passed (946 before this PR, 19 added)
npm run build       clean
npm run catalog:check / i18n:check:strict   pass
eslint on the touched files   49 problems, unchanged from the pre-change baseline
biome on the new files   no errors

Still worth a manual pass on a live Studio before merge, in particular a pinned non-catalog diffusion GGUF
picked from Chat, and a throttled listing raced by a second pick.

chatgpt-codex-connector[bot]

This comment was marked as resolved.

@chatgpt-codex-connector

Copy link
Copy Markdown

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

Reviewed commit: 770c351ca4

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

@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Aug 8, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Aug 8, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Aug 8, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Aug 8, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Aug 8, 2026
@danielhanchen

Copy link
Copy Markdown
Member

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. You're on a roll.

Reviewed commit: c54c85fe5f

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

Copy link
Copy Markdown
Member

Converged. Final head c54c85fe5, approved on that exact commit.

Rounds

Round 2 raised two P1s, both correct, both consequences of the ownership model I added in round 1. I reproduced each against the shipped code before touching anything, then fixed and re-ran.

Routed loads carried no token: the route effect's plain loadOrStage never claimed the page, so staging an uncached pick and then arriving with an already-cached exact filename let the staged pick's onReady put itself back over the routed model. The effect now claims before dispatching and hands the token down.

Eject did not end the pick: I had release() preserve isLatest so a page switch would defer a staged download rather than drop it, then reused the same call for eject and adapter deploy, where dropping it is the point. Ejecting and having the model reload itself a minute later undoes the eject. Split into release() for visibility and cancel() for end-of-pick; eject and deploy cancel, only the hidden-page effect releases. One of my own tests had asserted the old behaviour and now asserts the opposite.

Fixed in 770c351c, both 👍 with replies.

Round 3 was a clean approval on 770c351c.

Round 4 re-confirmed after the final comment pass (c54c85fe5), which is AST-verified comment-only: 11 of 11 files reported code unchanged, 87 comment lines out and 75 in. The reasoning that is not obvious from the code stayed, shortened: the ownership and staleness rules, the release-versus-cancel distinction, and the label-versus-filename URL contract.

Cross-platform and browser

Replicated onto a staging repo rather than the org queue. All four disposable workflows green: ubuntu-latest, macos-14, windows-latest, and studio-live Playwright across chromium, firefox and webkit. Of the replicated org suite, 12 runs green, 9 cancelled by concurrency.cancel-in-progress after the newer push (superseded, not failures). Staging PR closed, never merged.

One job stayed red: Core, on all three HF/TRL legs, failing tests/test_generated_fullgraph_fallback.py::test_maybe_compile_routes_fullgraph_through_the_fallback and ::test_the_alias_routes_a_fullgraph_compile_through_the_fallback. That job checks out unsloth_zoo @ main and runs its suite; this PR changes no Python at all. Both tests pass in isolation against the same zoo main commit locally, and they fail identically on every matrix leg and on a re-run, so it reads as a full-suite ordering interaction inside zoo's own tests rather than dependency drift. Unrelated to this PR, but worth someone looking at on zoo.

Final state

typecheck   clean, both TS projects
npm test    966 passed (946 before this PR, 20 added)
build       clean
eslint      49 problems on the touched files, unchanged from the pre-change baseline

Alongside the repo suite, a harness that executes the real page code (the decision functions are extracted from the .tsx and run against fake state) covers 30 ownership scenarios, 19 URL cases, 66 cross-platform path cases, 9 for this round's two items, 3423 exhaustive event interleavings and 25000 fuzzed listings. Everything green on the final head.

Thread pruned twice: 10 comments and 1 trigger removed, 3 review husks minimized. Rejected and untriaged items would have been kept; there were none.

@danielhanchen
danielhanchen merged commit 7ff60be into main Aug 8, 2026
40 of 44 checks passed
@danielhanchen
danielhanchen deleted the fix/diffusion-gguf-repo-pick-filename branch August 8, 2026 13:51
danielhanchen added a commit that referenced this pull request Aug 9, 2026
)

* Repin six UI contracts on what they guard, not how it was spelled

Repo tests (CPU) is red on main with six failures. All six are source-shape
contracts whose subject was rewritten by #8082 and #8149; in every case the
behaviour they exist to protect is intact, and in two cases it is better than
what the assertion described.

Three in test_update_release_notes.py asserted the literal Tailwind class
max-h-[calc(100dvh_-_2rem)]. #8082 replaced that fixed cap with stackGeometry,
which subtracts the same 2rem when nothing is in the way and subtracts more when
the Live monitor is, so the stack dodges it instead of sitting under it. The
arithmetic is checked numerically in monitor-stack-inset.test.ts, which pins
stackGeometry(null, W, H).maxHeight to H - 32 among thirteen other cases. What
these tests can still add is that every stack element reads it, so they now
count stack containers and require a cap on each. Counting matters: there are two
such elements, browser and desktop, and capping one and not the other is the
mistake worth catching. A fourth test names the node test, so deleting the
numeric check does not quietly leave the cap unguarded.

Three in test_model_picker_contracts.py:

- The routed pick test pinned diffusionRoutePick's second argument, which was
  respelled from routeSearch.quant to routedFilename. The catalog spec is the
  third argument and is the thing the test is named for, so the second is no
  longer matched.
- The GGUF guard test required a toast.error in a branch that used to reject a
  repo-id pick. #8149 made that branch resolve the repo's own .gguf instead,
  which is the better answer. The invariant that survives is that the branch does
  something: a bare return there drops the pick with no request and no message.
- The deferred-load test required the flush effect to end with }, [active]); and
  to call handleLoadRef directly. The load body moved into runStagedLoad, shared
  with the visible path, so the dependency array grew. It now accepts either
  spelling and, when the helper is used, follows through into it.

Mutation-tested, all eight caught: cap dropped from the browser stack; from the
desktop stack alone; desktop stack stops measuring itself; node test stops
pinning H - 32; repo-id GGUF pick returns bare; routed pick drops its catalog
spec; deferred flush clears the flag and stops; runStagedLoad loads nothing. The
first two survived an earlier draft that used a plain substring check, which is
why the counting form is there.

tests/studio: 3 failed, 2795 passed. The three are
test_studio_gguf_export_script_pin.py, which fails identically on main and is
outside this job's scope.

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Bound the deferred-flush match to its own effect

Keying the closing boundary on `[active` let a validly reordered dependency
array run the match past the effect and on to the next hook, where loadOrStage's
own handleLoadRef call satisfied the loader assertion for a flush that loads
nothing. Stop at the first boundary and check the deps separately.

* Check the catalog spec by position, not by presence

The capture is every argument after `wanted`, so a substring check did not prove
the spec reached the third parameter. `diffusionRoutePick(wanted, routedFilename
?? loadSpecFor(wanted, IMAGE_CATALOG)?.filename)` type-checks, passes the catalog
filename as the quant and drops the spec, which sends curated single-file
artifacts down the GGUF branch, and it satisfied the old assertion. Split the
argument list on its own commas and pin the third.

* Tighten the repinned contract comments

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: danielhanchen <[email protected]>
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