Skip to content

Commit 313094b

Browse files
committed
fix(models): Fix GGUF models not appearing in picker after download
**Problem:** Downloaded GGUF models via Model Manager did not appear in picker until SAM restart. User had to manually restart to see newly downloaded models. **Root Cause:** When downloading via ModelDownloadManager: 1. Model file downloaded and registered in registry (line 406) 2. refreshInstalledModels() called → scanForModels() (line 420) 3. scanForModels() called syncWithRegistry() to detect changes 4. syncWithRegistry() returned FALSE (model already registered in step 1!) 5. Because registryChanges=false, notifications NEVER posted 6. EndpointManager never reloaded, ModelListManager never refreshed 7. Model invisible until restart (when scanForModels runs on init) **Solution:** Track actual model list changes in scanForModels(): - Capture model paths before scan (previousModelPaths) - Capture model paths after scan (currentModelPaths) - Post notifications if EITHER registry changed OR model paths chang- Post notifications if EITHER registry changed OR model paths chang- Post notifications if EITHe build-debug co- Post notifications if EITHER registry changed OR model paths chang- Post notificate- Post notifications if EITHER registry changed OR model paact- Post notificed- Post notifications if EITHER registry cstart - Hot reload works as originally intended - Preserves regis- Preserves regis- Preserves regis- Preserves regis- Preserves r from Local Models redesign (20260108.1)
1 parent 9796f3f commit 313094b

1 file changed

Lines changed: 16 additions & 4 deletions

File tree

Sources/APIFramework/LocalModelManager.swift

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,9 @@ public class LocalModelManager {
168168
return
169169
}
170170

171+
/// Track previous model state to detect actual changes
172+
let previousModelPaths = Set(cachedModels.map { $0.path })
173+
171174
var scannedModels: [LocalModel] = []
172175

173176
do {
@@ -240,12 +243,21 @@ public class LocalModelManager {
240243
/// Sync with registry: register any new models found during scan.
241244
let registryChanges = syncWithRegistry()
242245

243-
/// Only post notifications if models actually changed (prevents notification loops)
244-
/// This enables hot-reloading when new models are downloaded without spamming
245-
if registryChanges {
246+
/// Detect if model list actually changed (new models added or models removed)
247+
let currentModelPaths = Set(cachedModels.map { $0.path })
248+
let modelsChanged = previousModelPaths != currentModelPaths
249+
250+
/// Post notifications if registry changed OR actual model list changed
251+
/// This fixes the bug where downloaded models were pre-registered, so registryChanges=false
252+
/// even though the actual model list changed (new model downloaded)
253+
if registryChanges || modelsChanged {
246254
NotificationCenter.default.post(name: .localModelsDidChange, object: self)
247255
NotificationCenter.default.post(name: .endpointManagerDidUpdateModels, object: self)
248-
modelLogger.info("Models changed - posted update notifications")
256+
if modelsChanged && !registryChanges {
257+
modelLogger.info("Model list changed (downloaded model) - posted update notifications")
258+
} else {
259+
modelLogger.info("Models changed - posted update notifications")
260+
}
249261
}
250262
} catch {
251263
modelLogger.error("Failed to scan models directory: \(error.localizedDescription)")

0 commit comments

Comments
 (0)