From f4087694b14b317c94129fe778ceb9537e6d7c8d Mon Sep 17 00:00:00 2001 From: tombii Date: Wed, 1 Apr 2026 23:01:30 +0200 Subject: [PATCH] fix(model-sync): skip replace when auto-sync returns empty model list MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Prevent auto-sync from wiping manually-imported models when the upstream /models endpoint fails, times out, or returns an empty list. Added `allowEmpty` option (default false) to replaceCustomModels — callers that intentionally clear all models (DELETE ?all=true) pass `allowEmpty: true`. Co-Authored-By: Claude Sonnet 4.6 --- src/lib/db/models.ts | 6 ++++++ 1 file changed, 6 insertions(+) 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 );