@@ -198,11 +198,8 @@ func InstallBackend(ctx context.Context, systemState *system.SystemState, modelL
198198 } else {
199199 xlog .Debug ("Downloading backend" , "uri" , config .URI , "backendPath" , backendPath )
200200 if err := uri .DownloadFileWithContext (ctx , backendPath , "" , 1 , 1 , downloadStatus ); err != nil {
201- // Clean up the partially downloaded backend directory on failure
202- xlog .Debug ("Backend download failed, cleaning up" , "backendPath" , backendPath , "error" , err )
203- if cleanupErr := os .RemoveAll (backendPath ); cleanupErr != nil {
204- xlog .Warn ("Failed to clean up backend directory" , "backendPath" , backendPath , "error" , cleanupErr )
205- }
201+ // Don't remove backendPath here — fallback OCI extractions need the directory to exist
202+ xlog .Debug ("Backend download failed, trying fallback" , "backendPath" , backendPath , "error" , err )
206203
207204 success := false
208205 // Try to download from mirrors
@@ -215,34 +212,36 @@ func InstallBackend(ctx context.Context, systemState *system.SystemState, modelL
215212 }
216213 if err := downloader .URI (mirror ).DownloadFileWithContext (ctx , backendPath , "" , 1 , 1 , downloadStatus ); err == nil {
217214 success = true
218- xlog .Debug ("Downloaded backend" , "uri" , config .URI , "backendPath" , backendPath )
215+ xlog .Debug ("Downloaded backend from mirror " , "uri" , config .URI , "backendPath" , backendPath )
219216 break
220217 }
221218 }
222219
223- // Try fallback: replace latestTag + "-" with masterTag + "-" in the URI
224- fallbackURI := strings .Replace (string (config .URI ), latestTag + "-" , masterTag + "-" , 1 )
225- if fallbackURI != string (config .URI ) {
226- xlog .Debug ("Trying fallback URI" , "original" , config .URI , "fallback" , fallbackURI )
227- if err := downloader .URI (fallbackURI ).DownloadFileWithContext (ctx , backendPath , "" , 1 , 1 , downloadStatus ); err == nil {
228- xlog .Debug ("Downloaded backend using fallback URI" , "uri" , fallbackURI , "backendPath" , backendPath )
229- success = true
230- } else {
231- // Try another fallback: add "-" + devSuffix suffix to the backend name
232- // For example: master-gpu-nvidia-cuda-13-ace-step -> master-gpu-nvidia-cuda-13-ace-step-development
233- if ! strings .Contains (fallbackURI , "-" + devSuffix ) {
234- // Extract backend name from URI and add -development
235- parts := strings .Split (fallbackURI , "-" )
236- if len (parts ) >= 2 {
237- // Find where the backend name ends (usually the last part before the tag)
238- // Pattern: quay.io/go-skynet/local-ai-backends:master-gpu-nvidia-cuda-13-ace-step
239- lastDash := strings .LastIndex (fallbackURI , "-" )
240- if lastDash > 0 {
241- devFallbackURI := fallbackURI [:lastDash ] + "-" + devSuffix
242- xlog .Debug ("Trying development fallback URI" , "fallback" , devFallbackURI )
243- if err := downloader .URI (devFallbackURI ).DownloadFileWithContext (ctx , backendPath , "" , 1 , 1 , downloadStatus ); err == nil {
244- xlog .Debug ("Downloaded backend using development fallback URI" , "uri" , devFallbackURI , "backendPath" , backendPath )
245- success = true
220+ if ! success {
221+ // Try fallback: replace latestTag + "-" with masterTag + "-" in the URI
222+ fallbackURI := strings .Replace (string (config .URI ), latestTag + "-" , masterTag + "-" , 1 )
223+ if fallbackURI != string (config .URI ) {
224+ xlog .Debug ("Trying fallback URI" , "original" , config .URI , "fallback" , fallbackURI )
225+ if err := downloader .URI (fallbackURI ).DownloadFileWithContext (ctx , backendPath , "" , 1 , 1 , downloadStatus ); err == nil {
226+ xlog .Info ("Downloaded backend using fallback URI" , "uri" , fallbackURI , "backendPath" , backendPath )
227+ success = true
228+ } else {
229+ // Try another fallback: add "-" + devSuffix suffix to the backend name
230+ // For example: master-gpu-nvidia-cuda-13-ace-step -> master-gpu-nvidia-cuda-13-ace-step-development
231+ if ! strings .Contains (fallbackURI , "-" + devSuffix ) {
232+ // Extract backend name from URI and add -development
233+ parts := strings .Split (fallbackURI , "-" )
234+ if len (parts ) >= 2 {
235+ // Find where the backend name ends (usually the last part before the tag)
236+ // Pattern: quay.io/go-skynet/local-ai-backends:master-gpu-nvidia-cuda-13-ace-step
237+ lastDash := strings .LastIndex (fallbackURI , "-" )
238+ if lastDash > 0 {
239+ devFallbackURI := fallbackURI [:lastDash ] + "-" + devSuffix
240+ xlog .Debug ("Trying development fallback URI" , "fallback" , devFallbackURI )
241+ if err := downloader .URI (devFallbackURI ).DownloadFileWithContext (ctx , backendPath , "" , 1 , 1 , downloadStatus ); err == nil {
242+ xlog .Info ("Downloaded backend using development fallback URI" , "uri" , devFallbackURI , "backendPath" , backendPath )
243+ success = true
244+ }
246245 }
247246 }
248247 }
@@ -251,6 +250,10 @@ func InstallBackend(ctx context.Context, systemState *system.SystemState, modelL
251250 }
252251
253252 if ! success {
253+ // Clean up backend directory only when all download attempts have failed
254+ if cleanupErr := os .RemoveAll (backendPath ); cleanupErr != nil {
255+ xlog .Warn ("Failed to clean up backend directory" , "backendPath" , backendPath , "error" , cleanupErr )
256+ }
254257 xlog .Error ("Failed to download backend" , "uri" , config .URI , "backendPath" , backendPath , "error" , err )
255258 return fmt .Errorf ("failed to download backend %q: %v" , config .URI , err )
256259 }
0 commit comments