Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions codex-rs/tui/src/chatwidget.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ struct RunningCommand {
parsed_cmd: Vec<ParsedCommand>,
}

const RATE_LIMIT_WARNING_THRESHOLDS: [f64; 3] = [50.0, 75.0, 90.0];
const RATE_LIMIT_WARNING_THRESHOLDS: [f64; 3] = [75.0, 90.0, 95.0];

#[derive(Default)]
struct RateLimitWarningState {
Expand All @@ -127,24 +127,30 @@ impl RateLimitWarningState {
) -> Vec<String> {
let mut warnings = Vec::new();

let mut highest_secondary: Option<f64> = None;
while self.secondary_index < RATE_LIMIT_WARNING_THRESHOLDS.len()
&& secondary_used_percent >= RATE_LIMIT_WARNING_THRESHOLDS[self.secondary_index]
{
let threshold = RATE_LIMIT_WARNING_THRESHOLDS[self.secondary_index];
highest_secondary = Some(RATE_LIMIT_WARNING_THRESHOLDS[self.secondary_index]);
self.secondary_index += 1;
}
if let Some(threshold) = highest_secondary {
warnings.push(format!(
"Heads up, you've used over {threshold:.0}% of your weekly limit. Run /status for a breakdown."
));
self.secondary_index += 1;
}

let mut highest_primary: Option<f64> = None;
while self.primary_index < RATE_LIMIT_WARNING_THRESHOLDS.len()
&& primary_used_percent >= RATE_LIMIT_WARNING_THRESHOLDS[self.primary_index]
{
let threshold = RATE_LIMIT_WARNING_THRESHOLDS[self.primary_index];
highest_primary = Some(RATE_LIMIT_WARNING_THRESHOLDS[self.primary_index]);
self.primary_index += 1;
}
if let Some(threshold) = highest_primary {
warnings.push(format!(
"Heads up, you've used over {threshold:.0}% of your 5h limit. Run /status for a breakdown."
Comment on lines 127 to 152
Copy link
Contributor

Choose a reason for hiding this comment

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

[P1] Update rate limit tests for new thresholds

The new thresholds [75.0, 90.0, 95.0] and the logic that emits only the highest crossed threshold mean RateLimitWarningState::take_warnings will now generate at most four warnings for the sequence used in rate_limit_warnings_emit_thresholds, and none will mention 50%. That test still asserts six warnings and checks for messages containing "over 50%", so it will fail after this change. Please update the test expectations to match the new thresholds and one‑per‑call behaviour, otherwise CI will remain red.

Useful? React with 👍 / 👎.

));
self.primary_index += 1;
}

warnings
Expand Down
43 changes: 16 additions & 27 deletions codex-rs/tui/src/chatwidget/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -390,33 +390,22 @@ fn rate_limit_warnings_emit_thresholds() {
warnings.extend(state.take_warnings(95.0, 10.0));

assert_eq!(
warnings.len(),
6,
"expected one warning per threshold per limit"
);
assert!(
warnings
.iter()
.any(|w| w.contains("Heads up, you've used over 50% of your 5h limit.")),
"expected hourly 50% warning (new copy)"
);
assert!(
warnings
.iter()
.any(|w| w.contains("Heads up, you've used over 50% of your weekly limit.")),
"expected weekly 50% warning (new copy)"
);
assert!(
warnings
.iter()
.any(|w| w.contains("Heads up, you've used over 90% of your 5h limit.")),
"expected hourly 90% warning (new copy)"
);
assert!(
warnings
.iter()
.any(|w| w.contains("Heads up, you've used over 90% of your weekly limit.")),
"expected weekly 90% warning (new copy)"
warnings,
vec![
String::from(
"Heads up, you've used over 75% of your 5h limit. Run /status for a breakdown."
),
String::from(
"Heads up, you've used over 75% of your weekly limit. Run /status for a breakdown.",
),
String::from(
"Heads up, you've used over 95% of your 5h limit. Run /status for a breakdown."
),
String::from(
"Heads up, you've used over 95% of your weekly limit. Run /status for a breakdown.",
),
],
"expected one warning per limit for the highest crossed threshold"
);
}

Expand Down
Loading