From 8e17756bf86ff6aa7e4e38c68d0faa00c28706ba Mon Sep 17 00:00:00 2001 From: Chris Staley Date: Sun, 29 Mar 2026 14:23:25 -0600 Subject: [PATCH] fix: filter registry models from auto-sync to prevent duplicates The model sync scheduler and sync-models endpoint were blindly replacing custom models with all fetched models, including ones already in the built-in registry. Now filters out registry models before saving to custom models. --- .../(dashboard)/dashboard/providers/[id]/page.tsx | 13 ++++--------- src/app/api/providers/[id]/sync-models/route.ts | 8 +++++++- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/src/app/(dashboard)/dashboard/providers/[id]/page.tsx b/src/app/(dashboard)/dashboard/providers/[id]/page.tsx index 7a90775412..66488b657e 100644 --- a/src/app/(dashboard)/dashboard/providers/[id]/page.tsx +++ b/src/app/(dashboard)/dashboard/providers/[id]/page.tsx @@ -1460,14 +1460,6 @@ export default function ProviderDetailPage() { return; } - setImportProgress((prev) => ({ - ...prev, - phase: "importing", - total: fetchedModels.length, - status: t("importingModelsProgress", { current: 0, total: fetchedModels.length }), - logs: [t("foundModelsStartingImport", { count: fetchedModels.length })], - })); - const existingIds = new Set([ ...(modelMeta.customModels || []).map((m: any) => m.id), ...models.map((m: any) => m.id), @@ -1483,6 +1475,8 @@ export default function ProviderDetailPage() { status: t("allModelsAlreadyImported") || "All models already imported", logs: [t("noNewModelsToImport") || "No new models to import"], importedCount: 0, + total: 0, + current: 0, })); return; } @@ -1490,7 +1484,8 @@ export default function ProviderDetailPage() { setImportProgress((prev) => ({ ...prev, phase: "importing", - total: fetchedModels.length, + total: newModels.length, + current: 0, status: t("importingModelsProgress", { current: 0, total: newModels.length }), logs: [ t("foundModelsStartingImport", { count: newModels.length }), diff --git a/src/app/api/providers/[id]/sync-models/route.ts b/src/app/api/providers/[id]/sync-models/route.ts index c86fd1ad52..b9a4e9d4f5 100644 --- a/src/app/api/providers/[id]/sync-models/route.ts +++ b/src/app/api/providers/[id]/sync-models/route.ts @@ -7,6 +7,7 @@ import { buildModelSyncInternalHeaders, isModelSyncInternalRequest, } from "@/shared/services/modelSyncScheduler"; +import { getModelsByProviderId } from "@/shared/constants/models"; /** * POST /api/providers/[id]/sync-models @@ -75,6 +76,11 @@ export async function POST(request: Request, { params }: { params: Promise<{ id: const fetchedModels = modelsData.models || []; + // Filter out models already in the built-in registry + const registryIds = new Set( + getModelsByProviderId(connection.provider).map((m: any) => m.id) + ); + // Replace the full model list const models = fetchedModels .map((m: any) => ({ @@ -82,7 +88,7 @@ export async function POST(request: Request, { params }: { params: Promise<{ id: name: m.name || m.displayName || m.id || m.model, source: "auto-sync", })) - .filter((m: any) => m.id); + .filter((m: any) => m.id && !registryIds.has(m.id)); const replaced = await replaceCustomModels(connection.provider, models);