Skip to content

Commit 50d9c5d

Browse files
etraut-openaicopyberry
authored andcommitted
Run piped legacy Windows sandbox processes without a console (#49308)
## What changed Use `ConsoleMode::NoWindow` for legacy Windows sandbox capture and non-TTY unified execution, enabling `CREATE_NO_WINDOW` for these piped processes. ## Testing Extend the PowerShell interrupt and capture tests to assert that `GetConsoleWindow()` returns null before checking process termination and descendant survival. GitOrigin-RevId: dcc3b5554986ab0280748e5fa7080d36ded3d673
1 parent c2837d8 commit 50d9c5d

3 files changed

Lines changed: 6 additions & 4 deletions

File tree

‎codex-rs/windows-sandbox-rs/src/lib.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -764,7 +764,7 @@ mod windows_impl {
764764
&env_map,
765765
logs_base_dir,
766766
Some((in_r, out_w, err_w)),
767-
ConsoleMode::Inherit,
767+
ConsoleMode::NoWindow,
768768
desktop,
769769
)
770770
});

‎codex-rs/windows-sandbox-rs/src/unified_exec/backends/legacy.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ fn spawn_legacy_process(
115115
StdinMode::Closed
116116
},
117117
StderrMode::Separate,
118-
ConsoleMode::Inherit,
118+
ConsoleMode::NoWindow,
119119
launch_desktop,
120120
logs_base_dir,
121121
)?;

‎codex-rs/windows-sandbox-rs/src/unified_exec/tests.rs‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ use windows_sys::Win32::System::Threading::WaitForSingleObject;
5050
static TEST_HOME_COUNTER: AtomicU64 = AtomicU64::new(0);
5151
static LEGACY_PROCESS_TEST_LOCK: Mutex<()> = Mutex::new(());
5252

53+
const ASSERT_NO_CONSOLE: &str = r#"Add-Type -ErrorAction Stop 'using System; using System.Runtime.InteropServices; public class ConsoleProbe { [DllImport("kernel32.dll")] public static extern IntPtr GetConsoleWindow(); }'; if ([ConsoleProbe]::GetConsoleWindow() -ne [IntPtr]::Zero) { throw 'piped sandbox process unexpectedly has a console' };"#;
54+
5355
fn legacy_process_test_guard() -> MutexGuard<'static, ()> {
5456
LEGACY_PROCESS_TEST_LOCK
5557
.lock()
@@ -460,7 +462,7 @@ fn legacy_non_tty_powershell_interrupt_terminates_process() {
460462
pwsh.display().to_string(),
461463
"-NoProfile".to_string(),
462464
"-Command".to_string(),
463-
"Write-Output LEGACY-NONTTY-DIRECT; [System.Threading.ManualResetEvent]::new($false).WaitOne()".to_string(),
465+
format!("{ASSERT_NO_CONSOLE} Write-Output LEGACY-NONTTY-DIRECT; [System.Threading.ManualResetEvent]::new($false).WaitOne()"),
464466
],
465467
cwd.as_path(),
466468
HashMap::new(),
@@ -681,7 +683,7 @@ fn legacy_capture_emits_output_and_preserves_descendant_after_normal_exit() {
681683
powershell_literal(&ready_marker),
682684
);
683685
let parent_command = format!(
684-
"Write-Output LEGACY-CAPTURE-DIRECT; {}",
686+
"{ASSERT_NO_CONSOLE} Write-Output LEGACY-CAPTURE-DIRECT; {}",
685687
start_powershell_child(&pwsh, codex_home.path(), &descendant_command, &parent_tail,),
686688
);
687689
let permission_profile = PermissionProfile::workspace_write();

0 commit comments

Comments
 (0)