Skip to content

fix(claude): keep the fetch time of a fallback usage snapshot - #90

Merged
bernardopg merged 1 commit into
mainfrom
fix/claude-stale-usage-snapshot
Oct 30, 2026
Merged

bernardopg merged 1 commit into
mainfrom
fix/claude-stale-usage-snapshot

Conversation

@bernardopg

Copy link
Copy Markdown
Owner

Summary

The Claude card could show an old weekly percentage as Live (#89: 79% in the card, 89% in Claude Code, same reset time).

Anthropic's /api/oauth/usage endpoint is rate-limited per account and often answers HTTP 429 (retry-after: 0), which reproduced locally. On a transient failure the adapter falls back to the last good snapshot, at any age, but native/claude.bash stamped it updatedAt: now. The widget's existing stale detection (two refresh intervals behind usage.updatedAt) therefore never fired, and the card kept the old numbers with a Live badge for as long as the endpoint kept failing. The reset countdown still looked right because resets_at is absolute.

  • get-claude-usage emits USAGE_UPDATED_AT: the time of a live fetch, or the snapshot's cached_at for a TTL cache hit or a fallback.
  • native/claude.bash uses it for usage.updatedAt, so a fallback card shows Stale and its real Updated time.
  • A window in the snapshot whose resets_at has already passed reads 0% with no reset time instead of its pre-reset value, so it no longer re-alerts after a rollover.

No QML or UI strings change; the badge and label already exist in all five locales.

Related issues

Closes #89

Type of change

  • New provider
  • Bug fix
  • Enhancement
  • Documentation / i18n
  • CI / tooling

Checklist

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

Tests: tests/test-cov-b-claude.sh serves an old snapshot through a 429 and asserts the original updatedAt, an untouched future window and a zeroed expired window, then a live fetch stamped now. It fails without the fix. Full tests/test-*.sh, shellcheck, check-metadata and check-changelog pass locally.

When the OAuth usage endpoint fails transiently (429 is common: it is
rate-limited per account), the adapter reuses the last good snapshot at
any age but stamped it with the current time. The card then read Live
while its percentages trailed Claude Code's (#89).

The snapshot now carries its cached_at as usage.updatedAt, so the
existing stale badge and "Updated" time apply, and a window whose reset
has passed since the snapshot reads 0% instead of its old value.

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:ci CI, workflows, tooling labels Oct 30, 2026
@bernardopg
bernardopg merged commit 4b89dec into main Oct 30, 2026
21 checks passed
@bernardopg
bernardopg deleted the fix/claude-stale-usage-snapshot branch October 30, 2026 20:19
@bernardopg bernardopg mentioned this pull request Oct 30, 2026
6 of 10 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:providers Provider adapters (providers/) documentation Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Wrong Claude weekly info

1 participant