From 1fdfdcd580e6c15081d912cb1f2109b73403a00b Mon Sep 17 00:00:00 2001 From: David Wiesen Date: Thu, 23 Apr 2026 09:50:56 -0700 Subject: [PATCH] Improve Windows sandbox helper cancel error --- .../src/setup_orchestrator.rs | 27 ++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/codex-rs/windows-sandbox-rs/src/setup_orchestrator.rs b/codex-rs/windows-sandbox-rs/src/setup_orchestrator.rs index 4effc0b70d..65f0fdf4ed 100644 --- a/codex-rs/windows-sandbox-rs/src/setup_orchestrator.rs +++ b/codex-rs/windows-sandbox-rs/src/setup_orchestrator.rs @@ -59,6 +59,14 @@ const WINDOWS_PLATFORM_DEFAULT_READ_ROOTS: &[&str] = &[ r"C:\ProgramData", ]; +fn setup_helper_launch_failure_message(last_error: u32) -> String { + if last_error == ERROR_CANCELLED { + "Windows canceled the sandbox setup helper launch (error 1223). This usually means the UAC elevation prompt was dismissed or denied before the helper could start.".to_string() + } else { + format!("ShellExecuteExW failed to launch setup helper: {last_error}") + } +} + pub fn sandbox_dir(codex_home: &Path) -> PathBuf { codex_home.join(".sandbox") } @@ -708,7 +716,7 @@ fn run_setup_exe( }; return Err(failure( code, - format!("ShellExecuteExW failed to launch setup helper: {last_error}"), + setup_helper_launch_failure_message(last_error), )); } unsafe { @@ -1024,6 +1032,23 @@ mod tests { ); } + #[test] + fn canceled_helper_launch_message_mentions_uac() { + let message = super::setup_helper_launch_failure_message(super::ERROR_CANCELLED); + + assert!(message.contains("1223")); + assert!(message.contains("UAC")); + assert!(message.contains("dismissed or denied")); + } + + #[test] + fn generic_helper_launch_message_preserves_error_code() { + assert_eq!( + super::setup_helper_launch_failure_message(5), + "ShellExecuteExW failed to launch setup helper: 5" + ); + } + #[test] fn profile_read_roots_excludes_configured_top_level_entries() { let tmp = TempDir::new().expect("tempdir");