fix: prevent deletion of model files shared by multiple configurations
Fixes #7171 - When deleting a model configuration, LocalAI was incorrectly removing model files still referenced by other configurations.
Root Cause
Two bugs in DeleteModelFromSystem:
-
Line 376: Logic error using OR instead of AND for file extension filtering
// Before: Skips ALL files (no file has both extensions) if !strings.HasSuffix(f.Name(), ".yaml") || !strings.HasSuffix(f.Name(), ".yml") // After: Skips only non-YAML files if !strings.HasSuffix(f.Name(), ".yaml") && !strings.HasSuffix(f.Name(), ".yml") -
Line 379: Incorrect filename comparison prevents skipping the config being deleted
// Before: Compares "model1.yaml" with "model1" - never matches if f.Name() == name // After: Properly compares full filenames if f.Name() == fmt.Sprintf("%s.yaml", name) || f.Name() == fmt.Sprintf("%s.yml", name)
Changes
- Fixed both bugs in
core/gallery/models.go - Added Ginkgo test that verifies:
- Shared model files are preserved when one config is deleted
- Shared model files are removed only when all referencing configs are deleted
Test Case
// Setup: Two configs sharing the same model file
model1.yaml -> shared_model.bin
model2.yaml -> shared_model.bin
// Delete model1 -> shared_model.bin remains (model2 still uses it)
// Delete model2 -> shared_model.bin removed (no references)
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.
Just as a heads up, I was blocked by some firewall rules while working on your feedback. Expand below for details.
[!WARNING]
Firewall rules blocked me from connecting to one or more addresses (expand for details)
I tried to connect to the following addresses, but was blocked by firewall rules:
cdn01.quay.io
- Triggering command:
/tmp/go-build1857095799/b001/gallery.test -test.testlogfile=/tmp/go-build1857095799/b001/testlog.txt -test.paniconexit0 -test.timeout=10m0s -test.v=true(dns block)huggingface.co
- Triggering command:
/tmp/go-build709347668/b001/gallery.test -test.paniconexit0 -test.timeout=10m0s -test.v=true -ginkgo.focus=does not delete shared model files(dns block)- Triggering command:
/tmp/go-build1857095799/b001/gallery.test -test.testlogfile=/tmp/go-build1857095799/b001/testlog.txt -test.paniconexit0 -test.timeout=10m0s -test.v=true(dns block)If you need me to access, download, or install something from one of these locations, you can either:
- Configure Actions setup steps to set up my environment, which run before the firewall is enabled
- Add the appropriate URLs or hosts to the custom allowlist in this repository's Copilot coding agent settings (admins only)