Skip to content

fix(resets): confirm a reset with one limits read a few seconds later - #173

Merged
rexdotsh merged 1 commit into
mainfrom
fix/refresh-after-reset
Oct 22, 2026
Merged

rexdotsh merged 1 commit into
mainfrom
fix/refresh-after-reset

Conversation

@rexdotsh

@rexdotsh rexdotsh commented Oct 22, 2026 •

Copy link
Copy Markdown
Owner

Stack 1/4 · resets UX redo. Server only.

Problem

After a Claude claim, the admin kept showing the old limits until the next scheduled usage poll, up to ~3 minutes later (#139/#143 dropped the extra reads to Anthropic's rate-limited /api/oauth/usage). Codex re-read its limits right away, but that read can still be stale.

Change

Kleis only ever shows limits the upstream reported, so nothing is updated optimistically. Instead, a real reset gets one confirming read a few seconds later.

Result Upstream reads
Claude reset (confirmed) One GET /api/oauth/usage about 5s later; offer invalidated as before
Codex reset, already_redeemed Existing immediate reload, plus one confirming reload about 5s later
Codex no_credit, errors, refusals Existing immediate reload only
Codex nothing_to_reset, Claude not_limited None; cached limits and resets are kept, since nothing changed
Other Claude results, unconfirmed claims, errors, refusals None; the next scheduled poll shows it

Confirming read rules. It goes through the existing loader, so it's single-flight and the shared Claude 429 pause applies (no request while paused). It's skipped if another lookup started after the reset or is still running, including an invalidated one, so it never overlaps a request. It never retries or loops. Polling cadence and backoff are unchanged.

Extra calls per reset: Claude, 1 /api/oauth/usage. Codex, 1 confirming reload: wham/usage + rate-limit-reset-credits + profiles/me (+ accounts/check only when the daily profile check is due). None for a result that changed nothing.

Tests

Failing first, through claimClaudeReset / redeemCodexResetCredit and the tracking cache, with mocked fetch, an in-memory DB, and a captured setTimeout on the fake clock:

  • both providers: exactly one confirming read, after about 5s and not before, and nothing more 10 minutes later
  • table: skipped during the 429 pause, when a poll ran since, or while an earlier poll is still running
  • both providers: no confirming read after a refused (422) or unanswered (503) spend
  • both providers: a "nothing needed a reset" answer reads nothing and keeps the shown limits and resets

bun lint, bun typecheck, bun run build pass. bun test: 312 pass, 6 skip, 0 fail. --randomize also passes.

A real reset on either provider gets one confirming limits read about 5s later, skipped when another lookup started since or is still running; Claude's shared 429 pause still applies. Kleis only ever shows limits the upstream reported. An answer that nothing needed a reset keeps the cached data and reads nothing.
@rexdotsh
rexdotsh force-pushed the fix/refresh-after-reset branch from 13f10f4 to 2bd67a6 Compare October 22, 2026 13:32
@rexdotsh rexdotsh changed the title fix(resets): show a reset's effect at once and confirm it with one read fix(resets): confirm a reset with one limits read a few seconds later Oct 22, 2026
@rexdotsh
rexdotsh merged commit baf5f31 into main Oct 22, 2026
5 checks passed
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.

1 participant