Cache reset times in-memory to preserve pace/deficit/reserve display#427
Cache reset times in-memory to preserve pace/deficit/reserve display#427Whoaa512 wants to merge 1 commit intosteipete:mainfrom
Conversation
7e2b719 to
6ff5903
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 6ff5903406
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
6ff5903 to
55f4351
Compare
When a fetch returns nil resetsAt (e.g. non-cookie auth path), backfill from a dedicated in-memory cache if the cached reset time hasn't expired. - Identity-aware: skips backfill when account email changes - Applied in both main refresh and token-account refresh paths - Cache cleared on credential changes and provider disable - 8 new tests covering backfill, expiry, account switch scenarios
55f4351 to
629f306
Compare
| return RateWindow( | ||
| usedPercent: self.usedPercent, | ||
| windowMinutes: self.windowMinutes ?? cached?.windowMinutes, | ||
| resetsAt: cachedReset, |
There was a problem hiding this comment.
Could we ensure this reconstructed RateWindow preserves the existing metadata from the fresh window? In particular, providers that expose rolling regeneration details may already populate additional fields that should remain intact after backfilling the reset time.
| bs?.resetsAt == self.secondary?.resetsAt, | ||
| bt?.resetsAt == self.tertiary?.resetsAt | ||
| { return self } | ||
| return UsageSnapshot( |
There was a problem hiding this comment.
Could we ensure this copy path preserves the full UsageSnapshot payload? Claude snapshots may include extraRateWindows, and it looks worth checking whether those are retained when reset-time backfill constructs a new snapshot.
|
Thanks @Whoaa512 — fixed this bug class on current I kept the reset-time backfill idea, but wired it against the current Closing this PR as superseded by the mainline fix. |
Problem
When Claude usage is fetched via a non-cookie auth path (e.g. OAuth),
resetsAtcan come back asnil. This causes the pace/deficit/reserve display to disappear until the next cookie-based fetch, which may prompt the user for keychain access.Fix
Add a dedicated in-memory reset time cache (
lastKnownResetTimes) onUsageStore, separate from the snapshots dict (which gets cleared on fetch failures and provider disable).When a fresh fetch returns
nilforresetsAt:windowMinutesandresetDescriptionwhen missingChanges
RateWindow.backfillingResetTime(from:)— backfill a single rate windowUsageSnapshot.backfillingResetTimes(from:)— backfill primary/secondary/tertiary with identity checkUsageStore.lastKnownResetTimes— dedicated cache dict that survives snapshot clearsUsageStore+Refresh.swift— apply backfill in main refresh path; clear cache on credential changes and provider disableUsageStore+TokenAccounts.swift— apply backfill in token-account refresh pathTesting
swift build✅swift test— all 803+ tests pass ✅ResetTimeBackfillTests— 8/8 pass ✅Related: #232, #84