From c9c5d694c90895ff246f540c13baaf57a7f2570b Mon Sep 17 00:00:00 2001 From: Dylan Hurd Date: Mon, 3 Nov 2025 20:54:39 -0800 Subject: [PATCH] OnceLock --- codex-rs/core/src/environment_context.rs | 11 ++++++++--- codex-rs/core/tests/suite/prompt_caching.rs | 5 ++--- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/codex-rs/core/src/environment_context.rs b/codex-rs/core/src/environment_context.rs index ac7e36f0a5..75c6009b7b 100644 --- a/codex-rs/core/src/environment_context.rs +++ b/codex-rs/core/src/environment_context.rs @@ -256,9 +256,14 @@ fn operating_system_info_impl() -> Option { #[cfg(not(target_os = "macos"))] fn has_wsl_env_markers() -> bool { - std::env::var_os("WSL_INTEROP").is_some() - || std::env::var_os("WSLENV").is_some() - || std::env::var_os("WSL_DISTRO_NAME").is_some() + // Cache detection result since env vars are stable across process lifetime + // and this function may be called multiple times. + static CACHE: std::sync::OnceLock = std::sync::OnceLock::new(); + *CACHE.get_or_init(|| { + std::env::var_os("WSL_INTEROP").is_some() + || std::env::var_os("WSLENV").is_some() + || std::env::var_os("WSL_DISTRO_NAME").is_some() + }) } #[cfg(test)] diff --git a/codex-rs/core/tests/suite/prompt_caching.rs b/codex-rs/core/tests/suite/prompt_caching.rs index 7797e6cf09..e4d1998663 100644 --- a/codex-rs/core/tests/suite/prompt_caching.rs +++ b/codex-rs/core/tests/suite/prompt_caching.rs @@ -77,12 +77,11 @@ fn default_env_context_str(cwd: &str, shell: &Shell) -> String { let os_block = operating_system_context_block(); format!( r#" - {} + {cwd} on-request read-only restricted -{}{}"#, - cwd, shell_line, os_block +{shell_line}{os_block}"# ) }