mirror of
https://github.com/openai/codex.git
synced 2026-10-19 17:28:46 +00:00
## Why Linux pipe launches need session, parent-death signal, and descriptor setup. Move this work into a fresh, single-threaded executable image to avoid forking the app-server for child setup. ## What changed - Register an early setup helper and launch it through `posix_spawn` for Linux pipe processes. - Start the helper with an empty environment, then transfer the target environment over a control socket so loader settings cannot interfere with helper startup. - Await target execution asynchronously, propagate setup and execution errors, and kill incomplete launches on cancellation. - Preserve direct spawning as a fallback when the helper is unavailable or fails before target execution. ## Testing Add coverage for launch semantics, avoiding fork, loader environment isolation, early argument dispatch, closed standard descriptors, and fallback under bootstrap failure or descriptor pressure. Add an app-server regression test that reuses a process handle after an execution failure. GitOrigin-RevId: 079c673f0f22ebd531f8c57e5338095cc98acfdc
41 lines
1.6 KiB
Rust
41 lines
1.6 KiB
Rust
//! Minimal exec-server fixture for Bazel-only integration tests.
|
|
//!
|
|
//! Linking only exec-server avoids depending on the full Codex CLI binary
|
|
//! when a test only needs a WebSocket executor endpoint. It handles the arg0
|
|
//! helper mode because sandboxed process requests re-exec this binary.
|
|
|
|
use codex_exec_server::ExecServerRuntimePaths;
|
|
use codex_http_client::HttpClientFactory;
|
|
use codex_http_client::OutboundProxyPolicy;
|
|
use std::ffi::OsStr;
|
|
|
|
const CODEX_LINUX_SANDBOX_EXE_ENV_VAR: &str = "CODEX_TEST_LINUX_SANDBOX_EXE";
|
|
|
|
fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
|
|
#[cfg(target_os = "linux")]
|
|
codex_utils_pty::init_spawn_helper(std::env::args_os());
|
|
let mut args = std::env::args_os();
|
|
let _ = args.next();
|
|
let argv1 = args.next();
|
|
#[cfg(unix)]
|
|
if argv1.as_deref() == Some(OsStr::new(codex_exec_server::CODEX_ARG0_EXEC_HELPER_ARG1)) {
|
|
codex_exec_server::run_arg0_exec_helper_main();
|
|
}
|
|
if argv1.as_deref() == Some(OsStr::new(codex_exec_server::CODEX_FS_HELPER_ARG1)) {
|
|
codex_exec_server::run_fs_helper_main();
|
|
}
|
|
|
|
let current_exe = std::env::current_exe()?;
|
|
let codex_linux_sandbox_exe =
|
|
std::env::var_os(CODEX_LINUX_SANDBOX_EXE_ENV_VAR).map(std::path::PathBuf::from);
|
|
let runtime_paths = ExecServerRuntimePaths::new(current_exe, codex_linux_sandbox_exe)?;
|
|
tokio::runtime::Builder::new_multi_thread()
|
|
.enable_all()
|
|
.build()?
|
|
.block_on(codex_exec_server::run_main(
|
|
"ws://127.0.0.1:0",
|
|
runtime_paths,
|
|
HttpClientFactory::new(OutboundProxyPolicy::ReqwestDefault),
|
|
))
|
|
}
|