Repository navigation
fix(claude): keep the fetch time of a fallback usage snapshot - #90
Merged
Merged
Conversation
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]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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/usageendpoint 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, butnative/claude.bashstamped itupdatedAt: now. The widget's existing stale detection (two refresh intervals behindusage.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 becauseresets_atis absolute.get-claude-usageemitsUSAGE_UPDATED_AT: the time of a live fetch, or the snapshot'scached_atfor a TTL cache hit or a fallback.native/claude.bashuses it forusage.updatedAt, so a fallback card shows Stale and its real Updated time.resets_athas 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
Checklist
plugin.json.versionandCHANGELOG.mdare consistent (Unreleased bullet; the version bump ships in the release PR)i18n/en.jsonkeys have translations in every locale (or the strings are user-neutral)git commit -s) under the DCOTests:
tests/test-cov-b-claude.shserves an old snapshot through a 429 and asserts the originalupdatedAt, an untouched future window and a zeroed expired window, then a live fetch stamped now. It fails without the fix. Fulltests/test-*.sh, shellcheck,check-metadataandcheck-changelogpass locally.