cua icon indicating copy to clipboard operation
cua copied to clipboard

Linux: get_window_state and type_text hang (no timeout) on modal dialogs

Open f-trycua opened this issue 5 months ago • 1 comments

Summary

On Linux, get_window_state and type_text hang indefinitely when the target app has a modal dialog open. The tool call never returns; the process sits blocked (load ~0, so it's waiting, not spinning). Discovered while live-driving a real desktop accounting app (HomeBank) for a demo.

Repro

  1. Launch HomeBank on an X11 session (apt install homebank), open the example file.
  2. Click the Add toolbar button → the modal "Add transaction" dialog opens (its own toplevel, WM_TRANSIENT_FOR the main window).
  3. Resolve the dialog's window_id (it's not in _NET_CLIENT_LIST; find via xdotool search --pid).
  4. cua-driver call get_window_state '{"pid":<pid>,"window_id":<dlg>,"capture_mode":"ax"}' → hangs (killed at 30s; the main window's tree returns fine).
  5. cua-driver call type_text '{"pid":<pid>,"window_id":<dlg>,"text":"42.50"}' after clicking a field → hangs (process blocked indefinitely).

click by x,y returns; get_window_state/type_text are the ones that hang. The main window walks fine — only the modal dialog traps the tools.

Suspected cause

  • type_text tries its AT-SPI GrabFocus + EditableText path first; under the modal grab a zbus call to the dialog's accessible blocks and never returns. It never reaches the XTEST fallback.
  • get_window_state has a 25s OP_TIMEOUT, but the call exceeded 30s — so either the timeout doesn't wrap the hanging step (e.g. the registry connect / app_for_pid lookup happens outside the timeout), or the per-call timeout isn't applied on this path.

Impact

A tool that hangs with no upper bound is worse than one that fails — it wedges the session and a daemon worker. Modal dialogs are a very common UI pattern (every "Add / Edit / Preferences" form), so this is hit easily on real apps.

Suggested fix

  • Time-bound every AT-SPI step in type_text (and set_value) and fall back to XTEST on timeout instead of hanging.
  • Ensure get_window_state's OP_TIMEOUT wraps the whole path including the registry connect / app_for_pid lookup, so it returns partial/empty rather than hanging.
  • Add an overall hard deadline to every Linux AT-SPI entry point.

Found on cua-driver-rs 0.5.7 (Ubuntu 22.04, XFCE/X11).

f-trycua avatar Jun 18 '26 06:06 f-trycua

Confirmed on a broader scope — hangs on ALL windows, not just modal dialogs

Environment:

  • cua-driver v0.6.5 (x86_64-linux)
  • Ubuntu 24.04.4 LTS, GNOME Shell, X11 (Xorg)
  • Resolution: 1920x1080, AT-SPI enabled, ibus-hangul
  • cua-driver doctor: all checks pass

Symptom: get_window_state hangs indefinitely on every window, not only modal dialogs. Tested against xfce4-terminal (GTK3), RustDesk (Qt), and Mutter system windows — all produce zero output and never return.

Individual tools work fine:

Tool Result
list_windows ✅ Returns 4 visible windows with bounds
get_accessibility_tree ✅ Returns ~21KB of AT-SPI data
zoom (screenshot only, with window_id) ✅ Returns ~98KB JPEG
get_window_state (capture_mode "ax", no screenshot) ❌ Hangs — 0 bytes, no return
get_window_state (default som mode) ❌ Hangs — 0 bytes, no return

The fact that capture_mode "ax" alone hangs (no screenshot involved) suggests the issue is in the window-targeted AT-SPI tree walk path (app_for_pid → zbus call), not in the screenshot/XGetImage path.

Additional data point: max_image_dimension config does not persist on Linux — related to #1923. config.json stores 1920 but get_config always returns 1568.

Reproduction:

DISPLAY=:0 XDG_RUNTIME_DIR=/run/user/1000 cua-driver call list_windows --json '{}'
# Pick any window_id from the output, then:
DISPLAY=:0 XDG_RUNTIME_DIR=/run/user/1000 timeout 30 cua-driver call get_window_state --json '{"pid":<PID>,"window_id":<WID>,"capture_mode":"ax"}'
# Returns 0 bytes, times out

downwind7clawd-ctrl avatar Jun 23 '26 07:06 downwind7clawd-ctrl