From 5cac3f896d74c5738e252bb3672e03565a30c815 Mon Sep 17 00:00:00 2001 From: iceweasel-oai Date: Wed, 29 Apr 2026 02:59:45 -0700 Subject: [PATCH] Fix Windows pseudoconsole attribute handling for sandboxed PTY sessions (#20042) ## Summary Fix the Windows sandbox PTY spawn path to pass the pseudoconsole handle value directly into `UpdateProcThreadAttribute`. ## Why Sandboxed `unified_exec` PTY sessions on Windows were failing during child process startup with `0xc0000142` (`STATUS_DLL_INIT_FAILED`). In practice this showed up as PowerShell DLL init popups when the sandboxed background-terminal path tried to launch an interactive shell. The root cause was that we were passing a pointer to a local `isize` variable instead of the pseudoconsole handle value in the form Windows expects for `PROC_THREAD_ATTRIBUTE_PSEUDOCONSOLE`. ## Validation - `cargo build -p codex-windows-sandbox --bins` - Reproduced the real sandboxed `codex exec` flow with `windows.sandbox_private_desktop=true` - Verified a `tty=true` interactive session launched through the normal PowerShell wrapper, printed `READY`, accepted follow-up stdin, and exited cleanly - Confirmed no new `0xc0000142` / `Application Popup` events appeared after the successful repro --- codex-rs/windows-sandbox-rs/src/proc_thread_attr.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/codex-rs/windows-sandbox-rs/src/proc_thread_attr.rs b/codex-rs/windows-sandbox-rs/src/proc_thread_attr.rs index 7641bb5ed..b81469983 100644 --- a/codex-rs/windows-sandbox-rs/src/proc_thread_attr.rs +++ b/codex-rs/windows-sandbox-rs/src/proc_thread_attr.rs @@ -1,3 +1,4 @@ +use std::ffi::c_void; use std::io; use windows_sys::Win32::Foundation::GetLastError; use windows_sys::Win32::Foundation::HANDLE; @@ -45,14 +46,13 @@ impl ProcThreadAttributeList { pub fn set_pseudoconsole(&mut self, hpc: isize) -> io::Result<()> { let list = self.as_mut_ptr(); - let mut hpc_value = hpc; let ok = unsafe { UpdateProcThreadAttribute( list, 0, PROC_THREAD_ATTRIBUTE_PSEUDOCONSOLE, - (&mut hpc_value as *mut isize).cast(), - std::mem::size_of::(), + hpc as *mut c_void, + std::mem::size_of::(), std::ptr::null_mut(), std::ptr::null_mut(), )