From 8ddf17c3581691e490dda24ae29680c52eb6583d Mon Sep 17 00:00:00 2001 From: ndycode Date: Mon, 23 Feb 2026 05:05:12 +0800 Subject: [PATCH] fix(auth): batch account hydration to prevent auth0 429 rate limits --- index.ts | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/index.ts b/index.ts index 010e150..db4709b 100644 --- a/index.ts +++ b/index.ts @@ -686,8 +686,12 @@ export const OpenAIOAuthPlugin: Plugin = async ({ client }: PluginInput) => { if (accountsToHydrate.length === 0) return storage; let changed = false; - await Promise.all( - accountsToHydrate.map(async (account) => { + // process in chunks of 3 to avoid auth0 rate limits (429) on startup + const chunkSize = 3; + for (let i = 0; i < accountsToHydrate.length; i += chunkSize) { + const chunk = accountsToHydrate.slice(i, i + chunkSize); + await Promise.all( + chunk.map(async (account) => { try { const refreshed = await queuedRefresh(account.refreshToken); if (refreshed.type !== "success") return; @@ -721,8 +725,9 @@ export const OpenAIOAuthPlugin: Plugin = async ({ client }: PluginInput) => { } catch { logWarn(`[${PLUGIN_NAME}] Failed to hydrate email for account`); } - }), + }) ); + } if (changed) { storage.accounts = accountsCopy;