[Bug]: AXWindow resolution finds zero windows for Safari — empty trees and refused background input
Primary area
Cua Driver
Summary
On macOS, get_window_state for a Safari window returns element_count: 0 with degraded_reason: ax_window_unresolved — the driver finds zero AXWindow elements under Safari's pid — and the same failed resolution then makes type_text with a window_id refuse (Background input refused (off_space_or_ax_unresolved)). One root cause, two symptoms: no accessibility tree, no window-targeted input, for an app whose AX surface other readers walk fully.
Reproduction
- Safari running with one or more normal browser windows (multi-window, some possibly on other Spaces — real desktop conditions).
{"method":"call","name":"get_window_state","args":{"pid":<safari>,"window_id":<big window's CGWindowID>}}against the daemon socket.{"method":"call","name":"type_text","args":{"pid":<safari>,"window_id":<same>,"text":"probe"}}.
Expected behavior
The window's AX tree (Safari exposes a full one), and typing delivered to the window.
Actual behavior
element_count: 0,degraded: true,degraded_reason: "ax_window_unresolved: window_id N exists and is owned by pid P, but none of the 0 AXWindow element(s) under that pid reports this CGWindowID"— note the 0: it isn't a CGWindowID↔AXWindow mismatch, the driver sees no AXWindows at all.type_text:Background input refused (off_space_or_ax_unresolved).
The degradation contract itself is good (honest empty tree, explicit refusal — in 0.16 the type path reported success while delivering nothing, so 0.23's refusal is a real improvement). The bug is the resolution failing.
Environment
cua-driver-rs 0.23.2 (darwin-arm64 release tarball), macOS 26.0 (Darwin 27), Apple Silicon. Daemon run with its own HOME, --no-overlay --no-permissions-gate --dangerously-bypass-approvals; Accessibility and Screen Recording granted via caller attribution (check_permissions reports both true).
Evidence
Cross-checked the same pid/window at the same moment:
- An independent AX referee (a small Swift CLI walking
AXUIElementCreateApplication(pid)directly) finds Safari's windows and its address field, and reads live values. - cua-driver 0.6.0 on the same machine returns a full ~740KB tree for the same window, containing a value planted in the address field.
- A Swift driver mirroring this tree's design also resolves it fully. So the AX surface is there and grants are sufficient; only 0.23's AXWindow enumeration comes back empty for this pid.
Workaround and additional context
Pixel-rung escalation per the tool's own guidance, when a screenshot is available (in our runs the px fallback capture also failed for these windows: could not create image from window). Happy to run diagnostics against a build with more logging if that helps pin where the AXWindow list comes back empty.
🤖 Generated with Claude Code
Taking a focused implementation pass on fresh, exact AX window discovery for this issue.
Independent local AppKit and SwiftUI fixtures reproduced AXWindows == [] when all target windows were off the active Space. Fresh AXMainWindow and AXFocusedWindow references still mapped to the exact requested CGWindowID and exposed working controls. Direct AX button presses changed fixture state without changing the before/after foreground process, active Space, window bounds, or target Space membership. A different live CGWindowID was refused before dispatch. A plain persistent ScreenCaptureKit stream did not restore AXWindows enumeration.
Scope: merge fresh, same-process window candidates from the existing window list and main/focused attributes; retain exact CGWindowID matching and use the same acquisition in observation and input preflight. No title/frame matching, app-root fallback, silent activation, or claim that every off-Space sibling is recoverable.
Acceptance evidence: focused candidate/identity tests; production-driver AppKit and SwiftUI off-Space observation plus semantic-action readback; wrong-window refusal; and separate assessment of keyboard/pixel routes and foreground invariants. Full representative desktop certification remains a stable-candidate gate before ready/merge.
This is recovery work, not a duplicate of #3459's diagnostics-only change. It does not implement #2894's unattributed AX surfaces or #3530's synthetic-focus change. I will link one draft PR here and keep progress and validation in its description. This is a contributor workstream pending maintainer review, not a scheduling claim on behalf of the project.
That scope matches what we observed exactly — for what it's worth as a datapoint for your acceptance evidence: 0.6.0 on the same machine resolved the same off-Space Safari windows to full ~740KB trees, so exact-CGWindowID recovery is demonstrably achievable without title/frame matching or activation. Happy to run our neutral AX referee (direct AXUIElementCreateApplication walk, no driver in the loop) against your draft PR's build when it's up.
Thanks @hyprcat. This has the same off-Space root cause as #3458. #4068 and #4085 (0.28.4) now recover off-Space windows, and #3458 tracks the remaining fullscreen-Space case, so I'm closing this as a duplicate of #3458.