Repository navigation
fix(claude): stop asking for refused usage credits on every refresh - #124
Conversation
A Team plan member gets HTTP 403 from the organization's
prepaid/credits endpoint. get-claude-usage only recorded a 200, so
every run asked again: each widget instance (one per monitor) and each
manual refresh, even while the usage request was served from its
120 s cache. That endpoint shares the account's rate limit with
/api/oauth/usage, which soon answered 429 with a one hour Retry-After.
Every credits answer is now recorded with its time, status and
organization:
- 403 or 404: not asked again for 24 hours, and no credits are shown.
- 429: starts the shared usage backoff, so both endpoints pause.
- any other failure (5xx, network, a 200 that is not a credits
object): retried after the usual 10 minutes, keeping the last good
balance.
Credits are not asked while a usage backoff holds, also when the usage
request itself came from the cache. A record for another organization,
a corrupt one or one stamped in the future is not trusted. Records
written before this change ({cached_at, data}) are still read.
Fixes #123
Signed-off-by: Bernardo Pinto Gomes <[email protected]>
PR Summary by QodoStop repeated Claude credits requests after access is refused
AI Description
Diagram
High-Level Assessment
Files changed (5)
|
Code Review by Qodo
1. Interrupted failures can erase credits
|
Review follow-up to #124: - The credits record is replaced with a rename (atomic_write), so a refresh killed mid-write keeps the last record and its balance; leftover temporary files are swept under the account lock. Failed reads rewrite the record since #124, which made an in-place write riskier than before. - A record written by 2.4.0 ({cached_at, data}) names no organization. It was taken as the current one, so after a switch inside its TTL the previous organization's balance could be shown. Such a record is now re-checked once and never shown. - A credits 429 starts the shared usage backoff but left USAGE_RETRY_AT/USAGE_RETRY_REASON empty, as did a run that served a fresh usage snapshot while a backoff held. The card now names the next try whenever the pause holds, as docs/architecture.md describes. Refs #123 Signed-off-by: Bernardo Pinto Gomes <[email protected]>
Claude Team accounts no longer ask for refused usage credits on every refresh (#123, #124, #125): a refusal is remembered for a day per organization, a credits 429 pauses the usage endpoint too, and the card names the next try. Signed-off-by: Bernardo Pinto Gomes <[email protected]>
Summary
On a Claude Team plan a non-admin member gets HTTP 403 from
GET /api/oauth/organizations/<org>/prepaid/credits.get-claude-usageonly wroteclaude-prepaid-cache.jsonon a 200, so the request was repeated on every run (each widget instance, each manual refresh), even while the usage request was served from its 120 s cache. That endpoint shares the account's rate limit with/api/oauth/usage, which then answered 429 with a one hourRetry-After(#123).Every credits answer is now recorded as
{checked_at, status, org, data}:PREPAID_UNAVAILABLE_TTL); no credits are shown.record_usage_backoff,Retry-Afterhonoured), so both endpoints pause.{cached_at, data}) are still read.Reproduced with a fake
curlanswering 403 onprepaid/credits: four runs made 4 credits requests before (1 usage request, from the cache) and 1 after; same for 404 and 500.Docs:
docs/provider-verification.md,docs/troubleshooting.md(Claude),CHANGELOG.mdUnreleased (Fixes, Thanks). No UI string changed, so no locale update.Related issues
Fixes #123. Refs #96.
Type of change
Checklist
plugin.json.versionandCHANGELOG.mdare consistent (no release in this PR)i18n/en.jsonkeys have translations in every localegit commit -s) under the DCOTests:
tests/test-limit-resets.shgains a Team-account section: a first refusal, the pre-change record format, 403 held for a day across instances and an expired usage cache, 404, organization switch, 500 and an HTML 200 keeping the last balance, corrupt/empty/future records, and a 429 on credits pausing the usage endpoint. Local: every non-QML suite,check-metadata,check-changelog --base origin/main,check-dco, shellcheck,git diff --check, and statement coverage 100.00% (2398/2398) with kcov built from the CI-pinned commit460cd988.