fix(usage): honor 429 Retry-After to stop self-sustaining rate-limit loop
The Claude usage poller retried /api/oauth/usage every 60s, but the endpoint returns 429 with a longer Retry-After window (~93s). Retrying mid-cooldown re-tripped the limit so the 429s never cleared and usage data never populated. Record a cooldownUntil from the 429 Retry-After header (5min fallback when absent) and skip the API until it closes; cleared on success. Dashboard now shows a "429" indicator instead of a stale value when rate-limited. Adds regression tests proving the cooldown outlasts the 60s throttle and releases once the window passes. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -7,6 +7,8 @@ export type UsageRow = {
|
||||
h5reset: string;
|
||||
d7pct: number;
|
||||
d7reset: string;
|
||||
/** When set, the renderer shows this text (e.g. "429") in place of the bars. */
|
||||
error?: string;
|
||||
};
|
||||
|
||||
export function formatResetRemaining(value: string | number): string {
|
||||
@@ -42,7 +44,11 @@ export function mergeClaudeDashboardAccounts(
|
||||
|
||||
return liveAccounts.map((account) => ({
|
||||
...account,
|
||||
usage: account.usage || cachedByIndex.get(account.index)?.usage || null,
|
||||
// On a 429 we deliberately do NOT fall back to the last cached value —
|
||||
// the dashboard surfaces a "429" indicator instead.
|
||||
usage: account.usageRateLimited
|
||||
? null
|
||||
: account.usage || cachedByIndex.get(account.index)?.usage || null,
|
||||
}));
|
||||
}
|
||||
|
||||
@@ -75,6 +81,7 @@ export function buildClaudeUsageRows(
|
||||
: Math.round(d7.utilization * 100)
|
||||
: -1,
|
||||
d7reset: d7 ? formatResetRemaining(d7.resets_at) : '',
|
||||
error: account.usageRateLimited ? '429' : undefined,
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user