From 06f97622f8529feef0d230fc37519c36c6bb2eeb Mon Sep 17 00:00:00 2001 From: zm-oai Date: Sat, 26 Sep 2026 20:18:09 +0000 Subject: [PATCH] Add context to Windows sandbox runtime registration errors (#48531) Identify the failing setup step when starting, completing, or verifying managed runtime package registration, granting metadata permissions, or persisting the completed registration. Preserve the underlying errors with `anyhow::Context`. GitOrigin-RevId: 85f712faf2519e95704d7e8cea15d2deeed0d51e --- .../src/registered_runtime.rs | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/codex-rs/windows-sandbox-service/src/registered_runtime.rs b/codex-rs/windows-sandbox-service/src/registered_runtime.rs index d1132d96e3..554cece304 100644 --- a/codex-rs/windows-sandbox-service/src/registered_runtime.rs +++ b/codex-rs/windows-sandbox-service/src/registered_runtime.rs @@ -163,7 +163,8 @@ pub(crate) fn provision( None, DeploymentOptions::None, )?) - })?; + }) + .context("start managed runtime package registration")?; // As with provisioning, retain the request's resources until Windows finishes. // A client timeout or an unreadable status cannot safely release the profile. let mut status_error_logged = false; @@ -193,18 +194,26 @@ pub(crate) fn provision( } std::thread::sleep(Duration::from_millis(50)); } - operation.GetResults()?.ExtendedErrorCode()?.ok()?; + operation + .GetResults() + .and_then(|result| result.ExtendedErrorCode()) + .and_then(windows::core::HRESULT::ok) + .context("finish managed runtime package registration")?; ensure!( - registered_packages(&profile.user_sid, &family)?.contains(full_name), + registered_packages(&profile.user_sid, &family) + .context("verify managed runtime package registration")? + .contains(full_name), "runtime registration completed without the expected package" ); } - metadata::grant(identity.token.0, &profile.user_sid, record)?; + metadata::grant(identity.token.0, &profile.user_sid, record) + .context("grant managed runtime metadata permissions")?; profile.unload_profile()?; } if !receipt_current { record.runtime_mut()?.ready_package = Some(full_name.to_string()); - crate::installation_record::save_runtime(record)?; + crate::installation_record::save_runtime(record) + .context("persist completed managed runtime registration")?; } Ok(()) }