Auth: bypass cooldown tracking for OpenRouter

This commit is contained in:
Vincent Koc
2026-02-24 18:45:29 -05:00
parent 31e6d18538
commit daa4f34ce8

View File

@@ -17,6 +17,10 @@ const FAILURE_REASON_ORDER = new Map<AuthProfileFailureReason, number>(
FAILURE_REASON_PRIORITY.map((reason, index) => [reason, index]), FAILURE_REASON_PRIORITY.map((reason, index) => [reason, index]),
); );
function isAuthCooldownBypassedForProvider(provider: string | undefined): boolean {
return normalizeProviderId(provider ?? "") === "openrouter";
}
export function resolveProfileUnusableUntil( export function resolveProfileUnusableUntil(
stats: Pick<ProfileUsageStats, "cooldownUntil" | "disabledUntil">, stats: Pick<ProfileUsageStats, "cooldownUntil" | "disabledUntil">,
): number | null { ): number | null {
@@ -33,6 +37,9 @@ export function resolveProfileUnusableUntil(
* Check if a profile is currently in cooldown (due to rate limiting or errors). * Check if a profile is currently in cooldown (due to rate limiting or errors).
*/ */
export function isProfileInCooldown(store: AuthProfileStore, profileId: string): boolean { export function isProfileInCooldown(store: AuthProfileStore, profileId: string): boolean {
if (isAuthCooldownBypassedForProvider(store.profiles[profileId]?.provider)) {
return false;
}
const stats = store.usageStats?.[profileId]; const stats = store.usageStats?.[profileId];
if (!stats) { if (!stats) {
return false; return false;
@@ -342,6 +349,9 @@ export function resolveProfileUnusableUntilForDisplay(
store: AuthProfileStore, store: AuthProfileStore,
profileId: string, profileId: string,
): number | null { ): number | null {
if (isAuthCooldownBypassedForProvider(store.profiles[profileId]?.provider)) {
return null;
}
const stats = store.usageStats?.[profileId]; const stats = store.usageStats?.[profileId];
if (!stats) { if (!stats) {
return null; return null;
@@ -425,11 +435,15 @@ export async function markAuthProfileFailure(params: {
agentDir?: string; agentDir?: string;
}): Promise<void> { }): Promise<void> {
const { store, profileId, reason, agentDir, cfg } = params; const { store, profileId, reason, agentDir, cfg } = params;
const profile = store.profiles[profileId];
if (!profile || isAuthCooldownBypassedForProvider(profile.provider)) {
return;
}
const updated = await updateAuthProfileStoreWithLock({ const updated = await updateAuthProfileStoreWithLock({
agentDir, agentDir,
updater: (freshStore) => { updater: (freshStore) => {
const profile = freshStore.profiles[profileId]; const profile = freshStore.profiles[profileId];
if (!profile) { if (!profile || isAuthCooldownBypassedForProvider(profile.provider)) {
return false; return false;
} }
freshStore.usageStats = freshStore.usageStats ?? {}; freshStore.usageStats = freshStore.usageStats ?? {};