cua icon indicating copy to clipboard operation
cua copied to clipboard

macOS AX walk withholds two facts about a control: a disabled control gets no element_index, and AXSubrole is never read

Open will-bogusz opened this issue 2 months ago • 1 comments

What happens

The macOS AX walk withholds two facts about a control that a caller needs, and both are decided in is_addressable / the node read.

1. A disabled control gets no element_index, so it is not published at all

fn is_addressable(actions_present: bool, value_settable: bool, enabled: Option<bool>) -> bool {
    (actions_present || value_settable) && enabled != Some(false)
}

The walker's own test pins the consequence — assert!(!is_addressable(true, false, Some(false))): a control that advertises actions is refused an index purely because it reports AXEnabled=false. get_window_state then publishes only indexed nodes (let idx = node.element_index?;), so such a control appears in tree_markdown as a display-only row with no index and no actions, and is absent from the elements array entirely — including from its own enabled field, which the payload already has.

That erases a recoverable state. macOS reports controls disabled for reasons the caller can undo: a toolbar control in a window that has never been key reads AXEnabled=false until the window becomes key, and the dispatch path already knows this and says so —

// input/ax_actions.rs:200-218
"refusing {action}: the target reports AXEnabled=false. \
 Retry this action with delivery_mode:\"foreground\" or call bring_to_front first"

— but that advice can never reach a caller, because the control it is about has no index to dispatch against. The caller sees an inert row indistinguishable from decoration, with no way to learn why.

Live: Notes' collapsed toolbar search control. AX reports it as

/1/10/0 AXRole='AXButton' AXSubrole='AXSearchField' AXTitle='' AXDescription='Search' AXEnabled='False'

and the driver's own tree for that window renders it as

    - AXButton (Search)

— no index, and none of that snapshot's 231 elements rows is it. (Captured from a build carrying these exact two lines; the walker is unchanged here at 9e60d90b8.)

2. AXSubrole is never read, so the role is the only class token on a node

AXSubrole is read for windows (list_windows, window_scope) and for the text-field write plan (set_value), but never for a tree node. macOS puts the control class there rather than in the role, and the role alone is frequently not enough to identify a control.

Same Notes window, search expanded. AX reports AXRole='AXTextField' AXSubrole='AXSearchField' AXValue='' AXEnabled='True' — and no title, description, placeholder or identifier at all. So the only thing the driver can render is:

    - [85] AXTextField = "" [actions=[showmenu,confirm]]

The structured element is {element_index: 85, role: "AXTextField", depth: …} with no label. A consumer looking for the search field has nothing to match on; measured against that snapshot: find({role:"AXSearchField"}) -> 0, find({label:"Search"}) -> 0, find({role:"AXButton", label:"Search"}) -> 0.

It is not only search fields. On that one window, 173 of 1558 walked nodes publish a subrole, and the ones whose subrole is the only class token include the window's close / minimize / full-screen buttons and the scroll bar's increment/decrement arrows — all AXButton with an empty title.

Where (9e60d90b8)

  • crates/platform-macos/src/ax/tree.rs:131-132 — is_addressable, the enabled != Some(false) conjunct.
  • same file, :434-443 — the AXEnabled pre-read feeding it, with a comment explaining the exclusion as protection against closed-submenu descendants.
  • same file, :744 — the test that pins "actions present, disabled ⇒ not addressable".
  • crates/platform-macos/src/tools/get_window_state.rs:820 — let idx = node.element_index?;, the publish gate.
  • crates/platform-macos/src/ax/tree.rs:47-95 — AXNode: AXRole is read, AXSubrole is not a field.
  • crates/platform-macos/src/ax/tree.rs:612-659 — format_node_line, the rendered row and its bracketed metadata block.
  • crates/cua-driver-contract/src/windows.rs:202-230 — WindowElement, which already carries enabled.
  • crates/platform-macos/src/input/ax_actions.rs:215-218 — ensure_ax_action_enabled, which re-reads AXEnabled immediately before every dispatch.

Expected

  • Enablement is state, not existence. A control that advertises an action or exposes a writable value gets an element_index regardless of its enablement, and publishes enabled: false. Nothing can be dispatched by mistake: ensure_ax_action_enabled re-reads the attribute immediately before performing and refuses with the recovery advice above, so the only change is that the caller can now reach the refusal instead of the control being invisible. The closed-submenu case the current comment protects against is answered by the same publication — the row says it is disabled rather than vanishing.
  • AXSubrole is published. One read per addressable node, carried as subrole on the element payload (Option<String>, omitted when the app reports none) and rendered on the tree row.

Cost, measured

On a captured 1558-node Notes window:

  • AX requests: one AXSubrole read per addressable node — 314 of that window's 500 rendered rows are indexed — against the ~10 reads every visited node already pays and the 5 more an indexed node pays. That is +1.8% requests for the window, and zero for display-only rows, because the read sits inside the existing actionable gate (read_control_state_if_actionable's precondition).
  • Rendered bytes: 173 of the 1558 nodes publish a subrole, but 164 of them are AXRow+AXTableRow (153), AXRow+AXOutlineRow (11) and AXWindow+AXStandardWindow (1) — tokens that restate the role the row already prints. Rendering all of them costs ~3.1 kB on a 33.2 kB tree (+9.4%) for no information. So the row omits a subrole that ends in its own role's stem (AXRow/AXTableRow is suppressed, AXTextField/AXSearchField is not) and the payload always carries the raw value; the 9 that survive on that window cost ~0.2 kB and are exactly the ones that name a different control class.

Rendered shape, for the two cases above:

    - [3] AXButton (Search) [subrole=AXSearchField actions=[press] enabled=false]
    - [85] AXTextField = "" [subrole=AXSearchField actions=[showmenu,confirm]]

enabled=false is rendered only when the app reports the control disabled; an enabled control adds nothing to the line.

I have this implemented and unit-tested on a branch and can open a PR referencing this issue.

will-bogusz avatar Sep 17 '26 21:09 will-bogusz

Thanks for the detail. Whether a disabled control should get an element_index is a real design question: publishing it with enabled: false and no actions would show the state without letting an agent act on it. Reading AXSubrole is a separate and simpler addition. This was filed in September, so is this still a problem for you on the current release (0.56.4)? If so, say which of the two matters more and we will take that one first.

f-trycua avatar Nov 21 '26 11:11 f-trycua