- Updated markAccountUnavailable function to accept resetsAtMs for precise cooldown management.

- Added email backfill functionality for Codex OAuth connections to improve account information accuracy.
This commit is contained in:
decolua
2026-04-24 11:36:16 +07:00
parent fd8163e26e
commit 030fb34f88
15 changed files with 628 additions and 132 deletions

View File

@@ -149,7 +149,7 @@ async function handleSingleModelChat(body, modelStr, machineId, env) {
if (shouldFallback) {
log.warn("FALLBACK", `${provider.toUpperCase()} | ${credentials.id} | ${result.status}`);
await markAccountUnavailable(machineId, credentials.id, result.status, result.error, env);
await markAccountUnavailable(machineId, credentials.id, result.status, result.error, env, result.resetsAtMs);
excludeConnectionId = credentials.id;
lastError = result.error;
lastStatus = result.status;
@@ -244,13 +244,20 @@ async function getProviderCredentials(machineId, provider, env, excludeConnectio
};
}
async function markAccountUnavailable(machineId, connectionId, status, errorText, env) {
async function markAccountUnavailable(machineId, connectionId, status, errorText, env, resetsAtMs = null) {
const data = await getMachineData(machineId, env);
if (!data?.providers?.[connectionId]) return;
const conn = data.providers[connectionId];
const backoffLevel = conn.backoffLevel || 0;
const { cooldownMs, newBackoffLevel } = checkFallbackError(status, errorText, backoffLevel);
// Provider-specific precise cooldown (e.g. codex usage_limit_reached) overrides backoff
let cooldownMs, newBackoffLevel;
if (resetsAtMs && resetsAtMs > Date.now()) {
cooldownMs = resetsAtMs - Date.now();
newBackoffLevel = 0;
} else {
({ cooldownMs, newBackoffLevel } = checkFallbackError(status, errorText, backoffLevel));
}
const rateLimitedUntil = getUnavailableUntil(cooldownMs);
const reason = typeof errorText === "string" ? errorText.slice(0, 100) : "Provider error";