fix(ollama): guard nil filter in galleryop.ListModels (#9817)#9836
Merged
Conversation
The Ollama /api/tags handler passes a nil filter to galleryop.ListModels. When ModelsPath contains any non-skipped loose file the function then calls filter(name, nil) and panics, which Echo surfaces to clients as "Server disconnected without sending a response" - the exact failure Home Assistant's Ollama integration reports against LocalAI. Mirror the nil guard already present in ModelConfigLoader.GetModelConfigsByFilter so every caller is safe, and add a regression test that exercises the loose-file path with a nil filter. Assisted-by: claude:claude-opus-4-7 [Claude Code] Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
filterargument insidegalleryop.ListModels(mirrors the same guard already present inModelConfigLoader.GetModelConfigsByFilter).masterand passes with the fix.Root cause (closes #9817)
The Ollama
/api/tagshandler (core/http/endpoints/ollama/models.go:21) calls:ListModelsthen iterates over loose files inModelsPathand invokesfilter(m, nil)unconditionally. Withfilter == nil, the first non-skipped file in the models directory triggers a nil-function panic. Echo's recover middleware aborts the response mid-flight, which Home Assistant'shttpx/ollamaclient surfaces as:(See traceback in #9817 — fails inside
client.list()->GET /api/tags.)Every other caller of
ListModelsalready supplies a non-nil filter (config.NoFilterFn,BuildNameFilterFn,BuildUsecaseFilterFn), so the Ollama endpoint was the only path hitting this. Fixing it inListModelsitself prevents the same footgun from recurring at any future call site.Test plan
go test ./core/services/galleryop/...— passesgo test ./core/http/endpoints/ollama/...— passesclient.list()no longer disconnects