-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[codex-cli] Confirm reset credit redemption #31329
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
jayp-oai
wants to merge
7
commits into
main
Choose a base branch
from
codex/reset-credit-confirmation
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
90dd95e
Show reset credits in redemption picker
jayp-oai 482a81d
Use backend reset credit titles
jayp-oai 1a7f90f
Simplify reset credit picker fallback
jayp-oai 8bb6baf
Use rate limits refresh for reset picker
jayp-oai 5527081
Handle unknown reset types in picker
jayp-oai d0a3d00
Confirm reset credit redemption
jayp-oai 4a82441
Rearm rejected reset confirmations
jayp-oai File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| use chrono::DateTime; | ||
| use chrono::Local; | ||
| use chrono::Utc; | ||
| use codex_app_server_protocol::RateLimitResetCreditStatus; | ||
| use codex_app_server_protocol::RateLimitResetCreditsSummary; | ||
|
|
||
| #[derive(Debug, Eq, PartialEq)] | ||
| pub(super) struct ResetCreditOption { | ||
| pub(super) credit_id: Option<String>, | ||
| pub(super) name: String, | ||
| pub(super) detail: Option<String>, | ||
| pub(super) description: String, | ||
| } | ||
|
|
||
| pub(super) fn reset_credit_options( | ||
| summary: &RateLimitResetCreditsSummary, | ||
| ) -> Vec<ResetCreditOption> { | ||
| let available_count = summary.available_count.max(0); | ||
| let detail_limit = usize::try_from(available_count).unwrap_or(usize::MAX); | ||
| let mut available_credits = summary | ||
| .credits | ||
| .as_deref() | ||
| .unwrap_or_default() | ||
| .iter() | ||
| .filter(|credit| credit.status == RateLimitResetCreditStatus::Available) | ||
| .collect::<Vec<_>>(); | ||
| available_credits.sort_by_key(|credit| credit.expires_at.unwrap_or(i64::MAX)); | ||
|
|
||
| let mut options = available_credits | ||
| .into_iter() | ||
| .take(detail_limit) | ||
| .map(|credit| { | ||
| let expiration = match credit.expires_at { | ||
| Some(expires_at) => DateTime::<Utc>::from_timestamp(expires_at, 0) | ||
| .map(|expires_at| { | ||
| format!( | ||
| "Expires {}", | ||
| expires_at | ||
| .with_timezone(&Local) | ||
| .format("%H:%M on %-d %b %Y") | ||
| ) | ||
| }) | ||
| .unwrap_or_else(|| "Expiration unavailable".to_string()), | ||
| None => "Does not expire".to_string(), | ||
| }; | ||
| let reset_title = credit | ||
| .title | ||
| .as_deref() | ||
| .map(str::trim) | ||
| .filter(|title| !title.is_empty()) | ||
| .unwrap_or("Full reset"); | ||
| let reset_description = credit | ||
| .description | ||
| .as_deref() | ||
| .map(str::trim) | ||
| .filter(|description| !description.is_empty()) | ||
| .unwrap_or("Reset your current usage limits."); | ||
| ResetCreditOption { | ||
| credit_id: Some(credit.id.clone()), | ||
| name: reset_title.to_string(), | ||
| detail: Some(format!("{expiration}.")), | ||
| description: reset_description.to_string(), | ||
| } | ||
| }) | ||
| .collect::<Vec<_>>(); | ||
|
|
||
| if options.is_empty() { | ||
| options.push(ResetCreditOption { | ||
| credit_id: None, | ||
| name: "Full reset".to_string(), | ||
| detail: None, | ||
| description: "Reset your current usage limits.".to_string(), | ||
| }); | ||
| } | ||
|
|
||
| options | ||
| } |
11 changes: 11 additions & 0 deletions
11
...src/chatwidget/snapshots/codex_tui__chatwidget__tests__rate_limit_reset_confirmation.snap
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| --- | ||
| source: tui/src/chatwidget/tests/usage.rs | ||
| expression: "render_bottom_popup(&chat, 80)" | ||
| --- | ||
| Use this reset? | ||
| Full reset (Weekly + 5 hr) · Expires 09:39 on 18 Jun 2026. | ||
|
|
||
| 1. Yes, use reset Reset your weekly and 5-hour usage limits. | ||
| › 2. No, go back Choose a different reset. | ||
|
|
||
| Press enter to confirm or esc to go back |
13 changes: 13 additions & 0 deletions
13
...rc/chatwidget/snapshots/codex_tui__chatwidget__tests__rate_limit_reset_picker_narrow.snap
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| --- | ||
| source: tui/src/chatwidget/tests/usage.rs | ||
| expression: "render_bottom_popup(&chat, 44)" | ||
| --- | ||
| Usage limit resets | ||
| 2 usage limit resets available. | ||
|
|
||
| › 1. Cancel | ||
| 2. Full reset Expires 09:39 on 18 Jun | ||
| 2026. | ||
| 3. Full reset Does not expire. | ||
|
|
||
| Press enter to confirm or esc to go back |
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When two different reset rows are accepted before the first
OpenRateLimitResetConfirmationis handled, the first event opens the confirmation and the second reaches this call while the active view is no longer the picker, soshow_rate_limit_reset_confirmationreturnsfalse. Because that return value is ignored, the second row'sAtomicBoolremainsfalse; after backing out of the first confirmation, selecting that second row no longer sends another event until the picker is rebuilt.Useful? React with 👍 / 👎.