Record Windows MXC availability (#42094)

## What changed

- Probe whether the native Windows MXC process security environment is usable
  when selecting a sandbox.
- Emit `codex.windows_mxc.available` at most once per process, labeled with the
  probe result.
- Add the MXC workspace dependencies for Cargo and Bazel, and pin
  `tracelogging` to a version compatible with the GNU Windows toolchain.

GitOrigin-RevId: d7cfeed6f0333feda5764e1ee44fe5bbd50f9a58
This commit is contained in:
iceweasel-oai
2026-09-01 16:40:05 +00:00
committed by copyberry
parent f4e6cb7876
commit ade0ccacf9
9 changed files with 231 additions and 0 deletions
+156
View File
@@ -421,6 +421,27 @@ dependencies = [
"wiremock",
]
[[package]]
name = "appcontainer_common"
version = "0.8.0"
source = "git+https://github.com/microsoft/mxc?rev=6cd3d58f05d3447e67109cfb75e042803b843ca4#6cd3d58f05d3447e67109cfb75e042803b843ca4"
dependencies = [
"flatbuffers",
"getrandom 0.2.17",
"learning_mode_core",
"learning_mode_windows",
"process_security_environment_spec",
"sandbox_spec",
"serde",
"serde_json",
"thiserror 2.0.18",
"widestring",
"windows 0.62.2",
"windows-core 0.62.2",
"winreg 0.55.0",
"wxc_common",
]
[[package]]
name = "approx"
version = "0.5.1"
@@ -1730,6 +1751,12 @@ version = "1.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6e4de3bc4ea267985becf712dc6d9eed8b04c953b3fcfb339ebc87acd9804901"
[[package]]
name = "cidr"
version = "0.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "579504560394e388085d0c080ea587dfa5c15f7e251b4d5247d1e1a61d1d6928"
[[package]]
name = "cipher"
version = "0.4.4"
@@ -4194,7 +4221,9 @@ name = "codex-sandboxing"
version = "0.0.0"
dependencies = [
"anyhow",
"appcontainer_common",
"codex-network-proxy",
"codex-otel",
"codex-protocol",
"codex-utils-absolute-path",
"codex-utils-home-dir",
@@ -4208,6 +4237,7 @@ dependencies = [
"serde_json",
"tempfile",
"tokio",
"tracelogging",
"tracing",
"url",
"which 8.0.0",
@@ -6562,6 +6592,16 @@ version = "0.5.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1d674e81391d1e1ab681a28d99df07927c6d4aa5b027d7da16ba32d1d21ecd99"
[[package]]
name = "flatbuffers"
version = "25.12.19"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "35f6839d7b3b98adde531effaf34f0c2badc6f4735d26fe74709d8e513a96ef3"
dependencies = [
"bitflags 2.13.1",
"rustc_version",
]
[[package]]
name = "flate2"
version = "1.1.8"
@@ -9125,6 +9165,32 @@ version = "1.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe"
[[package]]
name = "learning_mode_core"
version = "0.8.0"
source = "git+https://github.com/microsoft/mxc?rev=6cd3d58f05d3447e67109cfb75e042803b843ca4#6cd3d58f05d3447e67109cfb75e042803b843ca4"
dependencies = [
"same-file",
"serde",
"serde_json",
"sha2 0.10.9",
"tempfile",
"thiserror 2.0.18",
]
[[package]]
name = "learning_mode_windows"
version = "0.8.0"
source = "git+https://github.com/microsoft/mxc?rev=6cd3d58f05d3447e67109cfb75e042803b843ca4#6cd3d58f05d3447e67109cfb75e042803b843ca4"
dependencies = [
"learning_mode_core",
"sha2 0.10.9",
"thiserror 2.0.18",
"windows 0.62.2",
"windows-core 0.62.2",
"wxc_common",
]
[[package]]
name = "leb128fmt"
version = "0.1.0"
@@ -9581,6 +9647,25 @@ dependencies = [
"serde",
]
[[package]]
name = "mxc_config_contract"
version = "0.8.0"
source = "git+https://github.com/microsoft/mxc?rev=6cd3d58f05d3447e67109cfb75e042803b843ca4#6cd3d58f05d3447e67109cfb75e042803b843ca4"
dependencies = [
"serde",
"serde_json",
"thiserror 2.0.18",
]
[[package]]
name = "mxc_telemetry"
version = "0.8.0"
source = "git+https://github.com/microsoft/mxc?rev=6cd3d58f05d3447e67109cfb75e042803b843ca4#6cd3d58f05d3447e67109cfb75e042803b843ca4"
dependencies = [
"tracelogging",
"uuid",
]
[[package]]
name = "native-tls"
version = "0.2.14"
@@ -10912,6 +10997,14 @@ dependencies = [
"windows 0.62.2",
]
[[package]]
name = "process_security_environment_spec"
version = "0.8.0"
source = "git+https://github.com/microsoft/mxc?rev=6cd3d58f05d3447e67109cfb75e042803b843ca4#6cd3d58f05d3447e67109cfb75e042803b843ca4"
dependencies = [
"flatbuffers",
]
[[package]]
name = "prodash"
version = "31.0.0"
@@ -12251,6 +12344,14 @@ dependencies = [
"winapi-util",
]
[[package]]
name = "sandbox_spec"
version = "0.8.0"
source = "git+https://github.com/microsoft/mxc?rev=6cd3d58f05d3447e67109cfb75e042803b843ca4#6cd3d58f05d3447e67109cfb75e042803b843ca4"
dependencies = [
"flatbuffers",
]
[[package]]
name = "scc"
version = "2.4.0"
@@ -14506,6 +14607,21 @@ version = "0.3.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8df9b6e13f2d32c91b9bd719c00d1958837bc7dec474d94952798cc8e69eeec3"
[[package]]
name = "tracelogging"
version = "1.2.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e4314470f3f54b29d582ff6776fceb7c819b023141828d559f19c790cee40e94"
dependencies = [
"tracelogging_macros",
]
[[package]]
name = "tracelogging_macros"
version = "1.2.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "95e2d891464ff33bc1814c4cbbb251bae7800458b1efdb6ac8b7c01ee6382563"
[[package]]
name = "tracing"
version = "0.1.44"
@@ -14852,6 +14968,12 @@ version = "2.0.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7eec5d1121208364f6793f7d2e222bf75a915c19557537745b195b253dd64217"
[[package]]
name = "unicode-general-category"
version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0b993bddc193ae5bd0d623b49ec06ac3e9312875fdae725a975c51db1cc1677f"
[[package]]
name = "unicode-ident"
version = "1.0.22"
@@ -16008,6 +16130,16 @@ dependencies = [
"windows-sys 0.48.0",
]
[[package]]
name = "winreg"
version = "0.55.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cb5a765337c50e9ec252c2069be9bf91c7df47afb103b642ba3a53bf8101be97"
dependencies = [
"cfg-if",
"windows-sys 0.59.0",
]
[[package]]
name = "winsafe"
version = "0.0.19"
@@ -16155,6 +16287,30 @@ version = "0.6.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9edde0db4769d2dc68579893f2306b26c6ecfbe0ef499b013d731b7b9247e0b9"
[[package]]
name = "wxc_common"
version = "0.8.0"
source = "git+https://github.com/microsoft/mxc?rev=6cd3d58f05d3447e67109cfb75e042803b843ca4#6cd3d58f05d3447e67109cfb75e042803b843ca4"
dependencies = [
"base64 0.22.1",
"cidr",
"getrandom 0.2.17",
"libc",
"mxc_config_contract",
"mxc_telemetry",
"semver",
"serde",
"serde_json",
"serde_path_to_error",
"thiserror 2.0.18",
"unicode-general-category",
"url",
"widestring",
"windows 0.62.2",
"windows-core 0.62.2",
"winreg 0.55.0",
]
[[package]]
name = "x11rb"
version = "0.13.2"
+1
View File
@@ -296,6 +296,7 @@ mcp_test_support = { path = "mcp-server/tests/common" }
age = "0.11.1"
ansi-to-tui = "8.0.1"
anyhow = "1"
appcontainer_common = { git = "https://github.com/microsoft/mxc", rev = "6cd3d58f05d3447e67109cfb75e042803b843ca4" }
arboard = { version = "3", features = ["wayland-data-control"] }
arc-swap = "1.9.0"
assert_cmd = "2"
+1
View File
@@ -313,6 +313,7 @@ allow-git = [
"https://github.com/dzbarsky/rules_rust",
"https://github.com/helix-editor/nucleo.git",
"https://github.com/juberti-oai/rust-sdks.git",
"https://github.com/microsoft/mxc",
"https://github.com/openai-oss-forks/crossterm",
"https://github.com/openai-oss-forks/tokio-tungstenite",
"https://github.com/openai-oss-forks/tungstenite-rs",
+8
View File
@@ -12,6 +12,10 @@ doctest = false
[lints]
workspace = true
# This direct dependency pins MXC's transitive ETW dependency for Windows GNU linking.
[package.metadata.cargo-shear]
ignored = ["tracelogging"]
[dependencies]
anyhow = { workspace = true }
codex-network-proxy = { workspace = true }
@@ -30,7 +34,11 @@ url = { workspace = true }
which = { workspace = true }
[target.'cfg(windows)'.dependencies]
appcontainer_common = { workspace = true }
codex-otel = { workspace = true }
codex-utils-home-dir = { workspace = true }
# 1.2.4 imports OneCore_apiset, which the GNU Windows toolchain does not ship.
tracelogging = "=1.2.3"
[dev-dependencies]
anyhow = { workspace = true }
+2
View File
@@ -10,6 +10,8 @@ mod spawn;
mod terminal_queries;
mod violation;
mod windows;
#[cfg(windows)]
mod windows_mxc;
#[cfg(target_os = "linux")]
pub use bwrap::find_system_bwrap_in_path;
+3
View File
@@ -301,6 +301,9 @@ impl SandboxManager {
windows_sandbox_level: WindowsSandboxLevel,
has_managed_network_requirements: bool,
) -> SandboxType {
#[cfg(windows)]
crate::windows_mxc::record_availability_once();
if self.should_sandbox(permission_profile, pref, has_managed_network_requirements) {
get_platform_sandbox(windows_sandbox_level != WindowsSandboxLevel::Disabled)
.unwrap_or(SandboxType::None)
+28
View File
@@ -0,0 +1,28 @@
//! Native Windows MXC capability discovery and availability metrics.
//! Probing is cached upstream; reporting happens at most once per process.
use appcontainer_common::base_container_runner::BaseContainerRunner;
use std::sync::atomic::AtomicBool;
use std::sync::atomic::Ordering;
static AVAILABILITY_RECORDED: AtomicBool = AtomicBool::new(false);
// tracelogging 1.2.3 leaves its ETW import library to the application. These
// APIs are exported by Advapi32 in both the MSVC and GNU Windows toolchains.
#[link(name = "advapi32")]
unsafe extern "system" {}
pub(super) fn record_availability_once() {
// Probe actual PSEC create/close support; symbol presence alone also
// succeeds on transitional Windows builds where MXC is not enabled.
let available = BaseContainerRunner::is_process_security_environment_usable();
if let Some(metrics) = codex_otel::global()
&& !AVAILABILITY_RECORDED.swap(true, Ordering::Relaxed)
{
let _ = metrics.counter(
"codex.windows_mxc.available",
/*inc*/ 1,
&[("available", if available { "true" } else { "false" })],
);
}
}