mirror of
https://github.com/openai/codex.git
synced 2026-11-01 19:33:35 +00:00
## Why Background helpers launched from a detached Windows process can allocate console windows. Job Object launches and containment fallbacks need to preserve console suppression as well. ## What changed - Add `codex_utils_process::background_command` to set `CREATE_NO_WINDOW` on Windows, and use it across background subprocess launches, including Git, plugins, authentication, diagnostics, and sandbox helpers. - Centralize console suppression in Job Object launches. Keep `CREATE_NO_WINDOW` when retrying without containment, and clear `CREATE_SUSPENDED` so the fallback child can run. - Preserve console inheritance for interactive shell launches and interactive AWS authentication refreshes. ## Testing Add Windows regression tests covering console-free launches from detached parents through standard and Tokio commands, stdout/stderr capture, successful containment, Job Object creation and assignment failures, and sandbox setup refresh helpers. GitOrigin-RevId: b2c238fa7d4f9fbd868e5adf7d4be9958ff01e6c
27 lines
965 B
Rust
27 lines
965 B
Rust
//! Command construction for background processes that must not allocate a Windows console.
|
|
//! Callers retain control of environment, stdio, and process lifetime. Interactive,
|
|
//! detached, and private-desktop launches must select their own console policy.
|
|
|
|
use std::ffi::OsStr;
|
|
use std::process::Command;
|
|
|
|
/// Construct a background command, suppressing console allocation on Windows.
|
|
/// Convert with `tokio::process::Command::from` for asynchronous execution.
|
|
/// Subsequent Windows `creation_flags` calls must retain `CREATE_NO_WINDOW`.
|
|
pub fn background_command(program: impl AsRef<OsStr>) -> Command {
|
|
#[cfg(windows)]
|
|
{
|
|
use std::os::windows::process::CommandExt;
|
|
|
|
let mut command = Command::new(program);
|
|
command.creation_flags(/*flags*/ 0x0800_0000); // CREATE_NO_WINDOW
|
|
command
|
|
}
|
|
#[cfg(not(windows))]
|
|
Command::new(program)
|
|
}
|
|
|
|
#[cfg(all(test, windows))]
|
|
#[path = "background_command_tests.rs"]
|
|
mod tests;
|