Harden CLI rate limit window labels (#22929)

## Context

The CLI rate-limit surfaces previously described usage windows as fixed
5-hour and weekly limits. We want the CLI to display whatever supported
rate-limit period the server returns instead of assuming a 5-hour/1-week
pair. This supports generalized Codex rate-limit periods.

## Summary

- Formats CLI rate-limit warning/status labels only for the supported
returned window durations: approximate 5h, daily, weekly, monthly, and
annual.
- Uses generic fallback copy when a primary or secondary window has no
duration, so missing secondary protection data does not produce stale
weekly copy.
- Uses generic fallback copy for unsupported window durations instead of
adding arbitrary hourly, multi-day, multi-week, or multi-year labels.
- Updates status line and terminal title setup descriptions/previews to
talk about primary/secondary usage limits rather than fixed 5h/weekly
limits.
- Adds rendered insta snapshot coverage for the updated rate-limit
status surfaces and `/status` fallback labels.

## Tests
Tested locally:
- one primary window
- one secondary window
- primary and secondary window
This commit is contained in:
Arun Eswara authored and GitHub committed 2026-05-19 11:22:00 -07:00
1 parent 3c76081876
commit d269aa2af9
16 files changed
+860 -89

No files matched your search

@@ -15,7 +15,7 @@
//! - Permissions profile
//! - Approval mode
//! - Context usage (remaining %, used %, window size)
//! - Usage limits (5-hour, weekly)
//! - Usage limits (primary, secondary)
//! - Session info (thread title, thread ID, tokens used)
//! - Application version
@@ -100,10 +100,10 @@ pub(crate) enum StatusLineItem {
#[strum(to_string = "context-used", serialize = "context-usage")]
ContextUsed,
/// Remaining usage on the 5-hour rate limit.
/// Remaining usage on the primary rate limit.
FiveHourLimit,
/// Remaining usage on the weekly rate limit.
/// Remaining usage on the secondary rate limit.
WeeklyLimit,
/// Codex application version.
@@ -163,10 +163,10 @@ impl StatusLineItem {
"Percentage of context window used (omitted when unknown)"
}
StatusLineItem::FiveHourLimit => {
"Remaining usage on 5-hour usage limit (omitted when unavailable)"
"Remaining usage on the primary usage limit (omitted when unavailable)"
}
StatusLineItem::WeeklyLimit => {
"Remaining usage on weekly usage limit (omitted when unavailable)"
"Remaining usage on the secondary usage limit (omitted when unavailable)"
}
StatusLineItem::CodexVersion => "Codex application version",
StatusLineItem::ContextWindowSize => {
@@ -268,7 +268,11 @@ impl StatusLineSetupView {
if !used_ids.insert(item_id.clone()) {
continue;
}
items.push(Self::status_line_select_item(item, /*enabled*/ true));
items.push(Self::status_line_select_item(
item,
/*enabled*/ true,
&preview_data,
));
}
}
@@ -277,7 +281,11 @@ impl StatusLineSetupView {
if used_ids.contains(&item_id) {
continue;
}
items.push(Self::status_line_select_item(item, /*enabled*/ false));
items.push(Self::status_line_select_item(
item,
/*enabled*/ false,
&preview_data,
));
}
Self {
@@ -324,11 +332,25 @@ impl StatusLineSetupView {
}
/// Converts a [`StatusLineItem`] into a [`MultiSelectItem`] for the picker.
fn status_line_select_item(item: StatusLineItem, enabled: bool) -> MultiSelectItem {
fn status_line_select_item(
item: StatusLineItem,
enabled: bool,
preview_data: &StatusSurfacePreviewData,
) -> MultiSelectItem {
let default_name = item.to_string();
let default_description = item.description();
let (name, description) = match item {
StatusLineItem::FiveHourLimit | StatusLineItem::WeeklyLimit => (
preview_data.rate_limit_item_name(item.preview_item(), &default_name),
preview_data.rate_limit_item_description(item.preview_item(), default_description),
),
_ => (default_name, default_description.to_string()),
};
MultiSelectItem {
id: item.to_string(),
name: item.to_string(),
description: Some(item.description().to_string()),
name,
description: Some(description),
enabled,
orderable: true,
section_break_after: false,
@@ -51,8 +51,8 @@ impl StatusSurfacePreviewItem {
StatusSurfacePreviewItem::ApprovalMode => "on-request",
StatusSurfacePreviewItem::ContextRemaining => "Context 0% left",
StatusSurfacePreviewItem::ContextUsed => "Context 0% used",
StatusSurfacePreviewItem::FiveHourLimit => "5h 0%",
StatusSurfacePreviewItem::WeeklyLimit => "weekly 0%",
StatusSurfacePreviewItem::FiveHourLimit => "primary 0%",
StatusSurfacePreviewItem::WeeklyLimit => "secondary 0%",
StatusSurfacePreviewItem::CodexVersion => "0.0.0",
StatusSurfacePreviewItem::ContextWindowSize => "0 window",
StatusSurfacePreviewItem::UsedTokens => "0 used",
@@ -169,10 +169,49 @@ impl StatusSurfacePreviewData {
);
}
pub(crate) fn suppress_placeholder(&mut self, item: StatusSurfacePreviewItem) {
if self
.values
.get(&item)
.is_some_and(|value| value.is_placeholder)
{
self.values.remove(&item);
}
}
pub(crate) fn rate_limit_item_name(
&self,
item: StatusSurfacePreviewItem,
fallback: &str,
) -> String {
self.live_value_for(item)
.and_then(rate_limit_preview_copy)
.map(|copy| copy.name.to_string())
.unwrap_or_else(|| fallback.to_string())
}
pub(crate) fn rate_limit_item_description(
&self,
item: StatusSurfacePreviewItem,
fallback: &str,
) -> String {
self.live_value_for(item)
.and_then(rate_limit_preview_copy)
.map(|copy| copy.description.to_string())
.unwrap_or_else(|| fallback.to_string())
}
pub(crate) fn value_for(&self, item: StatusSurfacePreviewItem) -> Option<&str> {
self.values.get(&item).map(|value| value.text.as_str())
}
fn live_value_for(&self, item: StatusSurfacePreviewItem) -> Option<&str> {
self.values
.get(&item)
.filter(|value| !value.is_placeholder)
.map(|value| value.text.as_str())
}
pub(crate) fn status_line_for_items<I>(
&self,
items: I,
@@ -188,3 +227,50 @@ impl StatusSurfacePreviewData {
status_line_from_segments(segments, use_theme_colors)
}
}
struct RateLimitPreviewCopy {
name: &'static str,
description: &'static str,
}
fn rate_limit_preview_copy(value: &str) -> Option<RateLimitPreviewCopy> {
let value = value.trim_start();
if value.starts_with("secondary usage ") {
Some(RateLimitPreviewCopy {
name: "secondary-usage-limit",
description: "Remaining usage on the secondary usage limit (omitted when unavailable)",
})
} else if value.starts_with("usage ") {
Some(RateLimitPreviewCopy {
name: "usage-limit",
description: "Remaining usage on the primary usage limit (omitted when unavailable)",
})
} else if value.starts_with("5h ") {
Some(RateLimitPreviewCopy {
name: "five-hour-limit",
description: "Remaining usage on the 5-hour usage limit (omitted when unavailable)",
})
} else if value.starts_with("daily ") {
Some(RateLimitPreviewCopy {
name: "daily-limit",
description: "Remaining usage on the daily usage limit (omitted when unavailable)",
})
} else if value.starts_with("weekly ") {
Some(RateLimitPreviewCopy {
name: "weekly-limit",
description: "Remaining usage on the weekly usage limit (omitted when unavailable)",
})
} else if value.starts_with("monthly ") {
Some(RateLimitPreviewCopy {
name: "monthly-limit",
description: "Remaining usage on the monthly usage limit (omitted when unavailable)",
})
} else if value.starts_with("annual ") {
Some(RateLimitPreviewCopy {
name: "annual-limit",
description: "Remaining usage on the annual usage limit (omitted when unavailable)",
})
} else {
None
}
}
+28 -9
View File
@@ -60,9 +60,9 @@ pub(crate) enum TerminalTitleItem {
/// Percentage of context window used.
#[strum(to_string = "context-used", serialize = "context-usage")]
ContextUsed,
/// Remaining usage on the 5-hour rate limit.
/// Remaining usage on the primary rate limit.
FiveHourLimit,
/// Remaining usage on the weekly rate limit.
/// Remaining usage on the secondary rate limit.
WeeklyLimit,
/// Codex application version.
CodexVersion,
@@ -107,10 +107,10 @@ impl TerminalTitleItem {
"Percentage of context window used (omitted when unknown)"
}
TerminalTitleItem::FiveHourLimit => {
"Remaining usage on 5-hour usage limit (omitted when unavailable)"
"Remaining usage on the primary usage limit (omitted when unavailable)"
}
TerminalTitleItem::WeeklyLimit => {
"Remaining usage on weekly usage limit (omitted when unavailable)"
"Remaining usage on the secondary usage limit (omitted when unavailable)"
}
TerminalTitleItem::CodexVersion => "Codex application version",
TerminalTitleItem::UsedTokens => "Total tokens used in session (omitted when zero)",
@@ -259,11 +259,13 @@ impl TerminalTitleSetupView {
.collect::<std::collections::HashSet<_>>();
let items = selected_items
.into_iter()
.map(|item| Self::title_select_item(item, /*enabled*/ true))
.map(|item| Self::title_select_item(item, /*enabled*/ true, &preview_data))
.chain(
TerminalTitleItem::iter()
.filter(|item| !selected_set.contains(item))
.map(|item| Self::title_select_item(item, /*enabled*/ false)),
.map(|item| {
Self::title_select_item(item, /*enabled*/ false, &preview_data)
}),
)
.collect();
@@ -309,11 +311,28 @@ impl TerminalTitleSetupView {
}
}
fn title_select_item(item: TerminalTitleItem, enabled: bool) -> MultiSelectItem {
fn title_select_item(
item: TerminalTitleItem,
enabled: bool,
preview_data: &StatusSurfacePreviewData,
) -> MultiSelectItem {
let default_name = item.to_string();
let default_description = item.description();
let (name, description) = match item.preview_item() {
Some(
preview_item @ (StatusSurfacePreviewItem::FiveHourLimit
| StatusSurfacePreviewItem::WeeklyLimit),
) => (
preview_data.rate_limit_item_name(preview_item, &default_name),
preview_data.rate_limit_item_description(preview_item, default_description),
),
_ => (default_name, default_description.to_string()),
};
MultiSelectItem {
id: item.to_string(),
name: item.to_string(),
description: Some(item.description().to_string()),
name,
description: Some(description),
enabled,
orderable: true,
section_break_after: false,