From f35fad1f56e396972efe83d9e2a6a54719e21b9b Mon Sep 17 00:00:00 2001 From: David Wiesen Date: Tue, 5 May 2026 09:57:34 -0700 Subject: [PATCH] fix(windows): launch sandbox refresh from stable cwd --- .../src/setup_orchestrator.rs | 29 +++++++++++++++++-- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/codex-rs/windows-sandbox-rs/src/setup_orchestrator.rs b/codex-rs/windows-sandbox-rs/src/setup_orchestrator.rs index ef952a4e03..937d69b902 100644 --- a/codex-rs/windows-sandbox-rs/src/setup_orchestrator.rs +++ b/codex-rs/windows-sandbox-rs/src/setup_orchestrator.rs @@ -156,6 +156,19 @@ pub fn run_setup_refresh_with_extra_read_roots( ) } +fn setup_refresh_spawn_cwd(codex_home: &Path) -> PathBuf { + std::env::current_dir().unwrap_or_else(|_| codex_home.to_path_buf()) +} + +fn build_setup_refresh_command(exe: &Path, payload_b64: &str, cwd: &Path) -> Command { + let mut cmd = Command::new(exe); + cmd.arg(payload_b64) + .current_dir(cwd) + .stdout(Stdio::null()) + .stderr(Stdio::null()); + cmd +} + fn run_setup_refresh_inner( request: SandboxSetupRequest<'_>, overrides: SetupRootOverrides, @@ -191,9 +204,8 @@ fn run_setup_refresh_inner( let b64 = BASE64_STANDARD.encode(json); let exe = find_setup_exe(); // Refresh should never request elevation; ensure verb isn't set and we don't trigger UAC. - let mut cmd = Command::new(&exe); - cmd.arg(&b64).stdout(Stdio::null()).stderr(Stdio::null()); - let cwd = std::env::current_dir().unwrap_or_else(|_| request.codex_home.to_path_buf()); + let cwd = setup_refresh_spawn_cwd(request.codex_home); + let mut cmd = build_setup_refresh_command(&exe, &b64, &cwd); log_note( &format!( "setup refresh: spawning {} (cwd={}, payload_len={})", @@ -1454,4 +1466,15 @@ mod tests { .all(|path| roots.contains(&path)) ); } + + #[test] + fn setup_refresh_command_runs_from_stable_cwd() { + let exe = Path::new(r"C:\codex\codex-windows-sandbox-setup.exe"); + let cwd = Path::new(r"C:\Users\tester\.codex"); + let cmd = super::build_setup_refresh_command(exe, "payload", cwd); + + assert_eq!(cmd.get_program(), exe); + assert_eq!(cmd.get_args().collect::>(), vec!["payload"]); + assert_eq!(cmd.get_current_dir(), Some(cwd)); + } }