Skip to content

fix(claude): back off a rate-limited usage endpoint and fade stale pills - #97

Merged
bernardopg merged 1 commit into
mainfrom
fix/claude-usage-backoff
Nov 5, 2026
Merged

bernardopg merged 1 commit into
mainfrom
fix/claude-usage-backoff

Conversation

@bernardopg

Copy link
Copy Markdown
Owner

Summary

Anthropic rate-limits api/oauth/usage per account, shared with Claude Code and any other tool polling it. After a 429 the adapter kept asking on every refresh of every widget instance (DMS builds one per bar screen, each with its own timer), and the 120 s cache that normally dedupes them is never refreshed while requests fail. The bar meanwhile showed the old snapshot at full colour, so a window that had reset since read 0% against claude.ai's 16%.

  • Backoff (providers/get-claude-usage): HTTP 429 and 5xx record claude-usage-backoff.json in the account cache, under the account flock every run already takes. Delay: one cache TTL (120 s), doubled per consecutive failure up to 30 min, or the response's Retry-After (seconds or HTTP date) when longer, capped at 1 h. No usage or credits request is sent until it ends; the last good snapshot is served with its own fetch time. A network failure (HTTP 000) starts none, a deadline beyond the cap (clock moved back) is ignored, a corrupt file is ignored, a 200 removes it.
  • Schema: while a backoff holds the item carries usage.retryAt (ISO) and usage.retryReason (rate_limited / server_error). Without a snapshot the error message names the next attempt.
  • Bar: the pill fades a provider's percentage once its numbers are older than two refresh intervals (same rule as the card's Stale badge, now one providerIsStale() helper); the tooltip adds stale since HH:MM:SS and the next try.
  • Card: the Updated line adds Rate limited · next try HH:MM / Endpoint failing · next try HH:MM.
  • Strings in all five locales; docs in architecture.md, usage.md, troubleshooting.md; CHANGELOG.md Unreleased.

Related issues

Closes #96

Type of change

  • Bug fix
  • Enhancement

Checklist

  • plugin.json .version and CHANGELOG.md are consistent (no release in this PR)
  • New/changed provider scripts are executable and emit valid JSON
  • i18n/en.json keys have translations in every locale
  • Every commit is signed off (git commit -s) under the DCO
  • CI is green

Local: every tests/test-*.sh passes (including test-widget-runtime.sh against the running DMS, with a new stale/backoff step), check-metadata, check-changelog, check-dco, shellcheck -S warning, qmllint, git diff --check. Local kcov 43 reads 94.12% because of its known line-tracking bug in the Hermes/OpenCode SQL files; get-claude-usage is at 96.7% with every new statement covered, and CI builds the pinned kcov.

Anthropic rate-limits the OAuth usage endpoint per account, and the
limit is shared with Claude Code and any other tool polling it. After a
429 the adapter kept asking on every refresh of every widget instance:
DMS builds one per bar screen, each with its own timer, and the 120 s
cache that normally dedupes them is never refreshed while requests
fail. The bar meanwhile showed the old snapshot at full colour, so a
window that had reset since read 0% against claude.ai's 16% (#96).

HTTP 429 and 5xx now record a backoff in the account cache, under the
account lock every run already takes: one cache TTL, doubled per
consecutive failure up to 30 minutes, or the server's Retry-After when
longer (capped at an hour). No usage or credits request is sent until
it ends; the last good snapshot is served with its own fetch time, and
the item carries usage.retryAt and usage.retryReason so the card can
name the next try. A network failure starts no backoff, and a deadline
beyond the cap (clock moved back) is ignored.

The DankBar pill fades a provider's percentage once its numbers are
older than two refresh intervals, the same rule the card's Stale badge
uses, and the tooltip adds since when and the next try.

Signed-off-by: Bernardo Pinto Gomes <[email protected]>
@github-actions github-actions Bot added documentation Improvements or additions to documentation area:providers Provider adapters (providers/) area:i18n Translations (i18n/) area:qml QML UI code area:ci CI, workflows, tooling labels Nov 5, 2026
@bernardopg
bernardopg merged commit 36dbbbf into main Nov 5, 2026
21 checks passed
@bernardopg
bernardopg deleted the fix/claude-usage-backoff branch November 5, 2026 01:47
@bernardopg bernardopg mentioned this pull request Nov 5, 2026
4 of 5 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:ci CI, workflows, tooling area:i18n Translations (i18n/) area:providers Provider adapters (providers/) area:qml QML UI code documentation Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Inaccurate Session usage data for Claude in v2.2.1

1 participant