Skip to content

feat: list every surface an app shows and wait for one - #705

Merged
lahfir merged 73 commits into
laf/reliability-16-effect-witnessfrom
laf/reliability-17-surfaces
Nov 28, 2026
Merged

lahfir merged 73 commits into
laf/reliability-16-effect-witnessfrom
laf/reliability-17-surfaces

Conversation

@lahfir

@lahfir lahfir commented Nov 17, 2026

Copy link
Copy Markdown
Collaborator
  1. list-surfaces on macOS read only the focused window, so a popover, a system dialog or a background window was missing, and a headless click inside a popover could silently bring the app forward.
  2. macOS now lists every window with its popovers and alerts, wait --surface <popover|sheet|alert|menu|any> --app <app> waits for one to be open, a headless click inside a popover is refused as popover_command, and Windows lists an owned pop-up tool window as a popover whose refs resolve.
  3. Builds on feat: verify a click by the effect it causes #704.

@vercel

vercel Bot commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

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

1 Skipped Deployment
Project Deployment Actions Updated
agent-desktop Ignored Ignored Preview, v0 Nov 27, 2026 8:30pm UTC

@lahfir
lahfir added this pull request to stack #669 November 17, 2026 01:01
Comment thread crates/core/src/commands/wait.rs Resolved
lahfir and others added 9 commits November 16, 2026 17:55
… while a system dialog holds the focus

A share from Finder showed none of its surfaces to an agent. With the Share
popover open, `list-surfaces` answered an empty list: the inventory read
only the application's focused window and that window's direct children,
and a popover hangs below the control that raised it. A headless target
window is rarely the focused one. With the AirDrop panel open, every
snapshot of the application failed with APP_UNRESPONSIVE: the focus sits in
a view the AirDrop process draws, the application answers the read of its
focused element with an error, and the snapshot treated that read as
required although it only marks one node as focused.

The inventory now reads every window of the application. While the
application shows an on-screen window at the pop-up menu level, where AppKit
draws an open menu or popover, every window also gets the bounded popover
search the Escape route uses; without one the search does not run. A system
dialog, the window a system service opens for an application, is listed
like a dialog. Only a window's subrole is read: a dialog subrole belongs to
a window, and a sheet or a popover has its own role. A snapshot whose
focused element cannot be read is built without the focused mark.

Measured on Finder with the Share popover and the AirDrop panel open: the
popover and the panel are listed, the panel's snapshot gives its device
buttons and its Cancel button as refs, and a click on that Cancel closes it.
An idle `list-surfaces` costs 27 ms more at the paired median on Finder and
17 ms more on a terminal with several windows, for reading every window
instead of one.
… read a click's surfaces from its own window

A headless click on AirDrop in Finder's Share popover brought Finder to the
front: the share item starts a service whose panel the platform activates.
The share items are plain buttons with a press action and nothing in the
tree tells a share item from a harmless one, so the headless policy now
refuses a click on a button inside a popover with `kind: popover_command`,
from a bounded walk up its ancestors; such a click needs headed mode. A
menu item is not covered: a click on a menu bar item ref is the documented
headless way to run a menu command, and a menu cannot open headless.

The surfaces an action raised were read through the inventory of every
window, which made each click pay for all of the application's windows.
They are now read from the target's own window, the elements below the
target, and the open menus, with no popover search: a popover that opens
after the click is found by `wait --surface`.

Measured on Finder against branch 15: the AirDrop click returns
POLICY_DENIED in 39 ms and the front application stays as it was; the Share
click costs 19 ms less to 10 ms more at the paired median, within the run
noise, and the toolbar back button is delivered as before.
A share popover opens about 300 ms after the click that raised it, so the
click's own result often cannot list it, and an event wait started after the
click takes its baseline after the popover is already open and never sees it
appear. An agent that clicks and then waits had no way to find it.

`wait --surface <popover|sheet|alert|menu|any> --app <app>` waits for a
state, not an event: it polls the application's surface list through the
shared `Deadline::poll_until` and returns the first open surface of that
kind, at once when one is already open. A context menu counts as a menu. A
kind the platform cannot show is refused before the wait starts, through
the same support check `snapshot --surface` uses, instead of ending in a
timeout. A timeout has the shape of the other waits, with
`predicate: surface` and the surfaces it last saw. The flag sits with
`--event` to keep the wait arguments within the field limit; the C ABI is
unchanged.

Measured on Finder with the Share popover: click then wait found it in all
three runs, within 0.6 to 0.8 s of the wait's start, which is one surface
list of Finder while a pop-up window is on screen.
…fs inside it

A ribbon drop-down (in Paint, the Size list) is an owned pop-up tool window
that the window census leaves out, so `list-surfaces` did not show it and a
snapshot could not root it. A popover is now a visible tool window owned by
a window of the same process, with WS_POPUP, that can activate (not
WS_EX_NOACTIVATE, which tooltips use) and is not a menu window (#32768,
which the menu detector owns). The existing EnumWindows pass collects it;
window styles are read only for the process's tool windows. `list-surfaces`
lists it as `popover`, `snapshot --surface popover` roots it, and Popover is
a supported surface, so `wait --surface popover` finds one.

A ref from that snapshot did not resolve: its anchor was rooted at the
recorded window, which a popover is not, and the application root was not
supported. The ref anchor, the application root and the surface observation
now root a popover-surface ref at the process's open popover through the
same predicate, after the process generation check. list-windows output is
unchanged.

Measured on Paint: a headless click on the 3px option is delivered_verified
in 185 ms, the option is selected afterwards, and the foreground window does
not move, so no headless refusal is needed. An idle `list-surfaces` costs
the same as before on Paint and Notepad, and a click with no effect costs
the same.
`snapshot --surface alert` roots a showing alert frame on Linux, but
`list-surfaces` listed that frame only as a sheet, so
`wait --surface alert` could never match and ended in a timeout. A listed
window now records whether its frame is a showing alert, through the same
predicate the alert snapshot roots at, and `list-surfaces` names it `alert`
in place of `sheet`, beside its `window` entry. Only a top-level frame is
classified this way.

Measured on gedit with its "Save changes?" prompt open: `list-surfaces`
gives `window` and `alert` instead of `window` and `sheet`,
`wait --surface alert` finds it in 112 ms instead of timing out, and the
alert snapshot roots the same window.
…pover

The ancestry walk stopped after eight levels and answered "no popover",
so a button deeper than that inside a popover skipped the headless
refusal. The walk now goes up to the window or application, and running
out answers unknown, which refuses.
One retryable accessibility read failure ended the wait at once, even
with most of its timeout left. Only a failure that cannot be retried
ends it now.
A failed read of the surfaces an action raised became an empty list, the
same as "no overlay opened". The result now carries
details.surfaces: "not_read" when the read fails.
The rewritten skill dropped the checks the packaged clipboard helper
must pass, so a failed install read like an empty clipboard.
@lahfir
lahfir force-pushed the laf/reliability-17-surfaces branch from 7d29b8e to ca2c5e5 Compare November 17, 2026 02:07
@lahfir
lahfir requested review from Railly and ctate November 17, 2026 02:08

@Railly Railly left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a couple of things to fix before merging

… not list

The search ran only while a window sat at the pop-up menu level, but a
standard NSPopover draws at the normal level (Calendar's event and quick-event
popovers are layer 0, kCGWindowAlpha 1, absent from AXWindows). The gate is now
any on-screen window of the process, outside the menu bar levels and not
transparent, that no AX window names; a closed popover's window stays on screen
at alpha 0 and does not count.
Linux and Windows list a window entry for every window, so any returned at
once with a plain window instead of waiting for an overlay.
The wait read the surfaces each poll and the app answered, but the timeout
still said the application may be busy or unresponsive. It now points at
details.last_observed and says a longer timeout helps only for a late surface.
list-surfaces and wait --surface sheet list a modal window of the app
headless, but snapshot --surface sheet rooted only the foreground window, so
the sheet a wait had just found returned WINDOW_NOT_FOUND unless it held the
foreground. The sheet root is now each candidate window that is itself modal,
read without the foreground.
…he shell

wait --surface popover and snapshot --surface popover took 3.02 s to return
INVALID_ARGS on GNOME, because the refusal first probed every shell surface for
the list it names. A kind that is neither an application surface nor a shell
surface is now refused at once.
The early refusal listed the application surfaces without asking the bus, so a
session with no accessibility bus refused a kind with INVALID_ARGS and four
surfaces instead of PLATFORM_NOT_SUPPORTED and none. The refusal now asks the
bus, which is cheap, and still skips only the shell probe.
…de a popover

Check AXSubrole for AXPopover before returning false on AXWindow in inside_popover so headless clicks inside subrole-identified popovers do not bypass the popover_command refusal.
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.

3 participants