Repository navigation
feat(resets): refuse a Codex credit when cached limits show nothing to reset - #174
Merged
Merged
Conversation
rexdotsh
added this pull request to stack #177
October 22, 2026 12:45
…o reset Codex only spends a reset credit when a limit is hit and otherwise answers nothing_to_reset. With limits read in the last 10 minutes that show every limit clear, the spend gets a 409 and nothing is sent; anything unknown or older is left to Codex. The admin accounts views report the same state as codexResets.unavailable = requires_limit.
Traffic refreshes some windows and the quota's fetchedAt, while the limit flags stay as last polled. The guard now needs the usage endpoint's last full read to be under 10 minutes old, so steady traffic can't keep refusing a usable credit.
rexdotsh
force-pushed
the
feat/codex-reset-guard
branch
from
October 22, 2026 13:32
795971d to
879900b
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.
Stack 2/4 · resets UX redo. Server only.
Problem
An owner kept using a Codex credit on an account at 6% (5h) and 12% (7d), with
limitReached: false. Every consume answered{"code":"nothing_to_reset","windowsReset":0}. Codex only spends a credit when a limit is hit.When a Codex credit is usable
In
openai/codex(94350a9), whether a credit can be used is decided only on the server:available_count > 0and never checks the limits first (codex-rs/tui/src/chatwidget/usage.rs:33-41,:137-139).NothingToResetmeans "No current rate-limit window is eligible for a reset" (codex-rs/app-server-protocol/src/protocol/v2/account.rs:426-427; codes incodex-rs/backend-client/src/types.rs:104-118, mapped incodex-rs/app-server/src/request_processors/account_processor/rate_limit_resets.rs:81-94). The TUI then says "Your usage does not need a reset right now." (usage.rs:380-381).So the rule comes only from
nothing_to_reset. Kleis uses the most conservative reading of the data it caches: nothing to reset only when the usage endpoint's last full read is under 10 minutes old and showsrate_limit_reached_typenull, and the main limit and every additional limit haveallowednot false,limit_reachedexactlyfalse, and every window under 100% (or past its reset). Anything unknown or older (a nulllimit_reached, a missing window percent, an old full read) leaves the decision to Codex. Freshness comes fromstatusObservedAt, which only the full poll sets. Traffic updates some windows and the quota'sfetchedAt, so it can't make old limit flags count as fresh, and steady traffic can't keep refusing a usable credit. A window that traffic reports at 100% still lets the spend through.Change
redeemCodexResetCreditrefuses with 409 before anything is sent: "Nothing to reset yet: Codex only uses a credit once you hit a limit. No credit was spent." It uses cached data only, with no new upstream calls, so a stale UI can't keep calling consume./admin/accountsand/admin/accounts/quotasreport the same check ascodexResets: { unavailable: "requires_limit" | null }, using the same reason code as Claude. The UI uses it in feat(admin): one reset model for Codex and Claude, with honest results #175.READ_MAX_AGE_MS).Tests
Failing first, through
redeemCodexResetCreditwith mockedwham/usageand an in-memory DB:limit_reachedis unknown, or when the limits are over 10 minutes old (each row fails against a guard that skips that check)bun lint,bun typecheck,bun run buildpass.bun test: 318 pass, 12 skip, 0 fail.--randomizepasses (one run hit the known 5s flake in the isolated proxy scenarios, which also happens on main).