LocalAI icon indicating copy to clipboard operation
LocalAI copied to clipboard

fix: prevent deletion of model files shared by multiple configurations

Open Copilot opened this issue 3 months ago • 1 comments

Fixes #7171 - When deleting a model configuration, LocalAI was incorrectly removing model files still referenced by other configurations.

Root Cause

Two bugs in DeleteModelFromSystem:

  1. 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")
    
  2. 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.

Copilot avatar Nov 19 '25 21:11 Copilot

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:

Copilot avatar Nov 19 '25 22:11 Copilot