Skip to content

fix: stop refetching usage every render on accounts without rate-limit windows - #434

Merged
sirmalloc merged 1 commit into
sirmalloc:mainfrom
zachthedev:fix-enterprise-window-refetch
Jun 17, 2026
Merged

sirmalloc merged 1 commit into
sirmalloc:mainfrom
zachthedev:fix-enterprise-window-refetch

Conversation

@zachthedev

@zachthedev zachthedev commented Jun 13, 2026 •

Copy link
Copy Markdown
Contributor

Closes #343

Enterprise accounts have no 5-hour/7-day rate-limit windows, so the usage API returns five_hour: null and seven_day*: null (#343). Those buckets parse to utilization 0 with no resets_at, which leaves the cache permanently "incomplete" for any widget that requires a reset timestamp: fetchUsageData then bypasses the cache and hits the live API on every render. At a 15s refresh interval Anthropic starts answering 429 with Retry-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.

Area Change
usage-fetch.ts a missing window reset field counts as satisfied once its paired utilization is cached: a null bucket parses to utilization 0 with no resets_at, so refetching can never produce the timestamp
usage-fetch.test.ts probe test with the Enterprise response shape: first run fetches once, a second probe 10s later is served entirely from cache (zero requests)

Notes:

@zachthedev
zachthedev force-pushed the fix-enterprise-window-refetch branch from 9759182 to 67a37ea Compare June 13, 2026 01:20
…t windows

Co-Authored-By: Claude <noreply@anthropic.com>
@zachthedev
zachthedev force-pushed the fix-enterprise-window-refetch branch from 67a37ea to ac53174 Compare June 15, 2026 17:36
@sirmalloc

Copy link
Copy Markdown
Owner

@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?

@zachthedev

Copy link
Copy Markdown
Contributor Author

@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.

@zachthedev

zachthedev commented Jun 16, 2026 •

Copy link
Copy Markdown
Contributor Author

@sirmalloc

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?

No. The sentinel only gates completeness (hasRequiredUsageField); the cache is served only when also fresh: cacheAge < CACHE_MAX_AGE (180s) && hasRequiredUsageFields(...), ANDed. This PR touches only the second term, so a stale cache still refetches. After enterprise->personal it refetches at the 180s mark with the new token and the real windows replace it; the sentinel is recomputed per call (not persisted).

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.

@sirmalloc
sirmalloc merged commit 2bb0cdf into sirmalloc:main Jun 17, 2026
3 checks passed
@zachthedev
zachthedev deleted the fix-enterprise-window-refetch branch August 5, 2026 23:14
tahodev pushed a commit to tahodev/ccstatusline that referenced this pull request Oct 20, 2026
…t windows (sirmalloc#434)

Co-authored-by: Claude <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Session usage not updating on Enterprise plan

2 participants