Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Nov 19, 2025

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 AI and others added 2 commits November 19, 2025 21:59
- Fixed bug in DeleteModelFromSystem where OR was used instead of AND for file suffix check
- Fixed bug where model config filename comparison was incorrect
- Added comprehensive Ginkgo test to verify shared model files are not deleted

Co-authored-by: mudler <[email protected]>
Copy link
Contributor Author

Copilot AI commented Nov 19, 2025

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 AI changed the title [WIP] Fix: Do not delete files if used by other configured models fix: prevent deletion of model files shared by multiple configurations Nov 19, 2025
Copilot AI requested a review from mudler November 19, 2025 22:02
Copilot finished work on behalf of mudler November 19, 2025 22:02
@mudler mudler marked this pull request as ready for review November 20, 2025 11:33
@mudler mudler merged commit 6632a70 into fix/delete-files Nov 20, 2025
27 checks passed
@mudler mudler deleted the copilot/sub-pr-7235 branch November 20, 2025 11:33
mudler added a commit that referenced this pull request Nov 20, 2025
#7317)

* Initial plan

* fix: do not delete files if used by other configured models

- Fixed bug in DeleteModelFromSystem where OR was used instead of AND for file suffix check
- Fixed bug where model config filename comparison was incorrect
- Added comprehensive Ginkgo test to verify shared model files are not deleted

Co-authored-by: mudler <[email protected]>

* fix: prevent deletion of model files shared by multiple configurations

Co-authored-by: mudler <[email protected]>

---------

Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Co-authored-by: mudler <[email protected]>
Signed-off-by: Ettore Di Giacinto <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants