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): avoid SIGCHLD handler in doctor

injaneity31bbc074d75f
diff --git a/libs/cua-driver/rust/Cargo.lock b/libs/cua-driver/rust/Cargo.lock
index 2dca3095b0..3d5b30fb62 100644
--- a/libs/cua-driver/rust/Cargo.lock
+++ b/libs/cua-driver/rust/Cargo.lock
@@ -891,7 +891,6 @@ dependencies = [
"tracing-subscriber",
"ureq",
"uuid",
- "wait-timeout",
"windows 0.61.3",
]
@@ -4287,15 +4286,6 @@ dependencies = [
"libc",
]
-[[package]]
-name = "wait-timeout"
-version = "0.2.1"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "09ac3b126d3914f9849036f826e054cbabdc8519970b8998ddaf3b5bd3c65f11"
-dependencies = [
- "libc",
-]
-
[[package]]
name = "wasi"
version = "0.11.1+wasi-snapshot-preview1"
diff --git a/libs/cua-driver/rust/crates/cua-driver/Cargo.toml b/libs/cua-driver/rust/crates/cua-driver/Cargo.toml
index 746e5a903c..10aed51c45 100644
--- a/libs/cua-driver/rust/crates/cua-driver/Cargo.toml
+++ b/libs/cua-driver/rust/crates/cua-driver/Cargo.toml
@@ -30,11 +30,6 @@ ureq = { version = "3", features = ["json"] }
# pre-release tags (`-dev`, `-rc.1`) sort below their corresponding release
# and we never recommend a pre-release as an "update".
semver = "1"
-# Bounded `Child::wait_timeout` for the Linux AT-SPI / gdbus probe in
-# `doctor`. We can't rely on `gdbus introspect` returning quickly when the
-# session D-Bus is hung — without a timeout, `doctor` would block forever
-# on a broken accessibility stack. Tiny dep, exactly this use case.
-wait-timeout = "0.2"
# Tarball extraction for `cua-driver skills install`. The verb fetches a
# versioned `cua-driver-rs-v<v>-skills.tar.gz` release asset from GitHub
# and unpacks it under `<HomeDir>/skills/cua-driver-rs/`. `tar` is the
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 a7a6316480..0487a5c33d 100644
--- a/libs/cua-driver/rust/crates/cua-driver/src/doctor.rs
+++ b/libs/cua-driver/rust/crates/cua-driver/src/doctor.rs
@@ -379,7 +379,6 @@ fn append_platform_probes(report: &mut Report) {
#[cfg(target_os = "linux")]
fn probe_at_spi_bus_via_gdbus(timeout: std::time::Duration) -> bool {
use std::process::{Command, Stdio};
- use wait_timeout::ChildExt;
let mut child = match Command::new("gdbus")
.args([
@@ -397,20 +396,36 @@ fn probe_at_spi_bus_via_gdbus(timeout: std::time::Duration) -> bool {
Ok(c) => c,
Err(_) => return false,
};
- match child.wait_timeout(timeout) {
+ match wait_for_child(&mut child, timeout) {
Ok(Some(status)) => status.success(),
- Ok(None) => {
- // Timed out — kill the stuck child so we don't leave a
+ Ok(None) | Err(_) => {
+ // Timed out or failed — kill the stuck child so we don't leave a
// gdbus process hanging around after `doctor` exits.
let _ = child.kill();
let _ = child.wait();
false
}
- Err(_) => {
- let _ = child.kill();
- let _ = child.wait();
- false
+ }
+}
+
+#[cfg(target_os = "linux")]
+fn wait_for_child(
+ child: &mut std::process::Child,
+ timeout: std::time::Duration,
+) -> std::io::Result<Option<std::process::ExitStatus>> {
+ let deadline = std::time::Instant::now() + timeout;
+ loop {
+ if let Some(status) = child.try_wait()? {
+ return Ok(Some(status));
+ }
+
+ let Some(remaining) = deadline.checked_duration_since(std::time::Instant::now()) else {
+ return Ok(None);
+ };
+ if remaining.is_zero() {
+ return Ok(None);
}
+ std::thread::sleep(remaining.min(std::time::Duration::from_millis(15)));
}
}
@@ -618,6 +633,29 @@ mod tests {
assert_eq!(json["ok"], serde_json::Value::Bool(true));
}
+ #[cfg(target_os = "linux")]
+ #[test]
+ fn wait_for_child_reports_exit() {
+ let mut child = std::process::Command::new("true").spawn().unwrap();
+ let status = wait_for_child(&mut child, std::time::Duration::from_secs(1))
+ .unwrap()
+ .unwrap();
+ assert!(status.success());
+ }
+
+ #[cfg(target_os = "linux")]
+ #[test]
+ fn wait_for_child_times_out() {
+ let mut child = std::process::Command::new("sleep")
+ .arg("5")
+ .spawn()
+ .unwrap();
+ let status = wait_for_child(&mut child, std::time::Duration::from_millis(10)).unwrap();
+ assert!(status.is_none());
+ child.kill().unwrap();
+ child.wait().unwrap();
+ }
+
#[test]
fn cross_platform_probes_always_emit_something() {
// Smoke test: run the cross-platform probes and confirm they all