Skip to content

feat(tui): add rate-limit reset redemption to /usage#28154

Merged
jayp-oai merged 13 commits into
mainfrom
codex/usage-rate-limit-resets
Jun 16, 2026
Merged

feat(tui): add rate-limit reset redemption to /usage#28154
jayp-oai merged 13 commits into
mainfrom
codex/usage-rate-limit-resets

Conversation

@jayp-oai

@jayp-oai jayp-oai commented Jun 14, 2026

Copy link
Copy Markdown
Collaborator

Why

Codex users can earn personal rate-limit reset credits, but the CLI does not currently provide a way to view or redeem them. The /usage command restored in #27925 is intended to be the entry point for usage-related actions, so reset redemption belongs there rather than in a separate dashed slash command.

This uses the app-server and backend-client reset-credit APIs landed in #28143.

What changed

  • Turn bare /usage into a menu with entries for token activity and earned rate-limit resets while preserving /usage daily, /usage weekly, and /usage cumulative.
  • Keep the reset entry actionable for personal accounts so selecting it refreshes snapshot-only availability; workspace-managed accounts remain disabled.
  • Add loading, empty, confirmation, success, retry, and error states with a caller-generated UUID idempotency key reused across retries of the same logical reset.
  • Prefetch reset availability at startup and show a non-blocking hint when personal reset credits are available.

Validation

  • just test -p codex-tui chatwidget::tests::usage — 25 passed.
  • cargo insta pending-snapshots from codex-rs/tui — no pending snapshots.

Examples

The current confirmation defaults to Cancel and does not label either action as the default.

image image

Reset flow

image image image image

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: df9d29d6db

ℹ️ 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".

Comment thread codex-rs/tui/src/chatwidget/usage.rs
Comment thread codex-rs/tui/src/chatwidget/usage.rs Outdated
@fcoury-oai

fcoury-oai commented Jun 15, 2026

Copy link
Copy Markdown
Contributor

I am still not convinced that /usage alone is the way to go from a TUI perspective.

How would the user learn he is entitled to a reset? Is there a way we can proactively indicate on start that the user has a reset credit and guide him to use /usage?

Also when the user don't have a reset credit, the menu seems superfluous:

CleanShot 2026-06-15 at 13 18 16@2x

Should we go straight to the token activity in this case?

@jayp-oai jayp-oai force-pushed the codex/usage-rate-limit-resets branch 5 times, most recently from a8c5a51 to 03c9c7e Compare June 15, 2026 18:59
jayp-oai added a commit that referenced this pull request Jun 15, 2026
## Why

Codex users can earn personal rate-limit reset credits, but app-server
clients do not currently have an API for reading or redeeming them. This
adds the backend and protocol foundation used by the `/usage` TUI flow
in #28154.

## What changed

- Extend `account/rateLimits/read` with a nullable
`rateLimitResetCredits` summary sourced from the existing usage
response.
- Add backend-client and app-server support for consuming a reset with a
caller-generated idempotency key. A UUID is recommended, and clients
reuse the same key when retrying the same logical reset.
- Return only the consume `outcome`; clients refetch
`account/rateLimits/read` for updated window state.
- Document the response field and each consume outcome, and regenerate
the JSON and TypeScript schema fixtures.
- Clarify in `AGENTS.md` that new app-server string enum values use
camelCase on the wire.
- Update the existing TUI response fixture for the expanded protocol
shape.
- Add coverage for authentication, response mapping, backend failures,
consume outcomes, and request timeout behavior.

## Validation

- `just test -p codex-app-server-protocol` — 231 passed.
- `just test -p codex-backend-client` — 14 passed.
- Focused `codex-app-server` reset-credit tests — 5 passed.
- Focused `codex-tui` protocol response fixture test — passed.
- `just fix -p codex-backend-client -p codex-app-server-protocol -p
codex-app-server` — passed.
- `just fmt` — passed.
Base automatically changed from codex/rate-limit-reset-app-server to main June 15, 2026 21:54
@jayp-oai jayp-oai force-pushed the codex/usage-rate-limit-resets branch from b5b2bf7 to b3e7cd4 Compare June 15, 2026 22:08
@jayp-oai jayp-oai enabled auto-merge (squash) June 15, 2026 23:47
@jayp-oai jayp-oai self-assigned this Jun 16, 2026

@fcoury-oai fcoury-oai left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Codex identified what looks like a real problem refreshing credits when user has none, check below.

Comment thread codex-rs/tui/src/chatwidget/usage.rs Outdated
SelectionItem {
name: "Redeem rate limit reset".to_string(),
description: Some(reset_description),
is_disabled: !reset_available,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P2] Re-check a cached zero reset balance

Could we avoid treating a cached zero balance as terminal? Reset credits are snapshot-only, so a user who earns one after startup remains locked out because /usage disables the only action that refetches the balance. Please refresh when /usage opens or keep the action enabled as "Check reset availability."

Found by Codex.

@fcoury-oai fcoury-oai left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested the happy path with no reset credits. Code looks good.

Approved 👍

@jayp-oai jayp-oai merged commit f8f5a6e into main Jun 16, 2026
31 checks passed
@jayp-oai jayp-oai deleted the codex/usage-rate-limit-resets branch June 16, 2026 17:59
@github-actions github-actions Bot locked and limited conversation to collaborators Jun 16, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants