From f35a0fdc5d5fe591fbb2cad7ca6c491c884c3b4b Mon Sep 17 00:00:00 2001 From: zm-oai Date: Tue, 29 Sep 2026 12:50:57 +0000 Subject: [PATCH] Preserve Windows sandbox runner launch errors (#49261) ## Why Restoring the error mode with `SetErrorMode` can overwrite the failure code from `CreateProcessWithLogonW`, causing `RunnerLogonError` to report the wrong error. ## What changed Capture `GetLastError()` immediately after a failed runner launch, before restoring the previous error mode, and use the saved code for `RunnerLogonError`. GitOrigin-RevId: c0f4267232306be4d06e7e8accd60f7b77b8d6f3 --- codex-rs/windows-sandbox-rs/src/elevated/runner_client.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/codex-rs/windows-sandbox-rs/src/elevated/runner_client.rs b/codex-rs/windows-sandbox-rs/src/elevated/runner_client.rs index 6f688f166d..d09aa02d53 100644 --- a/codex-rs/windows-sandbox-rs/src/elevated/runner_client.rs +++ b/codex-rs/windows-sandbox-rs/src/elevated/runner_client.rs @@ -409,11 +409,12 @@ pub(crate) fn spawn_runner_transport( &mut pi, ) }; + // Preserve the failure code before SetErrorMode can overwrite it. + let spawn_error = (spawn_res == 0).then(|| unsafe { GetLastError() }); unsafe { SetErrorMode(previous_error_mode); } - if spawn_res == 0 { - let err = unsafe { GetLastError() }; + if let Some(err) = spawn_error { return Err(RunnerLogonError { code: err }.into()); } // Keep the process pinned through the entire startup handshake. Pipes close