Lightweight coding agent that runs in your terminal
Rust
Use the shared HTTP client for announcement tips (#35825)
Celia Chen155c3e299c3a
diff --git a/codex-rs/tui/src/lib.rs b/codex-rs/tui/src/lib.rsindex 7af8bc8885..7c3e6736ca 100644--- a/codex-rs/tui/src/lib.rs+++ b/codex-rs/tui/src/lib.rs@@ -1341,7 +1341,7 @@ async fn run_ratatui_app(let uses_remote_workspace = app_server_target.uses_remote_workspace();color_eyre::install()?;- tooltips::announcement::prewarm();+ tooltips::announcement::prewarm(initial_config.http_client_factory());// Forward panic reports through tracing so they appear in the UI status// line, but do not swallow the default/color-eyre panic handler.diff --git a/codex-rs/tui/src/tooltips.rs b/codex-rs/tui/src/tooltips.rsindex 6bdc4cf52d..79e74f5201 100644--- a/codex-rs/tui/src/tooltips.rs+++ b/codex-rs/tui/src/tooltips.rs@@ -125,19 +125,27 @@ pub(crate) mod announcement {use crate::version::CODEX_CLI_VERSION;use chrono::NaiveDate;use chrono::Utc;+ use codex_http_client::ClientRouteClass;+ use codex_http_client::HttpClientFactory;+ use codex_http_client::RouteAwareClientPool;use codex_protocol::account::PlanType;use regex_lite::Regex;use serde::Deserialize;use std::sync::OnceLock;- use std::thread;use std::time::Duration;static ANNOUNCEMENT_TIP: OnceLock<Option<String>> = OnceLock::new();const CURRENT_OS: TargetOs = TargetOs::current();/// Prewarm the cache of the announcement tip.- pub(crate) fn prewarm() {- let _ = thread::spawn(|| ANNOUNCEMENT_TIP.get_or_init(init_announcement_tip_in_thread));+ pub(crate) fn prewarm(http_client_factory: HttpClientFactory) {+ if ANNOUNCEMENT_TIP.get().is_some() {+ return;+ }+ tokio::spawn(async move {+ let announcement_tip = fetch_announcement_tip_text(http_client_factory).await;+ let _ = ANNOUNCEMENT_TIP.set(announcement_tip);+ });}/// Fetch the announcement tip, return None if the prewarm is not done yet.@@ -199,25 +207,15 @@ pub(crate) mod announcement {}}- fn init_announcement_tip_in_thread() -> Option<String> {- thread::spawn(blocking_init_announcement_tip)- .join()- .ok()- .flatten()- }-- fn blocking_init_announcement_tip() -> Option<String> {- // Avoid system proxy detection to prevent macOS system-configuration panics (#8912).- let client = reqwest::blocking::Client::builder()- .no_proxy()- .build()- .ok()?;+ async fn fetch_announcement_tip_text(http_client_factory: HttpClientFactory) -> Option<String> {+ let client = RouteAwareClientPool::new(http_client_factory, ClientRouteClass::Other);let response = client.get(ANNOUNCEMENT_TIP_URL).timeout(Duration::from_millis(2000)).send()+ .await.ok()?;- response.error_for_status().ok()?.text().ok()+ response.error_for_status().ok()?.text().await.ok()}pub(crate) fn parse_announcement_tip_toml(