fix(cua-driver-rs)(get_window_state): 30s timeout + 2000-node cap for heavy webview apps - #1754
Conversation
…apps Closes #1537. Cherry-picked from #1609 (@hippoley) — same fix concept, ported to the post-#1674 path layout (`libs/cua-driver/rust/crates/`) and dropped the Swift backend change (path being deprecated per #1738). - `ax/tree.rs`: `MAX_ELEMENTS = 2000` cap with `TreeWalkResult.truncated` surfaced as a warning line at the end of `tree_markdown`. - `tools/get_window_state.rs`: `tokio::time::timeout(30s)` wrap on the `spawn_blocking` AX walk. On expiry returns a clear error suggesting `capture_mode=vision` or a `query` filter rather than hanging forever. Reported by @obaid against Arc / Safari w/ many tabs on macOS 26 where `AXUIElementCopyAttributeValue` blocks indefinitely via XPC on pathologically large trees. Co-Authored-By: hippoley <noreply@github.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub. |
|
Caution Review failedThe pull request is closed. ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughThe PR hardens AX tree traversal against indefinite hangs on heavy webview apps by capping the total node visits at 2,000 and wrapping the walk in a 30-second timeout. The walker now tracks traversal progress and stops early with a truncation flag, while callers receive explicit timeout guidance instead of hanging forever. ChangesAX Tree Traversal Protection
🎯 2 (Simple) | ⏱️ ~12 minutes
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
Summary
Closes #1537. Cherry-picked from #1609 (@hippoley) — same fix concept, ported to the post-#1674 path layout (
libs/cua-driver/rust/crates/).When
get_window_statewalks the AX tree of a pathologically large app (Arc, Safari with many tabs, Electron),AXUIElementCopyAttributeValuecan block indefinitely via XPC. There's no built-in deadline, so the MCP server just hangs forever — reported by @obaid on macOS 26.Two changes, both Rust-only:
libs/cua-driver/rust/crates/platform-macos/src/ax/tree.rs—MAX_ELEMENTS = 2000cap on total nodes visited in a single walk.walk_elementnow threads a sharedvisited_count+truncatedflag; when the cap is hit the walk stops early andTreeWalkResult.truncated = true. The renderer appends a warning line totree_markdownso the agent knows the partial tree is intentional and existing element indices remain valid.libs/cua-driver/rust/crates/platform-macos/src/tools/get_window_state.rs— wraps thespawn_blockingAX walk intokio::time::timeout(Duration::from_secs(30)). On expiry returns a descriptiveToolResult::errorsuggestingcapture_mode=visionor aqueryfilter rather than hanging.Notes
libs/cua-driver/Sources/CuaDriverCore/AppState/AppState.swift) deliberately dropped — that path is being deprecated per [codex] docs(cua-driver): pivot to rust-first driver #1738.TreeWalkResultgains a new public field (truncated: bool); additive, doesn't break existing callers.Test plan
cargo build --release -p cua-driveron macOS — greencargo check -p platform-windows --target=x86_64-pc-windows-msvc— green (additive struct field doesn't touch Windows code)get_window_statereturns a truncation warning rather than hangingcc @obaid for the original repro, @hippoley for the original fix.
Summary by CodeRabbit