Scale computer-use 2.0 with open-source drivers, cross-OS sandboxes, and benchmarks for training, evaluation, and data generation.
Rust agentai-agentapplecomputer-usecomputer-use-agentcontainerizationcuadesktop-automationhacktoberfestlumemacosmanusoperatorswiftvirtualizationvirtualization-frameworkwindowswindows-sandbox
fix(cua-driver): tolerate a transient UIA read and a twice-reported consent prompt on Windows (#5082)
Francesco Bonaccif0c468f7b2b5
diff --git a/libs/cua-driver/rust/crates/platform-windows/src/browser_consent_ui.rs b/libs/cua-driver/rust/crates/platform-windows/src/browser_consent_ui.rsindex 25f91303b3..38099eb9cc 100644--- a/libs/cua-driver/rust/crates/platform-windows/src/browser_consent_ui.rs+++ b/libs/cua-driver/rust/crates/platform-windows/src/browser_consent_ui.rs@@ -335,10 +335,26 @@ wherehas_keyboard_focus,});}- matches.push(select_language_independent_actions(&candidates)?);+ let (allow, cancel) = select_language_independent_actions(&candidates)?;+ let rect_of = |ptr: usize| {+ candidates+ .iter()+ .find(|candidate| candidate.element_ptr == ptr)+ .map(|candidate| candidate.rect)+ };+ let geometry = (node_name(&nodes[start]), rect_of(allow), rect_of(cancel));+ // The same prompt can bind twice in one walk (a nested surface, or+ // UIA repeating its rows with fresh element pointers). Its title and+ // exact button geometry identify it; any other prompt still refuses.+ if !matches+ .iter()+ .any(|(_, existing_geometry)| *existing_geometry == geometry)+ {+ matches.push(((allow, cancel), geometry));+ }}match matches.as_slice() {- [element] => Ok(Some(*element)),+ [(element, _)] => Ok(Some(*element)),_ => Err(refusal(BrowserRefusalCode::BrowserWrongTargetRefused,"multiple bound native Chromium consent prompts exposed structural allow actions",@@ -744,6 +760,21 @@ mod tests {);}+ #[test]+ fn matcher_binds_one_prompt_reported_twice_with_the_same_geometry() {+ let mut nodes = pane_rooted_prompt("same title", ["A", "B", "C"]);+ let mut repeated = pane_rooted_prompt("same title", ["A", "B", "C"]);+ for node in &mut repeated {+ if node.element_ptr != 0 {+ node.element_ptr += 1000;+ }+ }+ nodes.extend(repeated);+ assert!(exact_allow_button_with(&nodes, properties)+ .unwrap()+ .is_some());+ }+#[test]fn matcher_refuses_multiple_pane_rooted_native_prompts() {let mut nodes = pane_rooted_prompt("first opaque title", ["A", "B", "C"]);diff --git a/libs/cua-driver/rust/crates/platform-windows/src/browser_setup_ui.rs b/libs/cua-driver/rust/crates/platform-windows/src/browser_setup_ui.rsindex 98cb11de7a..91bbe5cd9f 100644--- a/libs/cua-driver/rust/crates/platform-windows/src/browser_setup_ui.rs+++ b/libs/cua-driver/rust/crates/platform-windows/src/browser_setup_ui.rs@@ -41,8 +41,23 @@ fn release_nodes(nodes: &[UiaNode]) {/// `Document` node without its renderer-owned descendants. Tab topology and/// the committed setup URL are native facts, so reading them must not depend/// on the page renderer answering UIA (#4121).+const NATIVE_READ_RETRIES: usize = 3;+fn native_nodes(hwnd: u64) -> Result<Vec<UiaNode>, BrowserRefusal> {- crate::uia::walk_native_tree(hwnd).map_err(|error| {+ // A UIA read can fail transiently while Chromium rebuilds its tree (for+ // example "Malformed Cacheresponse" as a native prompt opens). Retry a+ // few times before refusing.+ let mut attempt = 0;+ let walked = loop {+ match crate::uia::walk_native_tree(hwnd) {+ Err(_) if attempt < NATIVE_READ_RETRIES => {+ attempt += 1;+ std::thread::sleep(std::time::Duration::from_millis(150));+ }+ result => break result,+ }+ };+ walked.map_err(|error| {refusal(BrowserRefusalCode::BrowserWrongTargetRefused,format!(