Show actionable rate-limit banners in the TUI (#41742)

## What changed

- Carry optional backend-owned banner and account identity data through
  `account/rateLimits/read`, filtering banners that do not match the authenticated
  account and user.
- Render supported rate-limit notices above the composer with actions for usage,
  credits, resets, owner notifications, and plan management while preserving the
  existing fallback UI for absent or unsupported banners.
- Refresh usage after limit errors, reject stale responses, and keep queued input
  paused until recovery completes. When instructed by the banner, switch to the
  first available fallback model without changing unrelated thread settings.

## Testing

- Add protocol, banner parsing and rendering, CTA, identity filtering, refresh
  ordering, fallback-model, account-change, and queued-input recovery coverage.

GitOrigin-RevId: e03d75a82e425deb87f4b120a71cf2286c0ef6cc
This commit is contained in:
stefanstokic-oai authored and copyberry committed 2026-08-31 00:20:06 +00:00
1 parent 94cbbddafc
commit 79b04f1ab5
69 files changed
+3454 -69

No files matched your search

+29 -20
View File
@@ -398,6 +398,8 @@ impl ChatWidget {
}
pub(super) fn on_rate_limit_error(&mut self, error_kind: RateLimitErrorKind, message: String) {
// on_error can drain queued input, before the asynchronous recovery read completes.
self.input_queue.rate_limit_recovery_pending = self.has_chatgpt_account;
let usage_limit_error = matches!(error_kind, RateLimitErrorKind::UsageLimit);
let rate_limit_reached_type = self.codex_rate_limit_reached_type.map(|kind| {
if usage_limit_error {
@@ -414,31 +416,38 @@ impl ChatWidget {
kind
}
});
if self.codex_rate_limit_reached_type != rate_limit_reached_type {
self.clear_backend_banner();
}
self.codex_rate_limit_reached_type = rate_limit_reached_type;
match rate_limit_reached_type {
Some(RateLimitReachedType::WorkspaceOwnerCreditsDepleted) => {
self.on_error(
// Keep owner remediation in history even when the optional backend banner is unavailable.
let (message, nudge) = match rate_limit_reached_type {
Some(RateLimitReachedType::WorkspaceOwnerCreditsDepleted) => (
"You're out of credits. Your workspace is out of credits. Add credits to continue using Codex."
.to_string(),
);
}
Some(RateLimitReachedType::WorkspaceOwnerUsageLimitReached) => {
self.on_error(
None,
),
Some(RateLimitReachedType::WorkspaceOwnerUsageLimitReached) => (
"Usage limit reached. You've reached your usage limit. Increase your limits to continue using codex."
.to_string(),
);
}
Some(RateLimitReachedType::WorkspaceMemberCreditsDepleted) => {
self.on_error(message);
self.open_workspace_owner_nudge_prompt(AddCreditsNudgeCreditType::Credits);
}
Some(RateLimitReachedType::WorkspaceMemberUsageLimitReached) => {
self.on_error(message);
self.open_workspace_owner_nudge_prompt(AddCreditsNudgeCreditType::UsageLimit);
}
Some(RateLimitReachedType::RateLimitReached) | None => {
self.on_error(message);
}
None,
),
Some(RateLimitReachedType::WorkspaceMemberCreditsDepleted) =>
(message, Some(AddCreditsNudgeCreditType::Credits)),
Some(RateLimitReachedType::WorkspaceMemberUsageLimitReached) =>
(message, Some(AddCreditsNudgeCreditType::UsageLimit)),
Some(RateLimitReachedType::RateLimitReached) | None => (message, None),
};
self.on_error(message);
if !self.has_applicable_backend_banner()
&& let Some(credit_type) = nudge
{
self.open_workspace_owner_nudge_prompt(credit_type);
}
if self.has_chatgpt_account {
self.app_event_tx.send(AppEvent::RefreshRateLimits {
origin: crate::app_event::RateLimitRefreshOrigin::Recovery,
});
}
}