• JIA-ss's avatar
    fix(usage): add negative caching, singleflight, and jitter to usage queries · 3ebebef9
    JIA-ss authored
    
    
    Prevents 429 rate-limit retry storms and reduces upstream correlation risk
    for Anthropic usage API queries.
    
    Three changes:
    1. Negative caching (1 min TTL) — 429/error responses are now cached,
       preventing every subsequent page load from re-triggering failed API calls.
    2. singleflight dedup — concurrent requests for the same account are
       collapsed into a single upstream call, preventing cache stampede.
    3. Random jitter (0–800 ms) — staggers multi-account cache-miss bursts so
       requests from different accounts don't hit upstream simultaneously with
       identical TLS fingerprints, reducing anti-abuse correlation risk.
    Co-Authored-By: default avatarClaude Opus 4.6 <noreply@anthropic.com>
    3ebebef9
account_usage_service.go 28.8 KB