From ce434b121958101df8b84ef43a34e039e2ac9c25 Mon Sep 17 00:00:00 2001 From: Michael Bolin Date: Tue, 19 Aug 2025 21:51:59 -0700 Subject: [PATCH] fix: prefer config var to env var (#2495) --- codex-rs/core/src/client.rs | 6 +----- codex-rs/core/src/config.rs | 21 +++++++++++---------- codex-rs/core/src/spawn.rs | 3 --- codex-rs/core/tests/client.rs | 2 +- 4 files changed, 13 insertions(+), 19 deletions(-) diff --git a/codex-rs/core/src/client.rs b/codex-rs/core/src/client.rs index 35d2c92e..9552a53d 100644 --- a/codex-rs/core/src/client.rs +++ b/codex-rs/core/src/client.rs @@ -208,11 +208,7 @@ impl ModelClient { req_builder = req_builder.header("chatgpt-account-id", account_id); } - let originator = self - .config - .internal_originator - .as_deref() - .unwrap_or("codex_cli_rs"); + let originator = &self.config.responses_originator_header; req_builder = req_builder.header("originator", originator); req_builder = req_builder.header("User-Agent", get_codex_user_agent(Some(originator))); diff --git a/codex-rs/core/src/config.rs b/codex-rs/core/src/config.rs index 90c5ba4a..4b6f8ac9 100644 --- a/codex-rs/core/src/config.rs +++ b/codex-rs/core/src/config.rs @@ -13,7 +13,6 @@ use crate::model_provider_info::built_in_model_providers; use crate::openai_model_info::get_model_info; use crate::protocol::AskForApproval; use crate::protocol::SandboxPolicy; -use crate::spawn::CODEX_ORIGINATOR_ENV_VAR; use codex_login::AuthMode; use codex_protocol::config_types::ReasoningEffort; use codex_protocol::config_types::ReasoningSummary; @@ -36,6 +35,8 @@ pub(crate) const PROJECT_DOC_MAX_BYTES: usize = 32 * 1024; // 32 KiB const CONFIG_TOML_FILE: &str = "config.toml"; +const DEFAULT_RESPONSES_ORIGINATOR_HEADER: &str = "codex_cli_rs"; + /// Application configuration loaded from disk and merged with overrides. #[derive(Debug, Clone, PartialEq)] pub struct Config { @@ -164,7 +165,7 @@ pub struct Config { pub include_apply_patch_tool: bool, /// The value for the `originator` header included with Responses API requests. - pub internal_originator: Option, + pub responses_originator_header: String, /// If set to `true`, the API key will be signed with the `originator` header. pub preferred_auth_method: AuthMode, @@ -411,7 +412,7 @@ pub struct ConfigToml { pub experimental_instructions_file: Option, /// The value for the `originator` header included with Responses API requests. - pub internal_originator: Option, + pub responses_originator_header_internal_override: Option, pub projects: Option>, @@ -626,9 +627,9 @@ impl Config { let include_apply_patch_tool_val = include_apply_patch_tool.unwrap_or(model_family.uses_apply_patch_tool); - let originator = std::env::var(CODEX_ORIGINATOR_ENV_VAR) - .ok() - .or(cfg.internal_originator); + let responses_originator_header: String = cfg + .responses_originator_header_internal_override + .unwrap_or(DEFAULT_RESPONSES_ORIGINATOR_HEADER.to_owned()); let config = Self { model, @@ -683,7 +684,7 @@ impl Config { experimental_resume, include_plan_tool: include_plan_tool.unwrap_or(false), include_apply_patch_tool: include_apply_patch_tool_val, - internal_originator: originator, + responses_originator_header, preferred_auth_method: cfg.preferred_auth_method.unwrap_or(AuthMode::ChatGPT), }; Ok(config) @@ -1048,7 +1049,7 @@ disable_response_storage = true base_instructions: None, include_plan_tool: false, include_apply_patch_tool: false, - internal_originator: None, + responses_originator_header: "codex_cli_rs".to_string(), preferred_auth_method: AuthMode::ChatGPT, }, o3_profile_config @@ -1101,7 +1102,7 @@ disable_response_storage = true base_instructions: None, include_plan_tool: false, include_apply_patch_tool: false, - internal_originator: None, + responses_originator_header: "codex_cli_rs".to_string(), preferred_auth_method: AuthMode::ChatGPT, }; @@ -1169,7 +1170,7 @@ disable_response_storage = true base_instructions: None, include_plan_tool: false, include_apply_patch_tool: false, - internal_originator: None, + responses_originator_header: "codex_cli_rs".to_string(), preferred_auth_method: AuthMode::ChatGPT, }; diff --git a/codex-rs/core/src/spawn.rs b/codex-rs/core/src/spawn.rs index d93e28ef..1c82df31 100644 --- a/codex-rs/core/src/spawn.rs +++ b/codex-rs/core/src/spawn.rs @@ -22,9 +22,6 @@ pub const CODEX_SANDBOX_NETWORK_DISABLED_ENV_VAR: &str = "CODEX_SANDBOX_NETWORK_ /// accommodate sandboxing configuration and other sandboxing mechanisms. pub const CODEX_SANDBOX_ENV_VAR: &str = "CODEX_SANDBOX"; -/// Set this to change the originator sent with all network requests. -pub const CODEX_ORIGINATOR_ENV_VAR: &str = "CODEX_ORIGINATOR"; - #[derive(Debug, Clone, Copy)] pub enum StdioPolicy { RedirectForShellTool, diff --git a/codex-rs/core/tests/client.rs b/codex-rs/core/tests/client.rs index 075c496a..30ba62ee 100644 --- a/codex-rs/core/tests/client.rs +++ b/codex-rs/core/tests/client.rs @@ -260,7 +260,7 @@ async fn originator_config_override_is_used() { let codex_home = TempDir::new().unwrap(); let mut config = load_default_config_for_test(&codex_home); config.model_provider = model_provider; - config.internal_originator = Some("my_override".to_string()); + config.responses_originator_header = "my_override".to_owned(); let conversation_manager = ConversationManager::default(); let codex = conversation_manager