Skip to content

armgit / cua

Public Imported from GitHub
0

Scale computer-use 2.0 with open-source drivers, cross-OS sandboxes, and benchmarks for training, evaluation, and data generation.

fix(cua-driver): report recoverable UIA timeouts as warnings (#3959)

lorenzozane59c1f4ba2fa6
diff --git a/libs/cua-driver/rust/crates/cua-driver/src/doctor.rs b/libs/cua-driver/rust/crates/cua-driver/src/doctor.rs
index 81416ae9a2..df3d6fbb87 100644
--- a/libs/cua-driver/rust/crates/cua-driver/src/doctor.rs
+++ b/libs/cua-driver/rust/crates/cua-driver/src/doctor.rs
@@ -354,16 +354,7 @@ fn append_platform_probes(report: &mut Report) {
};
// COM / UI Automation availability.
- match diag::ui_automation_available() {
- Ok(()) => report.push(Probe::ok(
- "UI Automation",
- "CoCreateInstance(CUIAutomation) succeeded",
- )),
- Err(e) => report.push(Probe::err(
- "UI Automation",
- format!("CoCreateInstance(CUIAutomation) failed: {e}"),
- )),
- }
+ report.push(ui_automation_probe());
// EnumWindows count — cross-check the session probe. When Session 0
// is in play, this almost always reports zero visible windows, which
@@ -383,6 +374,31 @@ fn append_platform_probes(report: &mut Report) {
report.push(probe);
}
+#[cfg(target_os = "windows")]
+fn ui_automation_probe() -> Probe {
+ use platform_windows::diagnostics as diag;
+
+ match diag::ui_automation_available() {
+ Ok(()) => ui_automation_probe_from(Ok(()), false),
+ Err(e) => {
+ let degraded = diag::is_degraded_ui_automation_error(&e);
+ ui_automation_probe_from(Err(e), degraded)
+ }
+ }
+}
+
+#[cfg(any(target_os = "windows", test))]
+fn ui_automation_probe_from(result: Result<(), String>, degraded: bool) -> Probe {
+ match result {
+ Ok(()) => Probe::ok("UI Automation", "CoCreateInstance(CUIAutomation) succeeded"),
+ Err(e) if degraded => Probe::warn("UI Automation", e),
+ Err(e) => Probe::err(
+ "UI Automation",
+ format!("CoCreateInstance(CUIAutomation) failed: {e}"),
+ ),
+ }
+}
+
/// Run `gdbus introspect` against the AT-SPI accessibility bus and report
/// whether it returned success within `timeout`. Any of: spawn failure,
/// timeout elapsed, non-zero exit — all collapse to `false` (the caller
@@ -760,4 +776,32 @@ mod tests {
assert_eq!(report.probes[0].message, "not present");
assert!(report.probes[1].message.starts_with("removed stale "));
}
+
+ #[test]
+ fn degraded_ui_automation_does_not_fail_doctor() {
+ let mut report = Report::default();
+ for error in [
+ "UI Automation desktop enumeration exceeded 4000ms; a UIA provider may be hung.",
+ "UI Automation is busy with an earlier timed-out provider call; window tools are temporarily using Win32-only enumeration.",
+ ] {
+ let probe = ui_automation_probe_from(Err(error.to_owned()), true);
+ assert_eq!(probe.status, Status::Warn);
+ assert_eq!(probe.message, error);
+ report.push(probe);
+ }
+ assert!(!report.has_errors());
+ assert_eq!(report.to_json()["ok"], serde_json::Value::Bool(true));
+ }
+
+ #[test]
+ fn genuine_ui_automation_failures_still_fail_doctor() {
+ let probe = ui_automation_probe_from(
+ Err("CoCreateInstance(CUIAutomation) failed".to_owned()),
+ false,
+ );
+ assert_eq!(probe.status, Status::Err);
+ assert!(probe
+ .message
+ .contains("CoCreateInstance(CUIAutomation) failed"));
+ }
}
diff --git a/libs/cua-driver/rust/crates/platform-windows/src/diagnostics.rs b/libs/cua-driver/rust/crates/platform-windows/src/diagnostics.rs
index 6de2266e3c..726fb538e3 100644
--- a/libs/cua-driver/rust/crates/platform-windows/src/diagnostics.rs
+++ b/libs/cua-driver/rust/crates/platform-windows/src/diagnostics.rs
@@ -224,6 +224,12 @@ pub fn ui_automation_available() -> Result<(), String> {
crate::uia::windows_enum::probe_desktop_availability()
}
+/// Whether a UIA failure leaves the Win32-only fallback usable.
+pub fn is_degraded_ui_automation_error(err: &str) -> bool {
+ err.starts_with("UI Automation desktop enumeration exceeded ")
+ || err.starts_with("UI Automation is busy with an earlier timed-out provider call;")
+}
+
// ── Non-Windows stubs so the cua-driver crate can call into us
// unconditionally during compilation on other targets. These never run —
// they exist purely to keep the type-checker happy on macOS / Linux.
@@ -364,3 +370,25 @@ mod tests {
}
}
}
+
+#[cfg(test)]
+mod error_classification_tests {
+ use super::is_degraded_ui_automation_error;
+
+ #[test]
+ fn only_bounded_desktop_failures_are_degraded() {
+ assert!(is_degraded_ui_automation_error(
+ "UI Automation desktop enumeration exceeded 4000ms; a UIA provider may be hung."
+ ));
+ assert!(is_degraded_ui_automation_error(
+ "UI Automation is busy with an earlier timed-out provider call; window tools are temporarily using Win32-only enumeration."
+ ));
+ assert!(!is_degraded_ui_automation_error(
+ "CoCreateInstance(CUIAutomation) failed"
+ ));
+ assert!(!is_degraded_ui_automation_error(
+ "FindAll(TreeScope_Children): operation timed out"
+ ));
+ assert!(!is_degraded_ui_automation_error("provider is busy"));
+ }
+}