@kenkaiiii/ggcoder 5.22.2 → 5.22.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -576,11 +576,14 @@ async function main() {
576
576
  });
577
577
  const usageCache = new Map();
578
578
  const usageRequests = new Map();
579
- // 429 backoff: when the provider rate-limits the usage endpoint, hold the
580
- // error result until this timestamp instead of re-polling (and re-logging a
581
- // WARN) every 60s the old cadence hammered a limited endpoint for hours.
579
+ // 429 backoff: quota endpoints are auxiliary UI data. Honor Retry-After when
580
+ // provided; otherwise retain the unavailable snapshot for 30 minutes. Clamp
581
+ // the provider value so a malformed header can neither hammer the endpoint
582
+ // nor suppress usage data forever.
582
583
  const usageRateLimitedUntil = new Map();
583
- const USAGE_RATE_LIMIT_BACKOFF_MS = 5 * 60_000;
584
+ const USAGE_RATE_LIMIT_FALLBACK_BACKOFF_MS = 30 * 60_000;
585
+ const USAGE_RATE_LIMIT_MIN_BACKOFF_MS = 60_000;
586
+ const USAGE_RATE_LIMIT_MAX_BACKOFF_MS = 24 * 60 * 60_000;
584
587
  async function fetchUsageProvider(provider) {
585
588
  const displayName = provider === "anthropic" ? "Anthropic" : provider === "openai" ? "Codex" : "Kimi";
586
589
  // Kimi plan usage is tracked on the OAuth credential specifically — the
@@ -619,10 +622,16 @@ async function main() {
619
622
  if (shouldCaptureUsagePollingError(error)) {
620
623
  captureSidecarError(error, "app-sidecar.usage.fetch", { provider });
621
624
  }
622
- log("WARN", "app-sidecar", "subscription usage fetch failed", { provider, message });
625
+ let backoffMs;
623
626
  if (error instanceof SubscriptionUsageError && error.status === 429) {
624
- usageRateLimitedUntil.set(provider, Date.now() + USAGE_RATE_LIMIT_BACKOFF_MS);
627
+ backoffMs = Math.min(USAGE_RATE_LIMIT_MAX_BACKOFF_MS, Math.max(USAGE_RATE_LIMIT_MIN_BACKOFF_MS, error.retryAfterMs ?? USAGE_RATE_LIMIT_FALLBACK_BACKOFF_MS));
628
+ usageRateLimitedUntil.set(provider, Date.now() + backoffMs);
625
629
  }
630
+ log("WARN", "app-sidecar", "subscription usage fetch failed", {
631
+ provider,
632
+ message,
633
+ ...(backoffMs !== undefined && { backoffMs: String(backoffMs) }),
634
+ });
626
635
  const connected = await auth.hasProviderAuth(authKey);
627
636
  return {
628
637
  provider,