Skip to content

YC (S26) | Open Computer History | Continuously record your company computer work, map your workflows, help you find work worth automating, and power your agents' context

fix: yield during AX tree walks to prevent USB input lag

Louis Beaumont441f248c1826
diff --git a/crates/screenpipe-a11y/src/tree/macos.rs b/crates/screenpipe-a11y/src/tree/macos.rs
index 65a281f37..99d747bd4 100644
--- a/crates/screenpipe-a11y/src/tree/macos.rs
+++ b/crates/screenpipe-a11y/src/tree/macos.rs
@@ -500,6 +500,12 @@ fn walk_element(elem: &ax::UiElement, depth: usize, state: &mut WalkState) {
state.max_depth_reached = depth;
}
+ // Yield every 100 elements to let macOS process pending HID/input events.
+ // Without this, tight AX IPC loops can starve USB mouse/keyboard event delivery.
+ if state.node_count % 100 == 0 {
+ std::thread::yield_now();
+ }
+
// Set a per-element timeout to prevent IPC hangs
let _ = elem.set_messaging_timeout_secs(state.element_timeout_secs);