From 6fa24d65f5a2d9b3880d7a0e2c5100ba8a55d498 Mon Sep 17 00:00:00 2001 From: Gav Verma Date: Tue, 9 Dec 2025 21:17:57 -0800 Subject: [PATCH] Express rate limit warning as % remaining (#7795) image Earlier, the warning was expressed as consumed% whereas status was expressed as remaining%. This change brings the two into sync to minimize confusion and improve visual consistency. --- codex-rs/tui/src/chatwidget.rs | 6 ++++-- codex-rs/tui/src/chatwidget/tests.rs | 10 +++++----- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/codex-rs/tui/src/chatwidget.rs b/codex-rs/tui/src/chatwidget.rs index a0b42ddbe..1d5ad24a0 100644 --- a/codex-rs/tui/src/chatwidget.rs +++ b/codex-rs/tui/src/chatwidget.rs @@ -199,8 +199,9 @@ impl RateLimitWarningState { let limit_label = secondary_window_minutes .map(get_limits_duration) .unwrap_or_else(|| "weekly".to_string()); + let remaining_percent = 100.0 - threshold; warnings.push(format!( - "Heads up, you've used over {threshold:.0}% of your {limit_label} limit. Run /status for a breakdown." + "Heads up, you have less than {remaining_percent:.0}% of your {limit_label} limit left. Run /status for a breakdown." )); } } @@ -217,8 +218,9 @@ impl RateLimitWarningState { let limit_label = primary_window_minutes .map(get_limits_duration) .unwrap_or_else(|| "5h".to_string()); + let remaining_percent = 100.0 - threshold; warnings.push(format!( - "Heads up, you've used over {threshold:.0}% of your {limit_label} limit. Run /status for a breakdown." + "Heads up, you have less than {remaining_percent:.0}% of your {limit_label} limit left. Run /status for a breakdown." )); } } diff --git a/codex-rs/tui/src/chatwidget/tests.rs b/codex-rs/tui/src/chatwidget/tests.rs index 0135abff7..5cc5321f3 100644 --- a/codex-rs/tui/src/chatwidget/tests.rs +++ b/codex-rs/tui/src/chatwidget/tests.rs @@ -515,16 +515,16 @@ fn rate_limit_warnings_emit_thresholds() { warnings, vec![ String::from( - "Heads up, you've used over 75% of your 5h limit. Run /status for a breakdown." + "Heads up, you have less than 25% of your 5h limit left. Run /status for a breakdown." ), String::from( - "Heads up, you've used over 75% of your weekly limit. Run /status for a breakdown.", + "Heads up, you have less than 25% of your weekly limit left. Run /status for a breakdown.", ), String::from( - "Heads up, you've used over 95% of your 5h limit. Run /status for a breakdown." + "Heads up, you have less than 5% of your 5h limit left. Run /status for a breakdown." ), String::from( - "Heads up, you've used over 95% of your weekly limit. Run /status for a breakdown.", + "Heads up, you have less than 5% of your weekly limit left. Run /status for a breakdown.", ), ], "expected one warning per limit for the highest crossed threshold" @@ -540,7 +540,7 @@ fn test_rate_limit_warnings_monthly() { assert_eq!( warnings, vec![String::from( - "Heads up, you've used over 75% of your monthly limit. Run /status for a breakdown.", + "Heads up, you have less than 25% of your monthly limit left. Run /status for a breakdown.", ),], "expected one warning per limit for the highest crossed threshold" );