fix(providers): empty refresh must not resurface just-cleared synced models (#3181)

Empty refresh must not resurface just-cleared synced models (fixes the release-blocking provider-models-route test). Integrated into release/v3.8.10.
This commit is contained in:
Diego Rodrigues de Sa e Souza
2026-06-04 19:05:00 -03:00
committed by GitHub
parent 3ac40829c0
commit ee791000a2

View File

@@ -923,10 +923,52 @@ export async function GET(
});
}
const fallback = buildLocalCatalogResponse(
"No remote models discovered — using local catalog"
);
if (fallback) return fallback;
// Empty discovery just cleared THIS connection's synced cache (via
// persistDiscoveredModels([])). `providerSyncedModels` was read at the top
// of the handler and is now stale, so it must not leak the just-cleared
// models back into the response (#3148 made synced authoritative for the
// normal path; here we re-read the current state instead). Re-derive the
// local catalog from the provider's remaining synced models (union across
// its other connections) or the static catalog when none remain.
let freshSynced: Awaited<ReturnType<typeof getSyncedAvailableModels>> = [];
try {
freshSynced = await getSyncedAvailableModels(provider);
} catch {
/* DB unavailable — fall through to static catalog */
}
const freshRegistry = freshSynced.length
? freshSynced.map((m) => ({
id: m.id,
name: m.name || m.id,
...(m.apiFormat ? { apiFormat: m.apiFormat } : {}),
...(m.supportedEndpoints ? { supportedEndpoints: m.supportedEndpoints } : {}),
}))
: getModelsByProviderId(provider) || [];
const freshSpecialty = freshSynced.length ? [] : getStaticModelsForProvider(provider) || [];
const freshLocal = mergeLocalCatalogModels(freshRegistry, freshSpecialty).map((model) => ({
id: model.id,
name: model.name || model.id,
...((model as Record<string, unknown>).apiFormat
? { apiFormat: (model as Record<string, unknown>).apiFormat as string | undefined }
: {}),
...((model as Record<string, unknown>).supportedEndpoints
? {
supportedEndpoints: (model as Record<string, unknown>).supportedEndpoints as
| string[]
| undefined,
}
: {}),
...(freshRegistry.length > 0 ? { owned_by: provider } : {}),
}));
if (freshLocal.length > 0) {
return buildResponse({
provider,
connectionId,
models: freshLocal,
source: "local_catalog",
warning: "No remote models discovered — using local catalog",
});
}
return buildResponse({
provider,