fix(routing): cache a bare-model lookup only under the version it was read at

A catalog write can land while the lookup awaits, and a concurrent lookup can
then move the cache to the new version before this one stores its result.
Store the providers only when the model-catalog version is still the one
captured before the query, so a pre-write answer is never kept under the
post-write version.
This commit is contained in:
serenity
2026-11-19 20:02:07 -03:00
committed by diegosouzapw
parent 22fa1077a1
commit b7e971ff97

View File

@@ -331,8 +331,12 @@ async function getActiveSyncedProvidersForModel(modelId: string) {
const providers = (await getActiveProvidersWithSyncedModel(modelId))
.map(resolveProviderAlias)
.filter((provider): provider is string => typeof provider === "string");
if (syncedProvidersCache.size >= SYNCED_PROVIDERS_CACHE_MAX) syncedProvidersCache.clear();
syncedProvidersCache.set(modelId, providers);
// A write can land while this lookup awaits the query; a concurrent lookup may then already
// have moved the map to the new version. Only cache a result read under the current version.
if (getModelCatalogCacheVersion() === version) {
if (syncedProvidersCache.size >= SYNCED_PROVIDERS_CACHE_MAX) syncedProvidersCache.clear();
syncedProvidersCache.set(modelId, providers);
}
return providers;
} catch {
return [];