[codex-cli] Show reset details in redemption picker (#30488)

## Why

Users can see that usage-limit reset credits are available, but not
which credits they have, when each one expires, or which credit will be
consumed. The TUI should use the supported rate-limit RPC for that
information without maintaining a second reset-credit request path.

## What changed

- load reset-credit details through the existing
`account/rateLimits/read` refresh when the user opens **Redeem usage
limit reset**
- show available credits sorted by expiry, using the backend title when
present and a scope-based fallback otherwise
- consume the exact selected credit and preserve its idempotency key
across retries
- fall back to the existing generic reset action when the RPC returns a
positive count without detail rows
- remove the dedicated list-RPC event, request, response-combining, and
TUI state plumbing
- handle a selected credit becoming unavailable without incorrectly
caching the user's total count as zero
- handle forward-compatible unknown reset types with the existing
scope-based fallback label

## TUI preview

Rendered from the final standard-width and narrow `insta` snapshots in
this PR.

<img width="1280" height="570" alt="pr30488-reset-picker-preview"
src="https://github.com/user-attachments/assets/8b84cd33-cb35-4a37-aaed-dbd6b62bff51"
/>

## Validation

- `just test -p codex-tui chatwidget::tests::usage` (32 passed)
- `just fix -p codex-tui`
- no pending `insta` snapshots

Uses the reset-credit details added by #30395.

Fixes #29618.
This commit is contained in:
jay authored and GitHub committed 2026-07-06 21:19:50 -07:00
1 parent 6cf42cf165
commit d7ab20ce62
10 files changed
+526 -256

No files matched your search

+11 -22
View File
@@ -83,7 +83,8 @@ impl App {
tokio::spawn(async move {
let request = fetch_account_rate_limits(request_handle);
let result = match origin {
RateLimitRefreshOrigin::ResetConsume { .. } => {
RateLimitRefreshOrigin::ResetConsume { .. }
| RateLimitRefreshOrigin::ResetPicker { .. } => {
tokio::time::timeout(RATE_LIMIT_RESET_REQUEST_TIMEOUT, request)
.await
.map_err(|_| "account/rateLimits/read timed out in TUI".to_string())
@@ -118,37 +119,23 @@ impl App {
});
}
pub(super) fn refresh_rate_limit_reset_credits(
&mut self,
app_server: &AppServerSession,
request_id: u64,
) {
let request_handle = app_server.request_handle();
let app_event_tx = self.app_event_tx.clone();
tokio::spawn(async move {
let result = tokio::time::timeout(
RATE_LIMIT_RESET_REQUEST_TIMEOUT,
fetch_account_rate_limits(request_handle),
)
.await
.map_err(|_| "account/rateLimits/read timed out in TUI".to_string())
.and_then(|result| result.map_err(|err| err.to_string()));
app_event_tx.send(AppEvent::RateLimitResetCreditsLoaded { request_id, result });
});
}
pub(super) fn consume_rate_limit_reset_credit(
&mut self,
app_server: &AppServerSession,
request_id: u64,
idempotency_key: String,
credit_id: Option<String>,
) {
let request_handle = app_server.request_handle();
let app_event_tx = self.app_event_tx.clone();
tokio::spawn(async move {
let result = tokio::time::timeout(
RATE_LIMIT_RESET_REQUEST_TIMEOUT,
consume_rate_limit_reset_credit_request(request_handle, idempotency_key.clone()),
consume_rate_limit_reset_credit_request(
request_handle,
idempotency_key.clone(),
credit_id.clone(),
),
)
.await
.map_err(|_| "account/rateLimitResetCredit/consume timed out in TUI".to_string())
@@ -156,6 +143,7 @@ impl App {
app_event_tx.send(AppEvent::RateLimitResetCreditConsumed {
request_id,
idempotency_key,
credit_id,
result,
});
});
@@ -793,6 +781,7 @@ pub(super) async fn fetch_account_token_activity(
pub(super) async fn consume_rate_limit_reset_credit_request(
request_handle: AppServerRequestHandle,
idempotency_key: String,
credit_id: Option<String>,
) -> Result<ConsumeAccountRateLimitResetCreditResponse> {
let request_id = RequestId::String(format!("consume-rate-limit-reset-{}", Uuid::new_v4()));
request_handle
@@ -800,7 +789,7 @@ pub(super) async fn consume_rate_limit_reset_credit_request(
request_id,
params: ConsumeAccountRateLimitResetCreditParams {
idempotency_key,
credit_id: None,
credit_id,
},
})
.await