Show Grok usage-limit reset coupons - #3188
Conversation
|
You have reached your Codex usage limits for security reviews. Please try again later. |
|
🦞👀 Pull request received. I will update this pull request when review starts. |
|
Codex review: needs changes before merge. Reviewed August 25, 2026, 1:33 PM ET / 17:33 UTC. ClawSweeper reviewWhat this changesThis PR adds a best-effort Grok request for unused usage-limit reset coupons and displays them beside weekly usage. Merge readinessKeep open: the supplied UI proof is sufficient, but four prior P2 cache and account-refresh defects remain in the refreshed head. Priority: P2 Review scores
Verification
Live VerificationCommand: Result: FAIL (failed) — execution before step 1 Assertions:
How this fits togetherCodexBar fetches Grok usage, publishes a primary snapshot to the menu and preferences views, and caches account-specific results. This change adds an optional authenticated coupon lookup whose result is applied later to the displayed snapshot. flowchart LR
A[Grok credential or cookie] --> B[Weekly usage fetch]
B --> C[Publish primary usage]
B --> D[Optional coupon lookup]
D --> E[Supplemental snapshot update]
E --> F[Menu and preferences display]
Before merge
Findings
Agent review detailsSecurityNone. Review metrics
Merge-risk optionsMaintainer options:
Copy recommended automerge instructionTechnical reviewBest possible solution: Share one in-flight lookup across refresh generations, treat only a successful empty response as authoritative, and apply its result to every affected account snapshot while removing obsolete detail rows. Do we have a high-confidence way to reproduce the issue? Yes—source-reproducible: seed a cached coupon, then return an empty result, a non-200 response, overlap two refreshes, or refresh multiple token accounts; each path has a direct state transition to inspect. Is this the best way to solve the issue? No. The best-effort design is appropriate, but the current cache and publication paths do not yet preserve correct coupon state across failures, refresh races, and stacked accounts. Full review comments:
Overall correctness: patch is incorrect AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against 0a1aa53598c9. LabelsLabel changes:
Label justifications:
EvidenceAcceptance criteria:
What I checked:
Likely related people:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (1 earlier review cycle)
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: dd39a4ac1d
ℹ️ About Codex in GitHub
Your team has set up Codex to 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 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
Weekly CLI-proxy credits omit SuperGrok reset tokens, so CodexBar never rendered an unused coupon even when grok.com listed one. Fetch remaining resets as a best-effort overlay and keep weekly usage if that call fails.
dd39a4a to
4583904
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 4583904361
ℹ️ About Codex in GitHub
Your team has set up Codex to 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 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| let resetCredits: GrokRateLimitResetCreditsSnapshot? = switch update { | ||
| case let .grokResetCredits(snapshot): snapshot | ||
| } | ||
| let updated = current.withGrokResetCredits(resetCredits) |
There was a problem hiding this comment.
Clear stale detail rows after the deferred refresh
When a previous cache entry contains a coupon but the deferred request confirms that no coupons remain, this updates only grokResetCredits to nil and leaves the cached Limit Reset Credits row in details. The Grok presentation then falls back to that row, so a redeemed coupon continues to appear until another full provider refresh rebuilds the details; remove or replace the matching detail row when applying the supplemental result.
Useful? React with 👍 / 👎.
| guard response.statusCode == 200 else { | ||
| return [] | ||
| } |
There was a problem hiding this comment.
Treat non-200 coupon responses as refresh failures
When the optional endpoint temporarily returns 401, 429, or 5xx, returning [] makes finishRefresh treat the response as an authoritative empty inventory and overwrite any still-valid cached coupons. Other transport and gRPC failures return nil specifically to retain the cache, so non-200 responses should follow that failure path rather than being indistinguishable from a successful response containing zero coupons.
Useful? React with 👍 / 👎.
| self.scheduleSupplementalUsageUpdate( | ||
| provider: provider, | ||
| result: result, | ||
| generation: generation, | ||
| accountID: account?.id) |
There was a problem hiding this comment.
Apply deferred coupons to every stacked account
With stacked Grok token accounts, refreshTokenAccounts fetches and publishes snapshots for every visible account, but only the selected result reaches this scheduling call. The supplemental tasks returned for all non-selected accounts are never consumed, so their cards omit coupons after a cold refresh and remain one refresh cycle behind; schedule each successful account result against its corresponding account snapshot rather than only the selected outcome.
Useful? React with 👍 / 👎.
| guard state.shouldRefresh else { | ||
| return GrokRemainingResetsLookupResult(tokens: state.tokens, snapshotTask: nil) |
There was a problem hiding this comment.
Let replacement refreshes join the in-flight coupon lookup
If another Grok refresh starts after the primary snapshot publishes but before its coupon request finishes, this branch returns the still-empty cache without a supplemental task. The older task's eventual update is rejected by the refresh-generation guard, while the newer snapshot has nothing waiting to apply the now-populated cache, so coupons remain absent until a third refresh; return a shareable handle to the in-flight lookup so the current generation can consume its result.
Useful? React with 👍 / 👎.
|
Addressed the review feedback in
Live proof from the packaged debug app against a real Grok account (account data and tokens redacted):
The weekly card remains available immediately; the reset-credit block then shows Validation: 47 affected tests across 7 suites pass, @clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. |

Summary
Limit Reset Creditsdetail row, and leave weekly usage intact if that extra call times out or returns nothingTests
CODEXBAR_SUPPRESS_TEST_KEYCHAIN_ACCESS=1 swift test --filter GrokRemainingResetsFetcherTestsCODEXBAR_SUPPRESS_TEST_KEYCHAIN_ACCESS=1 swift test --filter GrokMenuCardModelTestsCODEXBAR_SUPPRESS_TEST_KEYCHAIN_ACCESS=1 swift test --filter GrokCreditsProxyFetcherTestsswiftlint lint --stricton the Grok remaining-resets filesWhy this was missing
/v1/billing?format=creditsreports weekly SuperGrok usage only. grok.com's Использование panel reads unused reset coupons from a separate RPC:POST https://grok.com/prod_mc_billing.ConsumerUiSvc/GetRemainingResetsThat payload includes
token_idandvalidity_end. CodexBar never called it, so an unused coupon such as Доступен сброс / Истекает 12 сент. stayed invisible even when weekly usage was 29%.CodexBar does not redeem or modify reset tokens.