Skip to content

feat: verify a click by the effect it causes - #704

Merged
lahfir merged 73 commits into
laf/reliability-15-hard-surfacesfrom
laf/reliability-16-effect-witness
Nov 28, 2026
Merged

lahfir merged 73 commits into
laf/reliability-15-hard-surfacesfrom
laf/reliability-16-effect-witness

Conversation

@lahfir

@lahfir lahfir commented Nov 17, 2026

Copy link
Copy Markdown
Collaborator
  1. A click, double click, right click, triple click or select reported delivered_unverified even when it plainly did something, because nothing read what the app changed afterwards.
  2. Each of those actions now reads an effect witness before and after the dispatch, so a strong change (target gone, window closed, value or selection changed, surface opened, focus moved into the target) reports delivered_verified, and a refused Escape closes its popup through one core route.
  3. Builds on feat: reach the menu, popover and floating window an app shows #702.

@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 and others added 10 commits November 16, 2026 17:55
A click's effect lands outside the target's own state, so after a click
nothing was read: a delivered press stayed `delivered_unverified` even when
it plainly worked, and an unclear platform answer stayed uncertain even
when the window had changed. The only effect check was a macOS one, inside
one rung.

Core now reads an effect witness through a new adapter method,
`read_effect_witness`, before a click, double click, right click, triple
click or select, and decides with an explicit state machine:
- nothing sent, or the adapter already proved the effect: no further read;
- sent without proof: one read, no wait;
- an unclear answer (uncertain): reads until 400 ms after the dispatch.

The witness holds the target's selection, value and open surfaces below
it, the focused element (a stable identity, inside the target or in its
window, its value), and the window's title, a content sign and the window
count. A change on or under the target, focus moving into it, or the target
being gone afterwards is strong evidence and verifies the delivery. A title,
content or window-count change, or focus moving elsewhere, can happen by
itself, so it is reported but verifies nothing. The result carries
`effect` (observed, not_observed, indeterminate) and `details.witness_diff`.
A delivered result never becomes undelivered, and an unclear error with a
strong change stays an error whose disposition is `delivered_verified`.

An adapter that cannot read a witness keeps today's results.
Each platform that closes an open popup after a refused Escape carried its
own wrapper around its key route, and Windows overrode the key method for a
named window to reach the refusal. The order of the states belongs in one
place.

The press command now settles a plain Escape that the key route refused for
focus (`details.check` window_active, exact_window_focus or process_focus,
nothing sent) by asking the adapter to close the open transient surface of
the target through a new method, `close_transient_surface`. A closed
surface is the result; with none open, or when the adapter has no such
route, the refusal stands. Every other key result is left as it was.
The press check of the macOS adapter compared its own `FocusState` before
and after an `AXPress`: the focused element, its value, the target's
selection and value, and an owned menu. Core now reads an effect witness
around every click, so that state is now that witness, read in one place.

`effect_witness::read` builds the core witness from the existing reads:
the target's selection and value, the open menu of a menu control
(`owned_menu_open`) or a popover the control anchors, the focused element
with its element token as identity, whether focus is inside the target or
in its window, the window title with its document, a content sign (the
role and child count of each direct child), the number of windows and
whether the target's window is still listed. Counts are read with one call
each, without copying arrays. The press check reads the target and focus
parts and keeps its rule, now written over the core change list: a press
is delivered when the target's selection or value changes, a menu or
popover opens below it, or focus moves into it or within its window.

Measured on Finder against branch 15: sidebar navigation verified 6 of 6
on both; a Close button that closes its window goes from
delivered_unverified to delivered_verified (window_closed); a Share click
whose popover opens 290 ms later stays delivered_unverified with effect
not_observed; a Settings tab switch stays unverified with effect
indeterminate (window_content); a click with no effect in the
self-updating Activity Monitor window stays not_observed 4 of 4. The Share
click costs the same (357 against 359 ms median, p90 367 against 370).
…ract and the skill

The output contract and the core skill did not say what `effect` and
`details.witness_diff` mean, which changes are strong, that a strong change
verifies a delivery and sets an unclear error's disposition, or that a
refused Escape can close the target's open popup. An agent that reads
`not_observed` as "nothing happened" would repeat an action that landed.
The witness now has two states: no read when nothing was sent or the
adapter already proved the effect, and one read with no wait when the
delivery has no proof or the platform's answer was unclear. The settle
loop after an unclear answer is gone: a click on a Finder sidebar row that
was already open took 876 ms instead of 463 ms while it read for 400 ms and
saw nothing. A second read 10 ms after the first was also tried and
removed: a GTK tab reads as selected about 150 ms after the click, so it
caught nothing, and it cost 17 ms at the median on Linux. An effect that
lands later is for the caller to wait for.
…popup through core

The effect witness on Windows reads the target's own patterns in one cached
update (SelectionItem selected, Value, the ExpandCollapse state as an open
popup below it); a target that is gone fails that update and is a stale
reference. The focus is read at window-handle grain: GetGUIThreadInfo names
the focused window handle, and IsChild and GetAncestor say whether it is
inside the target or in the target's window. A focus change inside a window
with one handle (WPF, Chromium) is not seen, and the focused value is not
read. The window part is its title, a sign of its direct child window
handles, and one EnumWindows pass that counts the process's visible
top-level windows and tells whether the target's window is still one of
them; the target's window handle comes from its RuntimeId, which stays
readable after the window is gone. A first read through the UI Automation
focused element and a FindAll cost 23 ms more at the median on a click with
no effect; this one cost 10 ms more with one read more than core now makes.

The popup close after a refused Escape moves into
`close_transient_surface`, which core calls: it finds the innermost open
menu item, combo box or split button of the target and collapses it with
the existing `disclosure_steps`, which already reads the state back. The
copied collapse and poll code, the wrapper around the key route and the
`press_key_for_window` override are gone, so the core default refuses a
window that does not hold the focus, and the process refusals of the key
path name `check: process_focus`. A collapse no longer declares a
foreground effect, only an expand does, so a headless `collapse` on a combo
box or menu item now works where it was refused; Collapse was measured to
keep the foreground. The core function for a key to a named window is
private again.

Measured on real apps against branch 15: Notepad's Close button and the
Run dialog's Cancel go from delivered_unverified to delivered_verified
(window_closed, target_gone); a Services row click stays verified with
effect observed; a Calculator click with no effect stays unverified with
effect not_observed; a Server Manager page switch stays unverified
(not_observed: no witness field changes, a stated miss). An open Explorer
column menu in a window in the back closes with delivered_verified and the
foreground unchanged.
…pup through core

The effect witness on Linux reads the target's states and value in one
read; only a combo box or an element that reports HAS_POPUP or EXPANDED
gets the bounded walk that counts the popup menus showing below it, and the target's frame in
one step: its name, a sign of its direct children, and the application's
frames, which give the window count and whether the frame is still one of
them. A target that is gone, or whose application is gone, is a stale
reference. The application's focused element cannot be found cheaply on
this platform, so the focus part stays empty.

The popup close after a refused Escape moves into
`close_transient_surface`, which core calls. It keeps the rule of the
previous Linux fix: the owner's action goes through the shared action call,
a reply of false delivers nothing and is not read back, and the attempt's
own error is the answer. The wrapper around the key route, its own focus
refusal check and the answer function are gone, because core owns that
order now.

Measured on real apps against branch 15: gedit's Open dialog Cancel goes
from delivered_unverified to delivered_verified (target_gone); a
gnome-calculator click with no effect stays unverified with effect
not_observed; a terminal whose title changes by itself gives indeterminate
(window_title) and verifies nothing. A GTK3 combo popup in a window in the
back closes with delivered_verified and the active window unchanged. A
click with no effect costs 3 ms more at the median and 6 ms more at p95
(gnome-calculator, 40 runs).
…t witness

A missing ExpandCollapseState counted as closed, so a popup that was
already open looked like one the click had opened and verified it.
An application with no focused element read the same as a focus that
could not be read, so a press that moved focus into its target showed no
change. "Nothing has focus" is now its own read.
The element reader returns none for an attribute the application does
not implement or fails to answer, as well as for no value. Taking those
as "nothing has focus" could count an already focused target as focus
that moved. Only a no-value answer is read as no focus now.
@lahfir
lahfir force-pushed the laf/reliability-16-effect-witness branch from 6029482 to bdb7c55 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.

lgtm, one thing worth a look
the macos Test job is red at this head on gone_wait_requires_window_absence_after_accessibility_disappears (250 ms budget, outside this diff); it passes locally and the base is green. a rerun should clear it.

@GALAXYLLIYI

GALAXYLLIYI commented Nov 19, 2026 •

Copy link
Copy Markdown

This lands close to what we've been running in production for ~6 months in computer-use-gate — every action is followed by a screen re-read that must produce one of three verdicts (delivered / confirmed-unchanged / unobservable), and "unobservable" is never counted as success. A few field notes from Windows that may be useful for the witness design:

1. Scope the witness, or unrelated changes will impersonate yours. Screen-level witnesses get polluted constantly: toast notifications, tray popups, background animations, a spinning caret. We ended up restricting the "strong change" judgment to the target element's neighborhood (element bounds + margin, or the client rect of the owning window) and demoting anything outside that region to a weak signal. A full-screen change during a click on a button is usually not your click.

2. Timing numbers from real UI, Windows 11. After dispatch, UI repaint averages ~40ms later than the action. What works for us: a 50ms repaint grace, then poll the change fingerprint every 25ms and stop at the first frame that shows the change (hard cap 300ms). In practice the first poll round already produces a verdict; fixed sleeps turn the P95 into pure waiting.

3. Stabilize with hysteresis, and filter the cursor. A blinking caret is ~0.01% of pixels changed; a real change (a filled radio button) is ~0.5%. We require the diff ratio to exceed 0.1%, filter thin/narrow blobs (≤8px edge) as cursor-shaped noise, and only report after two consecutive frames agree (hysteresis). For scale: full-screen hashing during any animation reads ~90% change rate, which is no signal at all.

4. "Target disappeared" needs a second look before it counts as strong change. On Windows a store-managed app can tear down and rebuild its window tree without the process dying (Notepad, QQ/NT); the HWND vanishes but the app is mid-reconstruction, so treating that as success-witnessing would be wrong. We report that shape as stale/unobservable rather than delivered, and let the next observation disambiguate.

One semantic suggestion: keep the retry guidance attached to the verdict. In our experience confirmed-unchanged after a ref-targeted action mostly means the action went somewhere else (retrying the same action repeats the mistake), while unobservable is the only state where a retry is free. Delivering that distinction alongside the witness result would make callers' retry loops strictly safer.

Happy to dogfood this on real Windows apps (WinForms, WPF, Chromium-embedded, store apps) once it ships — happy to file structured findings if useful.

— GALAXYLLIYI · computer-use-gate

lahfir and others added 8 commits November 19, 2026 17:03
A value that changes by itself, such as a timer or a playing scrubber, made a
click that did nothing delivered_verified. A second read before the dispatch
would cost a full witness read and still miss a slow timer, so the value now
only reports, like the other changes an application can make by itself.
…ke itself

The press check turned a value change or a focus move into a verified
delivery, while core counts those as weak: a live value made a press that did
nothing delivered_verified. Any press-relevant change still shows the press
arrived; only a strong one (WitnessChange::is_strong) now verifies it, so one
rule decides verification in core and in the adapter. A toggle is verified
through check, uncheck or toggle, which read the state back.
…16-effect-witness

Keep the safe background-Escape dismissal checks alongside the close_transient_surface refactor.
Comment thread crates/linux/src/tree/effect_witness.rs Resolved
Comment thread docs/json-output.md Resolved
Asserting real-clock elapsed() < 40 ms flakes on loaded CI runners. Freeze the test clock and assert zero virtual time elapsed.
Comment thread docs/json-output.md Resolved
…tion

A strong witness change after a delivery_uncertain error returns Ok with delivered_verified, data.effect observed, and details.platform_report; only non-strong verdicts keep the error and set error.details.effect.
…e witness upgrade

- Gate WitnessChange::TargetGone in witnessed_action::after_changes on a confirmed, non-retryable StaleRef so transient or unsettled read failures stay indeterminate and never upgrade delivery.\n- Preserve retryable errors in Linux effect_witness::gone instead of collapsing them into target-gone.\n- Stamp direct-handle target absence in Windows effect_witness as complete and non-retryable while keeping transient UIA errors unchanged.
@lahfir
lahfir merged commit 47dc467 into main Nov 28, 2026
36 of 37 checks passed
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.

4 participants