From 12f61daca46f1af2f90eabd56fd641b2ff26a2b7 Mon Sep 17 00:00:00 2001 From: erio Date: Sat, 7 Mar 2026 12:53:28 +0800 Subject: [PATCH] fix: increase usage query throttle to 1-2s random delay Widen the per-group delay between Anthropic usage API calls from 1-1.5s to 1-2s to avoid upstream 429 rate limiting when multiple accounts share the same proxy exit. Co-Authored-By: Claude Opus 4.6 --- frontend/src/utils/__tests__/usageLoadQueue.spec.ts | 6 +++--- frontend/src/utils/usageLoadQueue.ts | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/frontend/src/utils/__tests__/usageLoadQueue.spec.ts b/frontend/src/utils/__tests__/usageLoadQueue.spec.ts index 24cebec836..c94070f443 100644 --- a/frontend/src/utils/__tests__/usageLoadQueue.spec.ts +++ b/frontend/src/utils/__tests__/usageLoadQueue.spec.ts @@ -20,11 +20,11 @@ describe('usageLoadQueue', () => { await Promise.all([p1, p2, p3]) expect(timestamps).toHaveLength(3) - // 随机 1-1.5s 间隔,至少 950ms(留一点误差) + // 随机 1-2s 间隔,至少 950ms(留一点误差) expect(timestamps[1] - timestamps[0]).toBeGreaterThanOrEqual(950) - expect(timestamps[1] - timestamps[0]).toBeLessThan(1600) + expect(timestamps[1] - timestamps[0]).toBeLessThan(2100) expect(timestamps[2] - timestamps[1]).toBeGreaterThanOrEqual(950) - expect(timestamps[2] - timestamps[1]).toBeLessThan(1600) + expect(timestamps[2] - timestamps[1]).toBeLessThan(2100) }) it('不同组请求并行执行', async () => { diff --git a/frontend/src/utils/usageLoadQueue.ts b/frontend/src/utils/usageLoadQueue.ts index 97549b15de..c329c97648 100644 --- a/frontend/src/utils/usageLoadQueue.ts +++ b/frontend/src/utils/usageLoadQueue.ts @@ -9,7 +9,7 @@ */ const GROUP_DELAY_MIN_MS = 1000 -const GROUP_DELAY_MAX_MS = 1500 +const GROUP_DELAY_MAX_MS = 2000 type Task = { fn: () => Promise @@ -37,7 +37,7 @@ async function drain(groupKey: string) { } catch (err) { task.reject(err) } - // Wait a random 1–1.5s before next request in the same group + // Wait a random 1–2s before next request in the same group if (queue.length > 0) { const jitter = GROUP_DELAY_MIN_MS + Math.random() * (GROUP_DELAY_MAX_MS - GROUP_DELAY_MIN_MS) await new Promise((r) => setTimeout(r, jitter))