From e2bd9311c9bdb6c7c055ac9128038be5d25803b0 Mon Sep 17 00:00:00 2001 From: Max Kong Date: Sat, 24 Jan 2026 13:23:37 -0500 Subject: [PATCH] fix(windows-sandbox): remove request files after read (#9316) ## Summary - Remove elevated runner request files after read (best-effort cleanup on errors) - Add a unit test to cover request file lifecycle ## Testing - `cargo test -p codex-windows-sandbox` (Windows) Fixes #9315 --- .../src/command_runner_win.rs | 28 ++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/codex-rs/windows-sandbox-rs/src/command_runner_win.rs b/codex-rs/windows-sandbox-rs/src/command_runner_win.rs index 173939990..a016c00c7 100644 --- a/codex-rs/windows-sandbox-rs/src/command_runner_win.rs +++ b/codex-rs/windows-sandbox-rs/src/command_runner_win.rs @@ -16,6 +16,7 @@ use codex_windows_sandbox::SandboxPolicy; use serde::Deserialize; use std::collections::HashMap; use std::ffi::c_void; +use std::path::Path; use std::path::PathBuf; use windows_sys::Win32::Foundation::CloseHandle; use windows_sys::Win32::Foundation::GetLastError; @@ -78,13 +79,20 @@ unsafe fn create_job_kill_on_close() -> Result { Ok(h) } +fn read_request_file(req_path: &Path) -> Result { + let content = std::fs::read_to_string(req_path) + .with_context(|| format!("read request file {}", req_path.display())); + let _ = std::fs::remove_file(req_path); + content +} + pub fn main() -> Result<()> { let mut input = String::new(); let mut args = std::env::args().skip(1); if let Some(first) = args.next() { if let Some(rest) = first.strip_prefix("--request-file=") { let req_path = PathBuf::from(rest); - input = std::fs::read_to_string(&req_path).context("read request file")?; + input = read_request_file(&req_path)?; } } if input.is_empty() { @@ -265,3 +273,21 @@ pub fn main() -> Result<()> { } std::process::exit(exit_code); } + +#[cfg(test)] +mod tests { + use super::read_request_file; + use pretty_assertions::assert_eq; + use std::fs; + + #[test] + fn removes_request_file_after_read() { + let dir = tempfile::tempdir().expect("tempdir"); + let req_path = dir.path().join("request.json"); + fs::write(&req_path, "{\"ok\":true}").expect("write request"); + + let content = read_request_file(&req_path).expect("read request"); + assert_eq!(content, "{\"ok\":true}"); + assert!(!req_path.exists(), "request file should be removed"); + } +}