mirror of
https://github.com/openai/codex.git
synced 2026-11-17 22:10:37 +00:00
Log Windows MXC deny-read glob expansion timings (#61931)
## What changed Record elapsed milliseconds, pattern count, scan root count, and `glob_scan_max_depth` when expanding deny-read globs on Windows. Pass the host's resolved Codex home directory to the MXC launcher and initialize runtime sandbox logging from it, so the log location does not depend on the workload's `CODEX_HOME` environment variable. GitOrigin-RevId: c8106cdb34ea467702f4efd24f3930a8656321d9
This commit is contained in:
@@ -20,6 +20,9 @@ use anyhow::Result;
|
||||
use anyhow::ensure;
|
||||
use codex_network_proxy::ManagedNetworkSandboxContext;
|
||||
use codex_protocol::models::PermissionProfile;
|
||||
use codex_utils_absolute_path::AbsolutePathBuf;
|
||||
#[cfg(windows)]
|
||||
use codex_utils_absolute_path::AbsolutePathBufGuard;
|
||||
use codex_windows_sandbox::environment_transport;
|
||||
use serde::Deserialize;
|
||||
use serde::Serialize;
|
||||
@@ -91,7 +94,21 @@ pub fn create_command_args(args: CreateMxcCommandArgsParams<'_>) -> Result<Vec<S
|
||||
},
|
||||
env,
|
||||
)?;
|
||||
Ok(vec![CODEX_WINDOWS_MXC_ARG1.to_owned()])
|
||||
// The workload environment can omit or override the host's CODEX_HOME.
|
||||
#[cfg(windows)]
|
||||
let codex_home = match std::env::var("CODEX_HOME").as_deref() {
|
||||
Ok(home) if !home.is_empty() => std::fs::canonicalize(home)
|
||||
.ok()
|
||||
.filter(|home| home.is_dir()),
|
||||
_ => AbsolutePathBufGuard::home_directory().map(|home| home.join(".codex")),
|
||||
}
|
||||
.and_then(|home| AbsolutePathBuf::from_absolute_path(home).ok());
|
||||
#[cfg(not(windows))]
|
||||
let codex_home: Option<AbsolutePathBuf> = None;
|
||||
Ok(std::iter::once(CODEX_WINDOWS_MXC_ARG1)
|
||||
.chain(codex_home.as_deref().and_then(Path::to_str))
|
||||
.map(str::to_owned)
|
||||
.collect())
|
||||
}
|
||||
|
||||
/// Whether the executor can create a native MXC process security environment.
|
||||
@@ -113,7 +130,7 @@ pub fn is_available() -> bool {
|
||||
pub fn prepare_file_system_policy(
|
||||
policy: codex_protocol::permissions::FileSystemSandboxPolicy,
|
||||
env: &HashMap<String, String>,
|
||||
policy_cwd: &codex_utils_absolute_path::AbsolutePathBuf,
|
||||
policy_cwd: &AbsolutePathBuf,
|
||||
command_cwd: &Path,
|
||||
) -> Result<codex_protocol::permissions::FileSystemSandboxPolicy> {
|
||||
use codex_utils_path_uri::PathUri;
|
||||
|
||||
@@ -189,7 +189,8 @@ fn wrapper_preserves_exact_argv_and_separate_command_cwd() -> Result<()> {
|
||||
managed_network: None,
|
||||
env: &mut env,
|
||||
})?;
|
||||
assert_eq!(wrapped, vec![crate::CODEX_WINDOWS_MXC_ARG1]);
|
||||
assert_eq!(wrapped[0], crate::CODEX_WINDOWS_MXC_ARG1);
|
||||
assert!(wrapped.len() == 1 || (cfg!(windows) && wrapped.len() == 2));
|
||||
let parsed = crate::transport::decode(&mut env)?;
|
||||
assert!(parsed.default_child_env);
|
||||
assert!(env.is_empty());
|
||||
|
||||
@@ -31,6 +31,9 @@ impl Drop for ComUninitializeGuard {
|
||||
}
|
||||
|
||||
pub(super) fn run() -> Result<i32> {
|
||||
if let Some(codex_home) = std::env::args_os().nth(2) {
|
||||
codex_windows_sandbox::init_runtime_log(Path::new(&codex_home));
|
||||
}
|
||||
ensure!(
|
||||
crate::is_available(),
|
||||
"native MXC is unavailable on this Windows build"
|
||||
|
||||
@@ -10,6 +10,8 @@ use ignore::overrides::OverrideBuilder;
|
||||
use std::collections::HashSet;
|
||||
use std::path::Path;
|
||||
use std::path::PathBuf;
|
||||
#[cfg(windows)]
|
||||
use std::time::Instant;
|
||||
|
||||
#[derive(Debug, Eq, PartialEq)]
|
||||
struct GlobScanPlan {
|
||||
@@ -68,6 +70,8 @@ fn expand_deny_read_paths(
|
||||
return Ok(paths);
|
||||
}
|
||||
|
||||
#[cfg(windows)]
|
||||
let started = Instant::now();
|
||||
let glob_policy = FileSystemSandboxPolicy::restricted(
|
||||
unreadable_globs
|
||||
.iter()
|
||||
@@ -86,6 +90,8 @@ fn expand_deny_read_paths(
|
||||
};
|
||||
|
||||
let scan_plans = glob_scan_plans(unreadable_globs, glob_scan_max_depth)?;
|
||||
#[cfg(windows)]
|
||||
let roots = scan_plans.len();
|
||||
|
||||
for scan_plan in scan_plans {
|
||||
if !scan_plan.root.exists() {
|
||||
@@ -141,6 +147,14 @@ fn expand_deny_read_paths(
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(windows)]
|
||||
{
|
||||
let elapsed_ms = started.elapsed().as_millis();
|
||||
let patterns = unreadable_globs.len();
|
||||
crate::log_runtime_note(&format!(
|
||||
"MXC deny glob expansion elapsed_ms={elapsed_ms} patterns={patterns} roots={roots} glob_scan_max_depth={glob_scan_max_depth:?}"
|
||||
));
|
||||
}
|
||||
Ok(paths)
|
||||
}
|
||||
|
||||
|
||||
@@ -331,17 +331,17 @@ pub use ipc_framed::read_frame;
|
||||
#[cfg(target_os = "windows")]
|
||||
pub use ipc_framed::write_frame;
|
||||
#[cfg(target_os = "windows")]
|
||||
pub use logging::current_log_file_path;
|
||||
#[cfg(target_os = "windows")]
|
||||
pub use logging::current_log_file_path_for_codex_home;
|
||||
#[cfg(target_os = "windows")]
|
||||
pub use logging::log_file_path_for_utc_date;
|
||||
#[cfg(target_os = "windows")]
|
||||
pub use logging::log_note;
|
||||
#[cfg(target_os = "windows")]
|
||||
pub use logging::log_writer;
|
||||
#[cfg(target_os = "windows")]
|
||||
pub use logging::setup_log_writer;
|
||||
#[rustfmt::skip]
|
||||
pub use logging::{
|
||||
current_log_file_path,
|
||||
current_log_file_path_for_codex_home,
|
||||
init_runtime_log,
|
||||
log_file_path_for_utc_date,
|
||||
log_note,
|
||||
log_runtime_note,
|
||||
log_writer,
|
||||
setup_log_writer,
|
||||
};
|
||||
#[cfg(target_os = "windows")]
|
||||
pub use no_reparse_dir::DirectoryOpenDisposition;
|
||||
#[cfg(target_os = "windows")]
|
||||
|
||||
@@ -20,6 +20,14 @@ pub const MAX_LOG_FILES: usize = 90;
|
||||
// Service provisioning never appends to a caller-controlled existing log entry.
|
||||
// An initialized but empty slot also prevents falling back after an open failure.
|
||||
static SETUP_LOG: OnceLock<Mutex<Option<(File, OwnedHandle)>>> = OnceLock::new();
|
||||
static RUNTIME_LOG_DIR: OnceLock<PathBuf> = OnceLock::new();
|
||||
|
||||
/// Set the default sandbox log directory for this launcher process.
|
||||
pub fn init_runtime_log(codex_home: &Path) {
|
||||
if codex_home.is_absolute() {
|
||||
let _ = RUNTIME_LOG_DIR.set(crate::sandbox_dir(codex_home));
|
||||
}
|
||||
}
|
||||
|
||||
fn exe_label() -> &'static str {
|
||||
static LABEL: OnceLock<String> = OnceLock::new();
|
||||
@@ -145,6 +153,13 @@ pub fn log_note(msg: &str, base_dir: Option<&Path>) {
|
||||
append_line(&format!("[{ts} {}] {}", exe_label(), msg), base_dir);
|
||||
}
|
||||
|
||||
/// Log a note in a launcher process configured with a sandbox log directory.
|
||||
pub fn log_runtime_note(msg: &str) {
|
||||
if let Some(dir) = RUNTIME_LOG_DIR.get() {
|
||||
log_note(msg, Some(dir));
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
Reference in New Issue
Block a user