Skip to content
8 changes: 8 additions & 0 deletions src/api/providers/virtual-quota-fallback.ts
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,14 @@ export class VirtualQuotaFallbackHandler implements ApiHandler {
// No valid handler found
if (this.activeProfileId) {
await this.notifyHandlerSwitch(undefined, "No Valid Provider")

// No valid handler found - reduce all cooldowns by 1 minute to gradually
// allow providers to become available again instead of blocking indefinitely
await Promise.all(
this.handlerConfigs.map((c) =>
this.usage.reduceCooldown(c.profileId, 1 * 60 * 1000)
)
);
}
this.activeHandler = undefined
this.activeProfileId = undefined
Expand Down
12 changes: 12 additions & 0 deletions src/utils/usage-tracker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,18 @@ export class UsageTracker {
await this.memento.update(COOLDOWNS_STORAGE_KEY, allCooldowns)
}

public async reduceCooldown(providerId: string, durationMs: number): Promise<void> {
const allCooldowns = await this.getPrunedCooldowns()
const currentCooldown = allCooldowns[providerId]

// Skip if provider has no active cooldown
if (!currentCooldown) return

allCooldowns[providerId] = currentCooldown - durationMs

await this.memento.update(COOLDOWNS_STORAGE_KEY, allCooldowns)
}

public async isUnderCooldown(providerId: string): Promise<boolean> {
const allCooldowns = await this.getPrunedCooldowns()
const cooldownUntil = allCooldowns[providerId]
Expand Down