[codex] suppress low usage remaining warnings when credits are available (#28593)

## Why

The TUI computed proactive `Heads up, you have less than ...` warnings
before considering workspace credits. As a result, users could see
included-limit warnings even when they could continue using Codex with
workspace credits.

`has_credits` alone is not sufficient to determine whether finite
credits are usable: a spend-control hard limit can cap the reported
balance to zero while `has_credits` still reflects the workspace's raw
balance. Unlimited credits are the opposite case: they are usable even
though no numeric balance is reported.

## What changed

- suppress proactive TUI rate-limit usage warnings and the lower-cost
model nudge when usable workspace credits are available
- treat credits as usable when `has_credits` is true and either
`unlimited` is true or the parsed balance is positive
- continue showing warnings when the usable balance is zero, including
when a spend-control limit has capped otherwise available workspace
credits
- add regression coverage for zero-balance, positive-balance, and
unlimited workspace-credit snapshots

## Validation

- `just test -p codex-tui rate_limit_usage_warnings_`
This commit is contained in:
Brooks authored and GitHub committed 2026-06-24 18:43:17 +00:00
1 parent a781761eda
commit 5013d10824
2 files changed
+89 -7

No files matched your search

+13 -7
View File
@@ -210,7 +210,19 @@ impl ChatWidget {
{
self.codex_rate_limit_reached_type = Some(rate_limit_reached_type);
}
let warnings = if is_codex_limit {
let has_workspace_credits = snapshot.credits.as_ref().is_some_and(|credits| {
credits.has_credits
&& (credits.unlimited
|| credits.balance.as_deref().is_some_and(|balance| {
balance
.trim()
.parse::<f64>()
.is_ok_and(|balance| balance > 0.0)
}))
});
let should_warn_about_rate_limit_usage = is_codex_limit && !has_workspace_credits;
let warnings = if should_warn_about_rate_limit_usage {
self.rate_limit_warnings.take_warnings(
snapshot
.secondary
@@ -245,12 +257,6 @@ impl ChatWidget {
.map(|w| f64::from(w.used_percent) >= RATE_LIMIT_SWITCH_PROMPT_THRESHOLD)
.unwrap_or(false));
let has_workspace_credits = snapshot
.credits
.as_ref()
.map(|credits| credits.has_credits)
.unwrap_or(false);
if high_usage
&& !has_workspace_credits
&& !self.rate_limit_switch_prompt_hidden()