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): drain autoreleased objects on SCK capture workers (#5170)

injaneityb6a8280d6ff7
diff --git a/libs/cua-driver/rust/crates/platform-macos/src/capture.rs b/libs/cua-driver/rust/crates/platform-macos/src/capture.rs
index 15fa2c82de..0db5c6f10a 100644
--- a/libs/cua-driver/rust/crates/platform-macos/src/capture.rs
+++ b/libs/cua-driver/rust/crates/platform-macos/src/capture.rs
@@ -40,6 +40,7 @@
//! its fallback and reports that it could not exclude the overlay.
use base64::{engine::general_purpose::STANDARD as BASE64, Engine};
+use objc2::rc::autoreleasepool;
use std::collections::HashMap;
use std::hash::Hash;
use std::process::Command;
@@ -418,7 +419,7 @@ where
std::thread::Builder::new()
.name("cua-sck-window-capture".into())
.spawn(move || {
- let result = work();
+ let result = autoreleasepool(|_| work());
drop(permit);
let _ = sender.send(result);
})
@@ -1470,6 +1471,23 @@ mod tests {
);
}
+ #[test]
+ fn pooled_native_worker_returns_work_result_and_error() {
+ static GATE: NativeCaptureGate = NativeCaptureGate::new();
+
+ let ok = run_native_capture_worker(&GATE, Duration::from_secs(5), || Ok(7u8));
+ assert_eq!(ok.expect("work result flows through the pooled worker"), 7);
+
+ let err: anyhow::Result<u8> =
+ run_native_capture_worker(&GATE, Duration::from_secs(5), || {
+ Err(anyhow::anyhow!("boom"))
+ });
+ assert!(err
+ .expect_err("work error flows through")
+ .to_string()
+ .contains("boom"));
+ }
+
#[test]
fn timed_out_native_worker_blocks_replacement_until_original_returns() {
use std::sync::atomic::{AtomicUsize, Ordering as AtomicOrdering};