Lightweight coding agent that runs in your terminal
Rust
Honor request PATH in exec-server shell snapshots (#39917)
jifff0e95007cca
diff --git a/codex-rs/exec-server-protocol/src/protocol.rs b/codex-rs/exec-server-protocol/src/protocol.rsindex ad557d8de6..d55b29ef75 100644--- a/codex-rs/exec-server-protocol/src/protocol.rs+++ b/codex-rs/exec-server-protocol/src/protocol.rs@@ -269,9 +269,6 @@ pub struct ShellSnapshotRequest {pub scope_id: String,/// Executor-native shell used to capture and restore the snapshot.pub shell: ShellInfo,- /// Runtime-owned PATH entries to replay after restoring profile state.- #[serde(default, skip_serializing_if = "Vec::is_empty")]- pub runtime_path_prepends: Vec<String>,}#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]diff --git a/codex-rs/exec-server/src/shell_snapshot.rs b/codex-rs/exec-server/src/shell_snapshot.rsindex f85ca4a2c5..495b3e8213 100644--- a/codex-rs/exec-server/src/shell_snapshot.rs+++ b/codex-rs/exec-server/src/shell_snapshot.rs@@ -132,15 +132,9 @@ impl ShellSnapshotCache {return Ok(());};- let restore_snapshot_path = snapshot.environment.contains_key("PATH")- && params- .env_policy- .as_ref()- .is_none_or(|policy| !policy.r#set.contains_key("PATH"));let request_overrides = params.env.iter()- .filter(|(name, _)| name.as_str() != "PATH" || !restore_snapshot_path).map(|(name, value)| {(name.clone(),@@ -155,20 +149,6 @@ impl ShellSnapshotCache {.map(|(name, value)| (name.clone(), value.clone())),);prepared.env.extend(request_overrides);- if restore_snapshot_path && let Some(path) = prepared.env.get_mut("PATH") {- for entry in &request.runtime_path_prepends {- if entry.is_empty() {- continue;- }- *path = std::iter::once(entry.as_str())- .chain(- path.split(':')- .filter(|existing| !existing.is_empty() && *existing != entry),- )- .collect::<Vec<_>>()- .join(":");- }- }prepared.env.retain(|name, _| !shell_environment::is_non_inheritable_env_var(name));diff --git a/codex-rs/exec-server/tests/exec_process.rs b/codex-rs/exec-server/tests/exec_process.rsindex 4f1126a097..32a9f527e8 100644--- a/codex-rs/exec-server/tests/exec_process.rs+++ b/codex-rs/exec-server/tests/exec_process.rs@@ -141,8 +141,6 @@ async fn shell_snapshot_v2_filters_profile_exports_and_stays_in_memory(let profile_path = home.path().join(profile_name);let profile_path_entry = home.path().join("profile-bin");let runtime_path_entry = home.path().join("runtime-bin");- let inherited_path = std::env::var("PATH")?;- let runtime_path = format!("{}:{inherited_path}", runtime_path_entry.display());let padding = if !use_remote && !tty && shell_name == "bash" {format!("snapshot_padding() {{ printf '%s' '{}'; }}\n",@@ -190,7 +188,8 @@ async fn shell_snapshot_v2_filters_profile_exports_and_stays_in_memory(("profile_helper; ", "helper")};let command = format!(- "{command_prefix}printf '|%s|%s|%s|%s|%s|%s' \"$PROFILE_ALLOWED\" \"${{PROFILE_SECRET-missing}}\" \"${{PROFILE_DENIED-missing}}\" \"$PATH\" \"${{__CODEX_SHELL_SNAPSHOT_STATE_0-missing}}\" \"${{__CODEX_SHELL_SNAPSHOT_STATE_1-missing}}\""+ "export PATH='{}':\"$PATH\"; {command_prefix}printf '|%s|%s|%s|%s|%s|%s' \"$PROFILE_ALLOWED\" \"${{PROFILE_SECRET-missing}}\" \"${{PROFILE_DENIED-missing}}\" \"$PATH\" \"${{__CODEX_SHELL_SNAPSHOT_STATE_0-missing}}\" \"${{__CODEX_SHELL_SNAPSHOT_STATE_1-missing}}\"",+ runtime_path_entry.display(),);let expected_stdout = format!("{expected_prefix}|profile|missing|missing|{}:{}:/usr/bin:/bin|missing|missing",@@ -212,9 +211,8 @@ async fn shell_snapshot_v2_filters_profile_exports_and_stays_in_memory(name: shell_name.to_string(),path: shell_path.to_string(),},- runtime_path_prepends: vec![runtime_path_entry.to_string_lossy().into_owned()],}),- env: HashMap::from([("PATH".to_string(), runtime_path.clone())]),+ env: HashMap::new(),tty,pipe_stdin: false,arg0: None,@@ -293,7 +291,6 @@ async fn shell_snapshot_v2_remote_managed_proxy_uses_prepared_execution_context(name: "bash".to_string(),path: "/bin/bash".to_string(),},- runtime_path_prepends: Vec::new(),}),env: HashMap::new(),tty: false,@@ -362,7 +359,6 @@ async fn shell_snapshot_v2_capture_failure_falls_back_to_original_command() -> Rname: "bash".to_string(),path: "/bin/bash".to_string(),},- runtime_path_prepends: Vec::new(),}),env: HashMap::new(),tty: false,