diff --git a/src/cli.ts b/src/cli.ts index 381e452f1..e4aa77ace 100644 --- a/src/cli.ts +++ b/src/cli.ts @@ -755,9 +755,8 @@ if (cliFlags.listModels !== undefined) { "./resources/extensions/sf/key-manager.js" ); await refreshSfManagedProviders(process.cwd(), getKeyManagerAuthStorage()); - } catch (err) { + } catch { // Non-fatal — never block model listing. - process.stderr.write(`[model-catalog-cache] SF provider refresh error: ${err}\n`); } } diff --git a/src/resources/extensions/sf/model-catalog-cache.js b/src/resources/extensions/sf/model-catalog-cache.js index 3d9f8633d..eded11146 100644 --- a/src/resources/extensions/sf/model-catalog-cache.js +++ b/src/resources/extensions/sf/model-catalog-cache.js @@ -322,9 +322,7 @@ export async function refreshProviderCatalog(basePath, providerId, apiKey) { // kimi-coding, xiaomi, etc.). Without this, --list-models --discover // silently omits them because their SDK adapter has supportsDiscovery=false. if (!SDK_NATIVE_DISCOVERY_PROVIDERS.has(providerId)) { - process.stderr.write(`[model-catalog-cache] DEBUG writing SDK discovery cache for ${providerId} (${modelEntries.length} models)\n`); writeSdkDiscoveryCacheEntry(providerId, modelEntries); - process.stderr.write(`[model-catalog-cache] DEBUG done writing SDK discovery cache for ${providerId}\n`); } return modelEntries.map((e) => e.id); } catch { @@ -374,24 +372,28 @@ export function scheduleModelCatalogRefresh(basePath, auth) { * unnecessary network calls on repeated --discover invocations. */ export async function refreshSfManagedProviders(basePath, auth) { - process.stderr.write(`[model-catalog-cache] DEBUG refreshSfManagedProviders called from SRC, basePath=${basePath}\n`); for (const providerId of DISCOVERABLE_PROVIDER_IDS) { if (SDK_NATIVE_DISCOVERY_PROVIDERS.has(providerId)) continue; try { const creds = auth.getCredentialsForProvider(providerId); const apiKey = creds.find((c) => c.type === "api_key" && c.key)?.key; - process.stderr.write(`[model-catalog-cache] DEBUG ${providerId}: apiKey=${apiKey ? 'found' : 'MISSING'}\n`); if (!apiKey) continue; - const cached = readCachedModelIds(basePath, providerId); - process.stderr.write(`[model-catalog-cache] DEBUG ${providerId}: cached=${cached !== null ? cached.length + ' models' : 'null'}\n`); - if (cached !== null) continue; + const cachedIds = readCachedModelIds(basePath, providerId); + if (cachedIds !== null) { + // Runtime cache is fresh — no need to re-fetch. Still ensure the SDK + // discovery cache has an entry for this provider (e.g. after --discover + // deletes discovery-cache.json but the runtime cache survives). + writeSdkDiscoveryCacheEntry( + providerId, + cachedIds.map((id) => ({ id })), + ); + continue; + } const result = await refreshProviderCatalog(basePath, providerId, apiKey); if (result === null) { process.stderr.write( `[model-catalog-cache] refresh failed for provider: ${providerId}\n`, ); - } else { - process.stderr.write(`[model-catalog-cache] DEBUG ${providerId}: fetched ${result.length} models\n`); } } catch (err) { process.stderr.write(