Skip to content

Commit ce434b1

Browse files
authored
fix: prefer config var to env var (#2495)
1 parent d1f1e36 commit ce434b1

File tree

4 files changed

+13
-19
lines changed

4 files changed

+13
-19
lines changed

codex-rs/core/src/client.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -208,11 +208,7 @@ impl ModelClient {
208208
req_builder = req_builder.header("chatgpt-account-id", account_id);
209209
}
210210

211-
let originator = self
212-
.config
213-
.internal_originator
214-
.as_deref()
215-
.unwrap_or("codex_cli_rs");
211+
let originator = &self.config.responses_originator_header;
216212
req_builder = req_builder.header("originator", originator);
217213
req_builder = req_builder.header("User-Agent", get_codex_user_agent(Some(originator)));
218214

codex-rs/core/src/config.rs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ use crate::model_provider_info::built_in_model_providers;
1313
use crate::openai_model_info::get_model_info;
1414
use crate::protocol::AskForApproval;
1515
use crate::protocol::SandboxPolicy;
16-
use crate::spawn::CODEX_ORIGINATOR_ENV_VAR;
1716
use codex_login::AuthMode;
1817
use codex_protocol::config_types::ReasoningEffort;
1918
use codex_protocol::config_types::ReasoningSummary;
@@ -36,6 +35,8 @@ pub(crate) const PROJECT_DOC_MAX_BYTES: usize = 32 * 1024; // 32 KiB
3635

3736
const CONFIG_TOML_FILE: &str = "config.toml";
3837

38+
const DEFAULT_RESPONSES_ORIGINATOR_HEADER: &str = "codex_cli_rs";
39+
3940
/// Application configuration loaded from disk and merged with overrides.
4041
#[derive(Debug, Clone, PartialEq)]
4142
pub struct Config {
@@ -164,7 +165,7 @@ pub struct Config {
164165
pub include_apply_patch_tool: bool,
165166

166167
/// The value for the `originator` header included with Responses API requests.
167-
pub internal_originator: Option<String>,
168+
pub responses_originator_header: String,
168169

169170
/// If set to `true`, the API key will be signed with the `originator` header.
170171
pub preferred_auth_method: AuthMode,
@@ -411,7 +412,7 @@ pub struct ConfigToml {
411412
pub experimental_instructions_file: Option<PathBuf>,
412413

413414
/// The value for the `originator` header included with Responses API requests.
414-
pub internal_originator: Option<String>,
415+
pub responses_originator_header_internal_override: Option<String>,
415416

416417
pub projects: Option<HashMap<String, ProjectConfig>>,
417418

@@ -626,9 +627,9 @@ impl Config {
626627
let include_apply_patch_tool_val =
627628
include_apply_patch_tool.unwrap_or(model_family.uses_apply_patch_tool);
628629

629-
let originator = std::env::var(CODEX_ORIGINATOR_ENV_VAR)
630-
.ok()
631-
.or(cfg.internal_originator);
630+
let responses_originator_header: String = cfg
631+
.responses_originator_header_internal_override
632+
.unwrap_or(DEFAULT_RESPONSES_ORIGINATOR_HEADER.to_owned());
632633

633634
let config = Self {
634635
model,
@@ -683,7 +684,7 @@ impl Config {
683684
experimental_resume,
684685
include_plan_tool: include_plan_tool.unwrap_or(false),
685686
include_apply_patch_tool: include_apply_patch_tool_val,
686-
internal_originator: originator,
687+
responses_originator_header,
687688
preferred_auth_method: cfg.preferred_auth_method.unwrap_or(AuthMode::ChatGPT),
688689
};
689690
Ok(config)
@@ -1048,7 +1049,7 @@ disable_response_storage = true
10481049
base_instructions: None,
10491050
include_plan_tool: false,
10501051
include_apply_patch_tool: false,
1051-
internal_originator: None,
1052+
responses_originator_header: "codex_cli_rs".to_string(),
10521053
preferred_auth_method: AuthMode::ChatGPT,
10531054
},
10541055
o3_profile_config
@@ -1101,7 +1102,7 @@ disable_response_storage = true
11011102
base_instructions: None,
11021103
include_plan_tool: false,
11031104
include_apply_patch_tool: false,
1104-
internal_originator: None,
1105+
responses_originator_header: "codex_cli_rs".to_string(),
11051106
preferred_auth_method: AuthMode::ChatGPT,
11061107
};
11071108

@@ -1169,7 +1170,7 @@ disable_response_storage = true
11691170
base_instructions: None,
11701171
include_plan_tool: false,
11711172
include_apply_patch_tool: false,
1172-
internal_originator: None,
1173+
responses_originator_header: "codex_cli_rs".to_string(),
11731174
preferred_auth_method: AuthMode::ChatGPT,
11741175
};
11751176

codex-rs/core/src/spawn.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,6 @@ pub const CODEX_SANDBOX_NETWORK_DISABLED_ENV_VAR: &str = "CODEX_SANDBOX_NETWORK_
2222
/// accommodate sandboxing configuration and other sandboxing mechanisms.
2323
pub const CODEX_SANDBOX_ENV_VAR: &str = "CODEX_SANDBOX";
2424

25-
/// Set this to change the originator sent with all network requests.
26-
pub const CODEX_ORIGINATOR_ENV_VAR: &str = "CODEX_ORIGINATOR";
27-
2825
#[derive(Debug, Clone, Copy)]
2926
pub enum StdioPolicy {
3027
RedirectForShellTool,

codex-rs/core/tests/client.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ async fn originator_config_override_is_used() {
260260
let codex_home = TempDir::new().unwrap();
261261
let mut config = load_default_config_for_test(&codex_home);
262262
config.model_provider = model_provider;
263-
config.internal_originator = Some("my_override".to_string());
263+
config.responses_originator_header = "my_override".to_owned();
264264

265265
let conversation_manager = ConversationManager::default();
266266
let codex = conversation_manager

0 commit comments

Comments
 (0)