Skip to content

fix(cua-driver-rs)(macos): per-element AX messaging timeout + cycle/time guards for heavy webview walks#1755

Draft
f-trycua wants to merge 1 commit into
mainfrom
fix/ax-walk-messaging-timeout
Draft

fix(cua-driver-rs)(macos): per-element AX messaging timeout + cycle/time guards for heavy webview walks#1755
f-trycua wants to merge 1 commit into
mainfrom
fix/ax-walk-messaging-timeout

Conversation

@f-trycua
Copy link
Copy Markdown
Collaborator

Problem

get_window_state can hang indefinitely on apps with large or busy accessibility trees (heavy webviews). Reading an AX attribute is a synchronous XPC round-trip into the target app; while a renderer is materializing its tree, that round-trip can stay pending forever and wedge the entire walk. The outer thread-level timeout then just tears down a stuck walk rather than letting it make progress.

Fix

Set a per-element messaging timeout once, on the application element, right after AXUIElementCreateApplication:

  • AXUIElementSetMessagingTimeout(app_elem, 1.5) — the ceiling is inherited by every descendant element vended through the app element, so a single wedged element fails fast with kAXErrorCannotComplete in ~1.5s instead of blocking the whole traversal. This is the real anti-hang fix.

Two layered backstops in walk_element:

  • Cycle dedup — a visited: HashSet<usize> keyed on the element pointer address. AX is a graph, not a strict tree; a malformed hierarchy can re-vend an element already walked, and this stops that from inflating the walk.
  • 5s per-walk wall-clock budget — bails between AX calls the same way the depth guard does. It cannot abort an in-flight call (that is the messaging timeout's job); it caps cumulative time across many slow-but-completing calls.

These complement, not replace, the existing outer thread-level timeout and the MAX_DEPTH guard.

Scope

  • platform-macos only; platform-windows / platform-linux unaffected.
  • AXUIElementSetMessagingTimeout is a stable HIServices symbol (since 10.4); declared alongside the other AXUIElement* FFI bindings.

Validation

  • cargo build --release -p cua-driver passes.
  • cargo test --no-run -p platform-macos compiles (the pre-existing libswift_Concurrency.dylib rpath issue is at the test-binary link step, not introduced here).
  • Live VM validation against heavy webview apps still recommended before un-drafting.

Refs #1537

🤖 Generated with Claude Code

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 29, 2026

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 1c542ec2-3b71-4605-9839-6d2ff63eb3ac

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/ax-walk-messaging-timeout

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@vercel
Copy link
Copy Markdown
Contributor

vercel Bot commented May 29, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
docs Ignored Ignored Preview May 29, 2026 4:35pm

Request Review

…ime guards for heavy webview walks

get_window_state could hang indefinitely on apps with large or busy
accessibility trees (heavy webviews). Reading an AX attribute is a
synchronous XPC round-trip to the target app; while a renderer is
materializing its tree that round-trip can stay pending forever, wedging
the entire walk.

Fix: call AXUIElementSetMessagingTimeout(app_elem, 1.5) right after
creating the application element. The ceiling is inherited by every
descendant, so a wedged element fails fast with kAXErrorCannotComplete
in ~1.5s instead of blocking the traversal.

Layered backstops in walk_element:
- cycle dedup via a visited HashSet keyed on element pointer address,
  since AX is a graph and a malformed hierarchy can re-vend elements;
- a 5s per-walk wall-clock budget that bails between calls (it cannot
  abort an in-flight call — that is the messaging timeout's job).

These complement, not replace, the existing outer thread-level timeout.

Refs #1537

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant