Add process-scoped PSP routing for ChatGPT requests (#36986)

## What changed

- Add a hidden global `--psp` runtime flag and propagate it through TUI, exec,
  app-server, remote-control, and in-process startup paths.
- Attach the `oai-chat-psp=true` cookie to first-party ChatGPT requests when
  enabled, using a cached cookie-aware client with sensitive request logging
  disabled.
- Keep the routing selection out of persistent configuration layers while
  preserving it across config refreshes and agent role changes.

## Testing

- Cover global flag parsing, app-server propagation, config-layer isolation,
  and preservation across config rebuilds and role changes.

GitOrigin-RevId: 05cdc61ffd7162d8e48fc1e166f4732113e5a816
This commit is contained in:
stevenlee-oai authored and copyberry committed 2026-08-04 22:23:40 +00:00
1 parent 411f3f0680
commit 1d952f027e
25 files changed
+199 -16

No files matched your search

+3
View File
@@ -5009,6 +5009,7 @@ async fn rebuild_preserving_session_layers_refreshes_requirements() -> std::io::
refreshed_toml,
ConfigOverrides {
cwd: Some(codex_home.path().to_path_buf()),
psp: Some(true),
..Default::default()
},
codex_home.abs(),
@@ -5086,6 +5087,8 @@ async fn rebuild_preserving_session_layers_refreshes_requirements() -> std::io::
.rebuild_preserving_session_layers(&refreshed_config)
.await?;
assert!(config.psp);
assert!(config.http_client_factory().has_chatgpt_cookies());
assert_eq!(
config.mcp_servers.get(),
&HashMap::from([
+14 -1
View File
@@ -117,6 +117,7 @@ pub use codex_thread_store::ExtraConfig;
use codex_utils_absolute_path::AbsolutePathBuf;
use codex_utils_absolute_path::AbsolutePathBufGuard;
use codex_utils_path_uri::PathUri;
use http::HeaderValue;
use rmcp::model::ElicitationCapability;
use rmcp::model::FormElicitationCapability;
use rmcp::model::UrlElicitationCapability;
@@ -975,6 +976,9 @@ pub struct Config {
/// Whether Codex-owned clients should respect host system proxy settings.
pub respect_system_proxy: bool,
/// Process-only ChatGPT routing selection supplied when Codex is launched.
pub psp: bool,
/// Optional product SKU forwarded to the host-owned apps MCP server.
pub apps_mcp_product_sku: Option<String>,
@@ -1621,7 +1625,12 @@ impl Config {
} else {
OutboundProxyPolicy::ReqwestDefault
};
HttpClientFactory::new(outbound_proxy_policy)
let factory = HttpClientFactory::new(outbound_proxy_policy);
if self.psp {
factory.with_chatgpt_cookies([HeaderValue::from_static("oai-chat-psp=true")])
} else {
factory
}
}
/// Build the plugin-manager input from the effective config.
@@ -1822,6 +1831,7 @@ impl Config {
ConfigOverrides {
cwd: Some(self.cwd.to_path_buf()),
default_zsh_path,
psp: Some(refreshed_config.psp),
..Default::default()
},
refreshed_config.codex_home.clone(),
@@ -2565,6 +2575,7 @@ pub struct ConfigOverrides {
pub tools_web_search_request: Option<bool>,
pub ephemeral: Option<bool>,
pub bypass_hook_trust: Option<bool>,
pub psp: Option<bool>,
/// Additional directories that should be treated as writable roots for this session.
pub additional_writable_roots: Vec<PathBuf>,
/// Explicit absolute runtime workspace roots for this session. When set,
@@ -3236,6 +3247,7 @@ impl Config {
tools_web_search_request: override_tools_web_search_request,
ephemeral,
bypass_hook_trust,
psp,
additional_writable_roots,
workspace_roots: workspace_roots_override,
} = overrides;
@@ -4152,6 +4164,7 @@ impl Config {
.chatgpt_base_url
.unwrap_or("https://chatgpt.com/backend-api/".to_string()),
respect_system_proxy,
psp: psp.unwrap_or_default(),
apps_mcp_product_sku: cfg.apps_mcp_product_sku.clone(),
realtime_audio: cfg
.audio