[codex] Fix usage-limit reset copy and state (#28793)

## Why

The reset flow introduced in #28154 still describes earned reset credits
as "rate-limit resets" and uses generic reset-scope copy. It can also
retain a stale available-credit count after redemption or an account
change, leaving the reset action enabled after the last credit is used.

This follow-up updates terminology only within that reset feature.
Existing rate-limit wording elsewhere in the CLI and TUI is unchanged.

## What changed

- Rename reset-specific `/usage` menu items, startup hints, and reset
dialogs to "usage limit reset."
- Describe monthly resets for Free, Go, and accounts that report a
monthly usage window; otherwise describe the current 5-hour and weekly
limits.
- Recheck a cached zero balance when `/usage` is reopened, and refresh
the balance after redemption so the final reset immediately disables the
action.
- Correlate async refresh results before updating snapshots and clear
account-derived reset state, warnings, prompts, and status surfaces when
the account changes.

## Validation

- `just test -p codex-tui chatwidget::tests::usage` — 29 passed.
- `just test -p codex-tui chatwidget::tests::status_command_tests` — 7
passed.
- Account-boundary prompt and plan-mode prompt regression tests passed.
- `cargo insta pending-snapshots` from `codex-rs/tui` — no pending
snapshots.\

<img width="814" height="318" alt="image"
src="https://github.com/user-attachments/assets/2a460e96-458b-4805-8d9f-c759382d21a4"
/>
view for monthly
<img width="905" height="243" alt="image"
src="https://github.com/user-attachments/assets/179f88e3-08fb-4af5-8dc6-ce6a944ed681"
/>
This commit is contained in:
jay authored and GitHub committed 2026-06-22 18:45:41 +00:00
1 parent 20431d49a0
commit 5c0fbf3492
20 files changed
+496 -112

No files matched your search

+3 -21
View File
@@ -19,7 +19,6 @@ use codex_app_server_protocol::MarketplaceRemoveResponse;
use codex_app_server_protocol::MarketplaceUpgradeParams;
use codex_app_server_protocol::MarketplaceUpgradeResponse;
use codex_app_server_protocol::RateLimitResetCreditsSummary;
use codex_app_server_protocol::RequestId;
use crate::hooks_rpc::fetch_hooks_list;
@@ -90,7 +89,8 @@ impl App {
.and_then(|result| result.map_err(|err| err.to_string()))
}
RateLimitRefreshOrigin::StartupPrefetch { .. }
| RateLimitRefreshOrigin::StatusCommand { .. } => {
| RateLimitRefreshOrigin::StatusCommand { .. }
| RateLimitRefreshOrigin::UsageMenu { .. } => {
request.await.map_err(|err| err.to_string())
}
};
@@ -127,7 +127,7 @@ impl App {
tokio::spawn(async move {
let result = tokio::time::timeout(
RATE_LIMIT_RESET_REQUEST_TIMEOUT,
fetch_rate_limit_reset_credits(request_handle),
fetch_account_rate_limits(request_handle),
)
.await
.map_err(|_| "account/rateLimits/read timed out in TUI".to_string())
@@ -789,24 +789,6 @@ pub(super) async fn fetch_account_token_activity(
.wrap_err("account/usage/read failed in TUI")
}
pub(super) async fn fetch_rate_limit_reset_credits(
request_handle: AppServerRequestHandle,
) -> Result<RateLimitResetCreditsSummary> {
let request_id = RequestId::String(format!("account-rate-limit-resets-{}", Uuid::new_v4()));
let response: GetAccountRateLimitsResponse = request_handle
.request_typed(ClientRequest::GetAccountRateLimits {
request_id,
params: None,
})
.await
.wrap_err("account/rateLimits/read failed in TUI")?;
response.rate_limit_reset_credits.ok_or_else(|| {
color_eyre::eyre::eyre!(
"account/rateLimits/read response did not include rateLimitResetCredits"
)
})
}
pub(super) async fn consume_rate_limit_reset_credit_request(
request_handle: AppServerRequestHandle,
idempotency_key: String,
+47 -12
View File
@@ -758,15 +758,14 @@ impl App {
AppEvent::RateLimitsLoaded { origin, result } => match result {
Ok(response) => {
let rate_limit_reset_credits = response.rate_limit_reset_credits.clone();
for snapshot in app_server_rate_limit_snapshots(response) {
self.chat_widget.on_rate_limit_snapshot(Some(snapshot));
}
let snapshots = app_server_rate_limit_snapshots(response);
match origin {
RateLimitRefreshOrigin::StartupPrefetch {
reset_hint_request_id,
} => {
if self.chat_widget.finish_rate_limit_reset_hint_refresh(
reset_hint_request_id,
snapshots,
rate_limit_reset_credits.ok_or_else(|| {
"account/rateLimits/read response did not include rateLimitResetCredits"
.to_string()
@@ -779,6 +778,7 @@ impl App {
RateLimitRefreshOrigin::ResetConsume { request_id } => {
self.chat_widget.finish_post_consume_reset_credits_refresh(
request_id,
snapshots,
rate_limit_reset_credits.ok_or_else(|| {
"account/rateLimits/read response did not include rateLimitResetCredits"
.to_string()
@@ -788,7 +788,17 @@ impl App {
}
RateLimitRefreshOrigin::StatusCommand { request_id } => {
self.chat_widget
.finish_status_rate_limit_refresh(request_id);
.finish_status_rate_limit_refresh(request_id, snapshots);
}
RateLimitRefreshOrigin::UsageMenu { request_id } => {
self.chat_widget.finish_usage_menu_rate_limit_refresh(
request_id,
snapshots,
rate_limit_reset_credits.ok_or_else(|| {
"account/rateLimits/read response did not include rateLimitResetCredits"
.to_string()
}),
);
}
}
}
@@ -800,16 +810,27 @@ impl App {
} => {
self.chat_widget.finish_rate_limit_reset_hint_refresh(
reset_hint_request_id,
Vec::new(),
Err(err),
);
}
RateLimitRefreshOrigin::ResetConsume { request_id } => {
self.chat_widget
.finish_post_consume_reset_credits_refresh(request_id, Err(err));
self.chat_widget.finish_post_consume_reset_credits_refresh(
request_id,
Vec::new(),
Err(err),
);
}
RateLimitRefreshOrigin::StatusCommand { request_id } => {
self.chat_widget
.finish_status_rate_limit_refresh(request_id);
.finish_status_rate_limit_refresh(request_id, Vec::new());
}
RateLimitRefreshOrigin::UsageMenu { request_id } => {
self.chat_widget.finish_usage_menu_rate_limit_refresh(
request_id,
Vec::new(),
Err(err),
);
}
}
}
@@ -822,15 +843,29 @@ impl App {
let request_id = self.chat_widget.show_rate_limit_reset_loading_popup();
self.refresh_rate_limit_reset_credits(app_server, request_id);
}
AppEvent::RateLimitResetCreditsLoaded { request_id, result } => {
if let Err(err) = &result {
AppEvent::RateLimitResetCreditsLoaded { request_id, result } => match result {
Ok(response) => {
let rate_limit_reset_credits = response.rate_limit_reset_credits.clone();
self.chat_widget.finish_rate_limit_reset_credits_refresh(
request_id,
app_server_rate_limit_snapshots(response),
rate_limit_reset_credits.ok_or_else(|| {
"account/rateLimits/read response did not include rateLimitResetCredits"
.to_string()
}),
);
}
Err(err) => {
tracing::warn!(
"account/rateLimits/read failed during reset-credit refresh: {err}"
);
self.chat_widget.finish_rate_limit_reset_credits_refresh(
request_id,
Vec::new(),
Err(err),
);
}
self.chat_widget
.finish_rate_limit_reset_credits_refresh(request_id, result);
}
},
AppEvent::ConsumeRateLimitResetCredit { idempotency_key } => {
let request_id = self.chat_widget.show_rate_limit_reset_consuming_popup();
self.consume_rate_limit_reset_credit(app_server, request_id, idempotency_key);