Skip to content

fix(api): return 404 for unknown weight-file model names instead of gallery fallthrough#10171

Open
localai-bot wants to merge 1 commit into
masterfrom
fix/model-not-found-guard-10162
Open

fix(api): return 404 for unknown weight-file model names instead of gallery fallthrough#10171
localai-bot wants to merge 1 commit into
masterfrom
fix/model-not-found-guard-10162

Conversation

@localai-bot
Copy link
Copy Markdown
Collaborator

What

Tightens the model-existence guard in SetModelAndConfig so an unknown model name that points at a concrete weight file returns a clean 404 instead of silently falling through to the gallery autoloader and triggering a surprise HuggingFace download.

Fixes #10162.

Why

The guard skipped the existence check for any model name containing /, to let HuggingFace org/repo IDs (which backends like diffusers download on the fly) pass through. But a name like local/model.gguf (the parameters.model weight path, mistakenly passed as the request model) also contains /, so it bypassed the guard. With AUTOLOAD_GALLERIES on by default, the request then fell through to the gallery autoloader, which attempted to download an unrelated GGUF from HuggingFace instead of returning a clear error.

In the linked issue, a user passed --model local/DeepSeek-R1-Distill-Qwen-1.5B-BF16.gguf (the file path) rather than the configured YAML name, and saw LocalAI try to download from bartowski/... instead of failing fast.

How

  • Only treat a /-containing name as a remote org/repo ID when it does not end in a recognized model-file extension. Names pointing at a concrete file are verified like any other.
  • New model.HasKnownModelFileExtension reuses the existing knownModelsNameSuffixToSkip list as the single source of truth. Version-style suffixes (e.g. the .0 in stabilityai/stable-diffusion-xl-base-1.0) are not in that list, so genuine repo IDs are still treated as remote and pass through.
  • CheckIfModelExists already resolves relative paths against the models dir, so a loose weight file addressed by its relative path (and that genuinely exists) still passes.

Tests

  • core/http/middleware/request_test.go: a missing weight-file path (local/missing-model.gguf) now returns 404; an existing one (local/present-model.gguf) passes through. Existing HuggingFace-ID passthrough test (stabilityai/stable-diffusion-xl-base-1.0) stays green.
  • pkg/model/loader_test.go: unit tests for HasKnownModelFileExtension (file paths vs repo IDs).

Behavior unchanged for legitimate HuggingFace IDs and for AUTOLOAD_GALLERIES when a real gallery match exists.

…allery fallthrough

The model-existence guard in SetModelAndConfig skipped the check for any
model name containing "/", to let diffusers-style HuggingFace "org/repo"
IDs download on the fly. But a name like "local/model.gguf" (the
parameters.model weight path, mistakenly passed as the request model)
also contains "/", so it bypassed the guard and silently fell through to
the gallery autoloader, which then attempted a surprising HuggingFace
download (issue #10162).

Tighten the guard so it only treats a "/"-containing name as a remote ID
when it does NOT end in a recognized model-file extension. Names that
point at a concrete weight file are now verified like any other, so a
wrong name returns a clear 404 while a loose weight file addressed by its
relative path (resolved by CheckIfModelExists against the models dir)
still passes.

The extension check reuses pkg/model's known-suffix list via the new
HasKnownModelFileExtension helper, so version-style suffixes like the
".0" in "stabilityai/stable-diffusion-xl-base-1.0" are correctly treated
as remote IDs.

Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
Assisted-by: Claude:claude-opus-4-8 [Claude Code]
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.

Can not Integrate LocalAI with ultraworkers/claw-code

2 participants