fix: giảm spam 429 từ Claude OAuth usage endpoint

- claudeAutoPing: cache resetAt in-mem, bỏ qua poll usage cho tới gần reset
- ProviderLimits: throttle auto-refresh Claude 3 phút, nút bấm tay vẫn refresh ngay
- claude.js: 429 ở OAuth usage → cooldown 3 phút, fallback legacy (không ảnh hưởng chat)

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
decolua
2026-06-17 11:42:20 +07:00
co-authored by Cursor
parent da667836cc
commit 79df34cad7
4 changed files with 40 additions and 8 deletions
+8 -1
View File
@@ -12,7 +12,7 @@ import { CLAUDE_AUTOPING_CONFIG } from "@/shared/constants/config";
const C = CLAUDE_AUTOPING_CONFIG;
const PING_URL = "https://api.anthropic.com/v1/messages?beta=true";
const g = (global.__claudeAutoPing ??= { interval: null, running: false });
const g = (global.__claudeAutoPing ??= { interval: null, running: false, resetCache: {} });
function buildProxyOptions(cfg) {
return {
@@ -43,6 +43,10 @@ async function sendPing(accessToken, proxyOptions) {
}
async function pingConnection(conn) {
// Cached resetAt is stable for the whole 5h window; skip usage poll until near reset
const cachedReset = g.resetCache[conn.id];
if (cachedReset && Date.now() < new Date(cachedReset).getTime() - C.refreshAheadMs) return;
const proxyCfg = await resolveConnectionProxyConfig(conn.providerSpecificData);
const proxyOptions = buildProxyOptions(proxyCfg);
@@ -60,6 +64,9 @@ async function pingConnection(conn) {
const resetAt = usage?.quotas?.[C.fiveHourKey]?.resetAt;
if (!resetAt) return;
// Cache resetAt to gate future ticks
g.resetCache[conn.id] = resetAt;
const resetMs = new Date(resetAt).getTime();
const now = Date.now();