Files
codex/codex-rs/mxc-sandbox/src/native.rs
T
iceweasel-oai 739f934a15 Add Windows MXC sandbox launch diagnostics (#62439)
## Why

Launch errors and timeouts can be hard to diagnose without knowing which
stage the launcher reached or how long each stage took.

## What changed

Log MXC launch phases by process ID in the Windows sandbox runtime log.
Distinguish filesystem helper launches from regular commands and record
filesystem grant counts, preparation, spawn, and wait durations, and
launch outcomes or errors.

Reuse the runtime log's rolling file appender across entries in the same
launcher process.

GitOrigin-RevId: 8d55261fc9efeab8afe4b5be67b5aacb6868f3da
2026-11-19 06:18:44 +00:00

33 lines
1.2 KiB
Rust

//! Run an already prepared MXC request with inherited stdio and job ownership.
use std::time::Instant;
use crate::windows::log_launch;
use anyhow::Context;
use anyhow::Result;
use mxc_sdk::v1;
// The ETW functions used by tracelogging are documented Advapi32 exports on
// both Windows toolchains; 1.2.3 leaves their import library to the application.
#[link(name = "advapi32")]
unsafe extern "system" {}
pub(super) fn launch(request: v1::ContainerRequest) -> Result<i32> {
let mut options = v1::SpawnExtendedOptions::default();
options.stdio = v1::SpawnStdio::Inherit;
let spawning = Instant::now();
let mut child = v1::spawn_with_extended_options(request, options)?;
let spawn_ms = spawning.elapsed().as_millis();
log_launch(format_args!("phase=wait spawn_ms={spawn_ms}"));
let waiting = Instant::now();
let outcome = child.wait().context("waiting for the MXC command")?;
let wait_ms = waiting.elapsed().as_millis();
log_launch(format_args!(
"phase=finished outcome={outcome:?} wait_ms={wait_ms}"
));
match outcome {
v1::WaitResult::Exited(code) => Ok(code),
v1::WaitResult::TimedOut => anyhow::bail!("MXC command timed out"),
}
}