Cache reset times in-memory to preserve pace/deficit/reserve display#427
Open
Whoaa512 wants to merge 1 commit intosteipete:mainfrom
Open
Cache reset times in-memory to preserve pace/deficit/reserve display#427Whoaa512 wants to merge 1 commit intosteipete:mainfrom
Whoaa512 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".
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
6ff5903 to
55f4351
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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