mirror of
https://github.com/mudler/LocalAI.git
synced 2026-09-29 17:44:30 -04:00
applyFailoverWarmTargets ran on the manager's single scheduler goroutine (Sync -> Tick), so a slow or hung PreloadModelByName call froze probing and fail-back for every chain. Keep the watchdog pin synchronous but run the preload loop in its own goroutine. Adds a seam (preloadModelByName) so a unit test can substitute a blocking loader and assert the callback still returns promptly. Assisted-by: Claude:claude-opus-5-5 Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
33 lines
1.4 KiB
Go
33 lines
1.4 KiB
Go
package application
|
|
|
|
import (
|
|
"github.com/mudler/LocalAI/core/backend"
|
|
"github.com/mudler/xlog"
|
|
)
|
|
|
|
// preloadModelByName is a seam over backend.PreloadModelByName so tests can
|
|
// substitute a controllable loader instead of touching real models/disk.
|
|
var preloadModelByName = backend.PreloadModelByName
|
|
|
|
// applyFailoverWarmTargets pins warm failover targets in the watchdog and
|
|
// loads them, so a switch does not wait for a cold load.
|
|
//
|
|
// SyncPinnedModelsToWatchdog runs synchronously: it is a cheap in-memory
|
|
// update, and the pin must land before the watchdog can evict a target that
|
|
// is about to become (or stay) a chain's active path. Preloading is not
|
|
// cheap — it can download or load a multi-GB model — and this callback runs
|
|
// on the failover manager's single scheduler goroutine (Sync, called from
|
|
// Tick, called from Run), before that tick's probes fire. A slow or hung
|
|
// load here would freeze probing and fail-back for every chain, so it runs
|
|
// in its own goroutine instead of blocking the scheduler loop.
|
|
func (a *Application) applyFailoverWarmTargets(warm []string) {
|
|
a.SyncPinnedModelsToWatchdog()
|
|
go func() {
|
|
for _, name := range warm {
|
|
if _, err := preloadModelByName(a.ApplicationConfig().Context, a.ModelConfigLoader(), a.ModelLoader(), a.ApplicationConfig(), name); err != nil {
|
|
xlog.Warn("failover: could not preload warm target", "model", name, "error", err)
|
|
}
|
|
}
|
|
}()
|
|
}
|