diff --git a/recommend.js b/recommend.js index cdf907d..8615dfa 100644 --- a/recommend.js +++ b/recommend.js @@ -50,7 +50,18 @@ async function getProviderData() { // Try fresh cache first (within 20 minutes from monitor.js runs) const cached = getCachedRun(20); if (cached && cached.providers) { - return { source: 'cache', providers: cached.providers }; + // Cache hit — but check if all chain members are invalid_key + // If so, probe fresh: invalid_key can be transient (API 401s during key rotation) + // vs. rejected/exhausted which are stable budget states worth caching + const chainProviders = PROVIDER_CHAIN + .map(name => cached.providers[name]) + .filter(Boolean); + const allInvalidOrMissing = chainProviders.length === 0 || + chainProviders.every(p => p.status === 'invalid_key' || p.status === 'error'); + if (!allInvalidOrMissing) { + return { source: 'cache', providers: cached.providers }; + } + // All invalid — fall through to fresh probe } // No cache — probe Teams providers directly (no full monitor run, targeted probes only)