Skip to content

Studio: fix two first-use regressions from deferred startup hardware detection - #16629

Merged
danielhanchen merged 8 commits into
mainfrom
fix/16469-first-use
Nov 5, 2026
Merged

danielhanchen merged 8 commits into
mainfrom
fix/16469-first-use

Conversation

@danielhanchen

@danielhanchen danielhanchen commented Nov 4, 2026 •

Copy link
Copy Markdown
Member

Follow-up to #16469 (opt-in startup ML warmup). With startup hardware detection now deferred by default, two first-use paths started answering on an unmeasured verdict. This keeps #16469's cold, torch-free idle start and fixes both.

What changes

  1. Images listing before hardware detection. Until detection completes, the listing reported every recognised diffusion family as loadable (family is not None). A family whose diffusers pipeline class is missing and that sd.cpp cannot assemble was therefore listed as an image model and only failed on load, which breaks the rule that the picker and the loader agree. Only the engine prediction needs the device. Before detection the listing now calls the same family_buildable_here with provisional=True, which answers only the device-dependent engine predictions optimistically and keeps every device-free refusal, so the listing and the loader still share one predicate. The load re-checks with the measured verdict. None of these checks imports torch or diffusers or starts detection.
  2. Chat autoload on chat-only hosts. With the verdict deferred, a CPU-only / Intel Mac / chat-only host read as "unknown", so autoload tried a cached safetensors repo, got the backend's chat-only refusal and stopped with an error toast before the default GGUF download. Autoload now asks for detection first, and only when a non-GGUF candidate exists, so a GGUF-only cache keeps the probe-free idle path. On a busy host detection outlasts the health read's single 5 s wait, so autoload keeps reading health until the verdict is measured (bounded at 60 s; each health read races the remaining deadline and the send's abort signal, so a stalled /api/health cannot outlive the deadline or a stopped send; past the deadline it stays fail-open as on main).

The post-detection listing contract tests in test_cached_gguf_routes.py (krea2, MOSS-Image, and the old-diffusers picker / loader agreement tests that stub the engine prediction) now pin detection complete instead of depending on test order. Run alone or in a fresh process on current main they fail (13 krea2 / MOSS-Image cases, plus the two old-diffusers tests on every staging OS), because nothing in the file marks detection complete.

Results

Behaviour main (after #16469) this branch
test_cached_gguf_routes.py -k "krea2_gguf_is_an_image or moss_image_gguf_inventory", run alone 13 failed 13 passed
Pre-detection listing of a family with no pipeline class and no sd.cpp support text-to-image image-diffusion-unsupported (same as after detection)
Autoload, chat-only host, only a cached safetensors repo error toast, no default GGUF default GGUF downloads and loads
Autoload, deferred verdict, host turns out to have a GPU backend loads the cached safetensors repo same
Autoload, chat-only host, detection slower than the 5 s health wait error toast, no default GGUF waits for the verdict, then the default GGUF
Autoload, deferred verdict, GGUF-only cache no detection request no detection request
torch / diffusers imported by the listing before detection (18 families x gguf/pipeline) no no

Tests

  • New test_listing_before_detection_keeps_device_free_refusals: fails on main, passes here; it also fails if the listing calls family_buildable_here or predict_engine before detection.
  • Autoload harness (tests/studio/test_chat_autoload_failure_gate.py) gains a fetchDeviceType stub and a detectedChatOnly scenario field; 4 deferred-verdict scenarios, including detection that lands only after several more health reads (3 fail without the change); the whole file passes, 85 tests.
  • Backend: test_cached_gguf_routes.py, test_cold_model_catalog.py, test_selective_ml_warmup.py, test_startup_ml_warmup.py, test_ml_warmup_idle_runtime.py: only failures are a local huggingface_hub / diffusers version mismatch in test_pipeline_class_guard_passes_every_shipped_family (fails on main too) and subprocess timeouts on a heavily loaded host in the startup subprocess tests.
  • tests/studio/test_model_picker_contracts.py passes.
  • Per-family matrix before vs after detection: no cell where the pre-detection answer refuses something the post-detection answer allows.

Not covered

  • No GPU host run here; on a GPU host some families listed before detection can still become unsupported once detection lands. That is the intended provisional answer, and the load re-checks it.
  • The autoload change is covered by the frontend harness and code reading, not a browser run on a real chat-only host.
  • If detection takes longer than 60 s, autoload stays fail-open, as on main.
  • A real-backend before/after run on a chat-only host showed the race behind the bounded wait: one run matched (BEFORE error toast, AFTER default GGUF download) and two did not, because detection on the loaded host took about 20 s, longer than the single 5 s wait. That is what the second change addresses.

Before / after (chat-only CPU host, cache holds only a safetensors repo)

First send with no model loaded, base b5c1396 vs head 3514aec, each Studio on an isolated HF cache seeded with trl-internal-testing/tiny-Qwen3ForCausalLM. Before: autoload tries the cached repo, the backend refuses it and the send stops with an error. After: autoload measures the verdict, skips the repo and starts the default GGUF.

Before: refusal toast for the cached safetensors repo. After: the default Gemma 4 E2B GGUF download starts

…dware detection

Before detection the listing reported every known diffusion family as loadable, so a family
whose diffusers class is missing and that sd.cpp cannot assemble showed up as an image model
and only failed on load. Only the engine prediction needs the device; keep that provisional
and apply the class and sd.cpp checks as before. The post-detection contract tests now pin
detection complete instead of depending on test order.
…s a non-GGUF cache

With startup detection deferred, a chat-only host read as unknown, so autoload tried a cached
safetensors repo, got the backend's refusal and stopped before the default GGUF. Ask for
detection first when such a candidate exists; a GGUF-only cache stays free of the probe.
…r tests pin an engine

Those tests stub predict_engine, which is a post-detection answer; run in a fresh process the
listing is still before detection and leaves the engine provisional, so they failed on every
staging OS.
danielhanchen added a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Nov 4, 2026
…toload picks a candidate

On a busy host detection outlasts the health read's single 5 s wait, so autoload still went on
with an unmeasured verdict and tried the cached non-GGUF repo. Poll the health read (bounded at
60 s, abortable) until the verdict is measured; past the bound it stays fail-open as before.
…rovisional=True)

One predicate for picker and loader: before detection only the device-dependent
engine predictions are answered optimistically, the device-free refusals are the
router's own, so the listing cannot drift from the load check.

[skip ci]
@danielhanchen
danielhanchen marked this pull request as ready for review November 5, 2026 12:54
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 5, 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-11-05T13:09:23.686275Z 3514aec 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.

@danielhanchen

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: 98f28d9067

ℹ️ 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 +3379 to +3381
async function awaitMeasuredVerdict(signal?: AbortSignal): Promise<void> {
try {
await fetchDeviceType({ detectHardware: true });

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 health reads by the deadline and cancellation signal

If a health request stalls while autoload is measuring a deferred verdict, this await can block indefinitely—even after the user stops the send. fetchDeviceType delegates to readHealth in studio/frontend/src/config/env.ts, whose fetches have neither an abort signal nor a request timeout; its five-second polling window does not bound an individual fetch. The initial request also runs before the 60-second deadline is established, and subsequent requests can overrun that deadline. Bound both health awaits by the remaining time and the caller's cancellation signal so a stalled request cannot leave autoload pending indefinitely.

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.

Fixed in 3514aec: each verdict read now races the remaining deadline and the send's abort signal; harness test stalls /api/health and stops the send.

@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

1 similar comment
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Breezy!

Reviewed commit: 3514aec643

ℹ️ 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 pushed a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Nov 5, 2026
@danielhanchen
danielhanchen merged commit 23907ad into main Nov 5, 2026
@danielhanchen
danielhanchen deleted the fix/16469-first-use branch November 5, 2026 13:39
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.

1 participant