Lightweight coding agent that runs in your terminal
Rust
fix: prefer config var to env var (#2495)
Michael Bolince434b121958
diff --git a/codex-rs/core/src/client.rs b/codex-rs/core/src/client.rsindex 35d2c92e44..9552a53d7f 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.rsindex 90c5ba4a60..4b6f8ac9ef 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 KiBconst 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<String>,+ 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<PathBuf>,/// The value for the `originator` header included with Responses API requests.- pub internal_originator: Option<String>,+ pub responses_originator_header_internal_override: Option<String>,pub projects: Option<HashMap<String, ProjectConfig>>,@@ -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 = truebase_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 = truebase_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 = truebase_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.rsindex d93e28ef63..1c82df3180 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.rsindex 075c496a6b..30ba62eeae 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