diff --git a/src/lib/db/models.ts b/src/lib/db/models.ts index 74234a7f12..6f062af580 100644 --- a/src/lib/db/models.ts +++ b/src/lib/db/models.ts @@ -429,6 +429,12 @@ export async function replaceCustomModels( }); if (merged.length === 0) { + // Guard: skip destructive clear when the caller hasn't explicitly opted in. + // This prevents auto-sync from wiping manually-imported models when the + // upstream /models endpoint fails, times out, or returns an empty list. + if (!allowEmpty) { + return Array.isArray(existing) ? existing : []; + } db.prepare("DELETE FROM key_value WHERE namespace = 'customModels' AND key = ?").run( providerId );