From 3779b52e2d2925eaf84c0c9ec57d34a113606db1 Mon Sep 17 00:00:00 2001 From: Eric Traut Date: Fri, 6 Feb 2026 23:26:44 -0800 Subject: [PATCH] Do not poll for usage when using API Key auth (#10973) Fixes #10869 - Gate TUI rate-limit polling on ChatGPT-auth providers only. - `prefetch_rate_limits()` now checks `should_prefetch_rate_limits()`. - New gate requires: - `config.model_provider.requires_openai_auth` - cached auth is ChatGPT (`CodexAuth::is_chatgpt_auth`) - Prevents `/wham/usage` polling in API/custom-endpoint profiles. --- codex-rs/tui/src/chatwidget.rs | 18 ++++++++++++------ codex-rs/tui/src/chatwidget/tests.rs | 16 ++++++++++++++++ 2 files changed, 28 insertions(+), 6 deletions(-) diff --git a/codex-rs/tui/src/chatwidget.rs b/codex-rs/tui/src/chatwidget.rs index 94fece362..f103f5bfc 100644 --- a/codex-rs/tui/src/chatwidget.rs +++ b/codex-rs/tui/src/chatwidget.rs @@ -4492,12 +4492,7 @@ impl ChatWidget { fn prefetch_rate_limits(&mut self) { self.stop_rate_limit_poller(); - if !self - .auth_manager - .auth_cached() - .as_ref() - .is_some_and(CodexAuth::is_chatgpt_auth) - { + if !self.should_prefetch_rate_limits() { return; } @@ -4522,6 +4517,17 @@ impl ChatWidget { self.rate_limit_poller = Some(handle); } + fn should_prefetch_rate_limits(&self) -> bool { + if !self.config.model_provider.requires_openai_auth { + return false; + } + + self.auth_manager + .auth_cached() + .as_ref() + .is_some_and(CodexAuth::is_chatgpt_auth) + } + fn lower_cost_preset(&self) -> Option { let models = self.models_manager.try_list_models(&self.config).ok()?; models diff --git a/codex-rs/tui/src/chatwidget/tests.rs b/codex-rs/tui/src/chatwidget/tests.rs index fcd2b8461..bf173ceca 100644 --- a/codex-rs/tui/src/chatwidget/tests.rs +++ b/codex-rs/tui/src/chatwidget/tests.rs @@ -1138,6 +1138,22 @@ fn set_chatgpt_auth(chat: &mut ChatWidget) { )); } +#[tokio::test] +async fn prefetch_rate_limits_is_gated_on_chatgpt_auth_provider() { + let (mut chat, _rx, _op_rx) = make_chatwidget_manual(None).await; + + assert!(!chat.should_prefetch_rate_limits()); + + set_chatgpt_auth(&mut chat); + assert!(chat.should_prefetch_rate_limits()); + + chat.config.model_provider.requires_openai_auth = false; + assert!(!chat.should_prefetch_rate_limits()); + + chat.prefetch_rate_limits(); + assert!(chat.rate_limit_poller.is_none()); +} + #[tokio::test] async fn worked_elapsed_from_resets_when_timer_restarts() { let (mut chat, _rx, _op_rx) = make_chatwidget_manual(None).await;