From 55c1bea00b26693bb6fd727bf989b4de6cd6b4ef Mon Sep 17 00:00:00 2001 From: David Wiesen Date: Mon, 29 Jun 2026 21:21:16 -0700 Subject: [PATCH] Improve windows sandbox refresh errors --- .../src/bin/setup_main/win.rs | 26 ++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/codex-rs/windows-sandbox-rs/src/bin/setup_main/win.rs b/codex-rs/windows-sandbox-rs/src/bin/setup_main/win.rs index e1146987bf..b9e64d397c 100644 --- a/codex-rs/windows-sandbox-rs/src/bin/setup_main/win.rs +++ b/codex-rs/windows-sandbox-rs/src/bin/setup_main/win.rs @@ -122,6 +122,14 @@ fn log_line(log: &mut dyn Write, msg: &str) -> Result<()> { Ok(()) } +fn refresh_failure(refresh_errors: &[String]) -> SetupFailure { + let detail = refresh_errors.join("; "); + SetupFailure::new( + SetupErrorCode::HelperSandboxLockFailed, + format!("setup refresh had errors: {detail}"), + ) +} + fn workspace_write_cap_sids_for_path( codex_home: &Path, command_cwd: &Path, @@ -1026,7 +1034,7 @@ fn run_setup_full(payload: &Payload, log: &mut dyn Write, sbx_dir: &Path) -> Res log, &format!("setup refresh completed with errors: {refresh_errors:?}"), )?; - anyhow::bail!("setup refresh had errors"); + return Err(anyhow::Error::new(refresh_failure(&refresh_errors))); } log_note("setup binary completed", Some(sbx_dir)); Ok(()) @@ -1036,7 +1044,9 @@ fn run_setup_full(payload: &Payload, log: &mut dyn Write, sbx_dir: &Path) -> Res mod tests { use super::Payload; use super::SETUP_VERSION; + use super::refresh_failure; use super::workspace_write_cap_sids_for_path; + use codex_windows_sandbox::SetupErrorCode; use codex_otel::StatsigMetricsSettings; use codex_windows_sandbox::load_or_create_cap_sids; use codex_windows_sandbox::workspace_write_cap_sid_for_root; @@ -1189,4 +1199,18 @@ mod tests { assert_eq!(deny_sids, vec![workspace_sid, nested_sid]); } + + #[test] + fn refresh_failure_preserves_acl_error_details() { + let failure = refresh_failure(&[ + "write ACE failed on C:\\workspace: SetNamedSecurityInfoW failed: 5".to_string(), + "deny ACE failed on C:\\workspace\\.git: Access is denied.".to_string(), + ]); + + assert_eq!(failure.code, SetupErrorCode::HelperSandboxLockFailed); + assert_eq!( + failure.message, + "setup refresh had errors: write ACE failed on C:\\workspace: SetNamedSecurityInfoW failed: 5; deny ACE failed on C:\\workspace\\.git: Access is denied." + ); + } }