From c187b160e7bcbbcb75fb2231265024a2a8bc9b86 Mon Sep 17 00:00:00 2001 From: "LocalAI [bot]" <139863280+localai-bot@users.noreply.github.com> Date: Sat, 28 Feb 2026 13:10:53 +0100 Subject: [PATCH] fix(gallery): clean up partially downloaded backend on installation failure (#8679) When a backend download fails (e.g., on Mac OS with port conflicts causing connection issues), the backend directory is left with partial files. This causes subsequent installation attempts to fail with 'run file not found' because the sanity check runs on an empty/partial directory. This fix cleans up the backend directory when the initial download fails before attempting fallback URIs or mirrors. This ensures a clean state for retry attempts. Fixes: #8016 Signed-off-by: localai-bot Co-authored-by: localai-bot --- core/gallery/backends.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/core/gallery/backends.go b/core/gallery/backends.go index 1bd3213d2..833408cfc 100644 --- a/core/gallery/backends.go +++ b/core/gallery/backends.go @@ -202,6 +202,12 @@ func InstallBackend(ctx context.Context, systemState *system.SystemState, modelL } else { xlog.Debug("Downloading backend", "uri", config.URI, "backendPath", backendPath) if err := uri.DownloadFileWithContext(ctx, backendPath, "", 1, 1, downloadStatus); err != nil { + // Clean up the partially downloaded backend directory on failure + xlog.Debug("Backend download failed, cleaning up", "backendPath", backendPath, "error", err) + if cleanupErr := os.RemoveAll(backendPath); cleanupErr != nil { + xlog.Warn("Failed to clean up backend directory", "backendPath", backendPath, "error", cleanupErr) + } + success := false // Try to download from mirrors for _, mirror := range config.Mirrors {