Repository navigation
fix: stop refetching usage every render on accounts without rate-limit windows - #434
Conversation
9759182 to
67a37ea
Compare
…t windows Co-Authored-By: Claude <noreply@anthropic.com>
67a37ea to
ac53174
Compare
|
@zachthedev If a user with an enterprise account logs out and logs back in with a personal account, will the usage ever refresh again if the enterprise sentinel is written? |
Good point, I can try with my setup. |
No. The sentinel only gates completeness ( During that window it serves the prior snapshot, which is the existing <=180s lag of a non-account-keyed cache, not something the sentinel introduces. #460 drops that 180s: it fingerprints the token into the cache and invalidates on mismatch. Orthogonal to this fix. |
…t windows (sirmalloc#434) Co-authored-by: Claude <noreply@anthropic.com>
Closes #343
Enterprise accounts have no 5-hour/7-day rate-limit windows, so the usage API returns
five_hour: nullandseven_day*: null(#343). Those buckets parse to utilization0with noresets_at, which leaves the cache permanently "incomplete" for any widget that requires a reset timestamp:fetchUsageDatathen bypasses the cache and hits the live API on every render. At a 15s refresh interval Anthropic starts answering 429 withRetry-After: 300, and the lock makes the usage/money widgets flicker[Rate limited]/[Timeout]indefinitely.Observed on a real Enterprise account: the API answers 200 with all windows null, the cache holds
{"sessionUsage":0,...}with no reset fields, and the lock sits at{"blockedUntil":...,"error":"rate-limited"}in a permanent refetch/backoff cycle.usage-fetch.tsresets_at, so refetching can never produce the timestampusage-fetch.test.tsNotes:
monthly_limit: nullcase; the two PRs touch the same function and either rebases trivially on the other.