mirror of
https://github.com/openai/codex.git
synced 2026-11-10 16:44:38 +00:00
Use the shared HTTP client for announcement tips (#35825)
## Why Announcement prewarming disabled proxy discovery to avoid the macOS sandbox panic fixed by https://github.com/openai/codex/pull/16670. ## What changed - Fetch announcement tips asynchronously with `RouteAwareClientPool` instead of a blocking `reqwest` client. - Pass the configured `HttpClientFactory` into prewarming so announcement requests honor the configured outbound proxy policy. GitOrigin-RevId: 535158d95a99c6f515bd30ea6e3bcb2ac6bb6d7e
This commit is contained in:
1 parent
8bbdf6c8f9
commit
155c3e299c
2 files changed
+16
-18
No files matched your search
@@ -1341,7 +1341,7 @@ async fn run_ratatui_app(
|
|||||||
let uses_remote_workspace = app_server_target.uses_remote_workspace();
|
let uses_remote_workspace = app_server_target.uses_remote_workspace();
|
||||||
color_eyre::install()?;
|
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
|
// Forward panic reports through tracing so they appear in the UI status
|
||||||
// line, but do not swallow the default/color-eyre panic handler.
|
// line, but do not swallow the default/color-eyre panic handler.
|
||||||
|
|||||||
@@ -125,19 +125,27 @@ pub(crate) mod announcement {
|
|||||||
use crate::version::CODEX_CLI_VERSION;
|
use crate::version::CODEX_CLI_VERSION;
|
||||||
use chrono::NaiveDate;
|
use chrono::NaiveDate;
|
||||||
use chrono::Utc;
|
use chrono::Utc;
|
||||||
|
use codex_http_client::ClientRouteClass;
|
||||||
|
use codex_http_client::HttpClientFactory;
|
||||||
|
use codex_http_client::RouteAwareClientPool;
|
||||||
use codex_protocol::account::PlanType;
|
use codex_protocol::account::PlanType;
|
||||||
use regex_lite::Regex;
|
use regex_lite::Regex;
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
use std::sync::OnceLock;
|
use std::sync::OnceLock;
|
||||||
use std::thread;
|
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
|
|
||||||
static ANNOUNCEMENT_TIP: OnceLock<Option<String>> = OnceLock::new();
|
static ANNOUNCEMENT_TIP: OnceLock<Option<String>> = OnceLock::new();
|
||||||
const CURRENT_OS: TargetOs = TargetOs::current();
|
const CURRENT_OS: TargetOs = TargetOs::current();
|
||||||
|
|
||||||
/// Prewarm the cache of the announcement tip.
|
/// Prewarm the cache of the announcement tip.
|
||||||
pub(crate) fn prewarm() {
|
pub(crate) fn prewarm(http_client_factory: HttpClientFactory) {
|
||||||
let _ = thread::spawn(|| ANNOUNCEMENT_TIP.get_or_init(init_announcement_tip_in_thread));
|
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.
|
/// 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> {
|
async fn fetch_announcement_tip_text(http_client_factory: HttpClientFactory) -> Option<String> {
|
||||||
thread::spawn(blocking_init_announcement_tip)
|
let client = RouteAwareClientPool::new(http_client_factory, ClientRouteClass::Other);
|
||||||
.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()?;
|
|
||||||
let response = client
|
let response = client
|
||||||
.get(ANNOUNCEMENT_TIP_URL)
|
.get(ANNOUNCEMENT_TIP_URL)
|
||||||
.timeout(Duration::from_millis(2000))
|
.timeout(Duration::from_millis(2000))
|
||||||
.send()
|
.send()
|
||||||
|
.await
|
||||||
.ok()?;
|
.ok()?;
|
||||||
response.error_for_status().ok()?.text().ok()
|
response.error_for_status().ok()?.text().await.ok()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn parse_announcement_tip_toml(
|
pub(crate) fn parse_announcement_tip_toml(
|
||||||
|
|||||||
Reference in new issue
Block a user