Skip to content

fix(studio): return 404 for mistyped GGUF model ids on /v1 API - #8389

Merged
danielhanchen merged 5 commits into
unslothai:mainfrom
Souravrajvi0:feat/fix-api-unknown-model-8376-1cc0
Aug 11, 2026
Merged

danielhanchen merged 5 commits into
unslothai:mainfrom
Souravrajvi0:feat/fix-api-unknown-model-8376-1cc0

Conversation

@Souravrajvi0

@Souravrajvi0 Souravrajvi0 commented Aug 11, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #8376

Summary

When a client called /v1/chat/completions (or other OpenAI-compatible endpoints) with a model name that was not loaded — for example a mistyped vision model id — the server silently routed the request to whatever model was already in memory. The client then got misleading errors (e.g. "Image provided but current GGUF model does not support vision") instead of a clear model_not_found response.

This change refuses mistyped or missing GGUF catalog model ids instead of answering with the wrong weights.

Root cause

_reject_unservable_model() only refused a named model when it looked like an explicit quant (:Q4_K_M) or was already known locally (here). A bare hub-style id like unsloth/typo-vision-GGUF that was not downloaded and not in the catalog fell through to drop-in OpenAI compatibility — so the loaded text model answered the request.

Fix

  • Added looks_like_gguf_hub_repo_id() in openai_auto_download.py to detect ids that clearly target this server's GGUF catalog:
    • repo names ending in -GGUF
    • anything under the unsloth/ namespace
  • Updated _reject_unservable_model() to treat those ids as concrete references and return 404 model_not_found when they do not match the loaded model.

LiteLLM / OpenRouter-style labels (openai/gpt-4o, anthropic/claude-3.5-sonnet, etc.) still fall through to the loaded model for drop-in compatibility.

Files changed

File Change
studio/backend/core/inference/openai_auto_download.py looks_like_gguf_hub_repo_id() helper
studio/backend/routes/inference.py Use helper in _reject_unservable_model()
studio/backend/tests/test_openai_auto_download.py Helper + reject-path unit tests
studio/backend/tests/test_openai_auto_switch.py Chat completions integration test (image + mistyped id → 404)

Test plan

  • pytest tests/test_openai_auto_download.py::test_looks_like_gguf_hub_repo_id
  • pytest tests/test_openai_auto_download.py::test_a_mistyped_gguf_repo_is_refused_while_another_model_is_loaded
  • pytest tests/test_openai_auto_switch.py::test_chat_mistyped_gguf_repo_404s_before_vision_guard
  • Regression: foreign provider labels (openai/gpt-4o, etc.) still fall through
  • Regression: org/Unlisted ids not in catalog still fall through

Treat unsloth/ and -GGUF hub repo ids as concrete references so a wrong
model name is refused instead of being answered by the loaded model.
Fixes unslothai#8376.
@danielhanchen

Copy link
Copy Markdown
Member

Pushed a one line change to this branch. The helper and the reject gate are good, but the except Exception handler had to stay fail open.

Backend CI was red on all four interpreters. Reproduced locally against the full suite on the previous head:

FAILED tests/test_openai_auto_download.py::test_diagnosis_failure_never_breaks_a_servable_request
1 failed, 21314 passed, 130 skipped, 36 deselected in 804s

That handler runs when the local model scan throws, and at that point we cannot tell "not downloaded" apart from "the scan broke". Refusing a catalog shaped id there returns 404 with a message saying the model is not downloaded on this server, which is exactly the thing we just failed to verify. Before this PR the fail closed path covered explicit quants only, where the blast radius is small. Extending it to the whole unsloth/ namespace plus every -GGUF suffix means one transient index or disk fault 404s nearly every real model id, including models that are downloaded and switchable.

Dropping and not gguf_hub_repo from that single branch keeps the fix fully intact. Behaviour with unsloth/A-GGUF:UD-Q4_K_XL loaded:

Request main this branch
unsloth/typo-vision-GGUF answered by resident model 404 model_not_found
unsloth/typo-vision answered by resident model 404 model_not_found
someorg/whatever-GGUF answered by resident model 404 model_not_found
openai/gpt-4o, anthropic/claude-3.5-sonnet, gpt-4, org/Unlisted falls through falls through
the loaded id, any case, or with :latest falls through falls through
any id while the scan is throwing falls through falls through

Full backend suite on the new head: 21315 passed, 130 skipped, 36 deselected.

Two things to settle before this goes in.

  1. [Bug] API Query to non-Existant model results in no confirmation or error #8376 was closed as expected behaviour, on the grounds that unknown names are accepted as aliases for LiteLLM and OpenRouter clients. This reverses that for the unsloth/ namespace and the -GGUF suffix. I think the carve out is the right call given foreign provider labels still fall through, but @Lyxot should confirm since it is his call on that setting.

  2. looks_like_gguf_hub_repo_id accepting the entire unsloth/ namespace also changes Transformers backed servers, not just the GGUF catalog that the helper name and docstring describe. A server running unsloth/Llama-3.2-1B now 404s a request for unsloth/Llama-3.2-3B. That is probably what we want, but either the docstring should say so or the rule should be narrowed to -GGUF plus catalog membership.

Also worth a rebase, the branch is a good way behind main now.

The looks_like_gguf_hub_repo_id helper also gates Transformers-backed
Studio entries, not just -GGUF repos. Update the docstring accordingly.
@Souravrajvi0

Copy link
Copy Markdown
Contributor Author

Thanks for the review and for pushing the fail-open fix — that makes sense; extending the except Exception path to catalog-shaped ids would have been a bad trade when the scan can't distinguish "not downloaded" from "scan broke".

Pulled your commit and updated the looks_like_gguf_hub_repo_id docstring to note that the unsloth/ namespace covers Transformers-backed Studio entries too, not just -GGUF repos.

On the two open points: agree the carve-out is the right call (foreign provider labels still fall through), and happy for @Lyxot to confirm on #8376. Branch is rebased on current main.

@danielhanchen

Copy link
Copy Markdown
Member

@codex review

danielhanchen added a commit to shimmyshimmer/unsloth-staging-4 that referenced this pull request Aug 11, 2026
@danielhanchen

Copy link
Copy Markdown
Member

Thanks for the docstring update, that settles point 2 well.

Pushed one more fix on top. Simulating the gate across the full product of id shape x loaded backend x resolver state x auto-switch x index-built x POSIX/NT path semantics (7168 cells per tree) turned up a second regression that the unit tests did not reach: a model loaded from a local directory gets 404d under its own hub id, while it is the model actually serving.

The model 'unsloth/gemma-3-4b-it' is not downloaded on this server.

ModelConfig.identifier is the path for a local load, so the orchestrator publishes a path and the model is advertised under a bare name. _loaded_satisfies then has nothing namespaced to compare unsloth/gemma-3-4b-it against, the id is read as a concrete reference to something else, and the request is refused. This hits the Transformers and MLX backends, so it is a drop-in break on the non-GGUF paths rather than in the GGUF catalog the change is aimed at.

The fix keeps the promotion but makes it decisive only against a resident that carries a hub-style id of its own. An HF cache path still maps back to org/name via public_model_id, so the catalog case is unaffected and a typo there still 404s. Where the resident is a bare directory name the comparison is genuinely undecidable, so it falls through as before. The check runs at the decision point rather than next to the other shape tests, so a foreign routing label never pays for it.

Behaviour across the three trees, same 7168 cells each, diffed against the merge base:

tree changed intended 404s unexpected forbidden crashes
before this fix 300 252 0 48 0
after 168 168 0 0 0

Every remaining change is a mistyped catalog id becoming a 404. Foreign labels (openai/gpt-4o, anthropic/claude-3.5-sonnet, gpt-4, org/Unlisted), the loaded model under any spelling including :latest, and every path form (POSIX, ~, WSL /mnt/c/..., Windows drive and UNC, forward-slash Windows) are untouched. Malformed ids follow the Hub's own rules, so unsloth/model--GGUF, unsloth/../model-GGUF and unsloth/model-GGUF.git fall through rather than 404, matching validate_repo_id.

I also drove every model-bearing surface end to end rather than just chat, since the gate is shared. On the merge base all six answered a mistyped id with the resident model, so the original report understated the scope: /v1/chat/completions, /v1/completions, /v1/embeddings, /v1/responses, /v1/messages, /v1/messages/count_tokens.

Two regression tests added, both of which fail on the previous head with the misleading message above. Full backend suite: 21317 passed, 130 skipped, 36 deselected.

One note on scope for whoever merges: this is still a deliberate change to the drop-in alias behaviour that #8376 was closed under, now covering the whole unsloth/ namespace and any -GGUF suffix. The code and the docstring agree with each other now, so it just needs a yes from @Lyxot on the policy itself.

@chatgpt-codex-connector

Copy link
Copy Markdown

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

Reviewed commit: 1ef3ed4fc4

ℹ️ 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 77e29f4 into unslothai:main Aug 11, 2026
39 of 50 checks passed
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.

[Bug] API Query to non-Existant model results in no confirmation or error

3 participants