recommend.js: probe fresh when all cached providers are invalid_key
invalid_key (HTTP 401) can be transient during key rotation or temporary API issues — unlike rejected/exhausted which are stable budget states. When cache shows all chain providers as invalid_key, bypass cache and probe fresh so recovery is immediate instead of waiting for the 20-minute TTL to expire.
This commit is contained in:
parent
6e6d93f3bf
commit
ab35cc8346
1 changed files with 12 additions and 1 deletions
13
recommend.js
13
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)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue