Skip to content

feat(macos): let get_app_state wait for the window to settle - #125

Open
hyprcat wants to merge 1 commit into
iFurySt:mainfrom
hyprcat:feat/settle-wait
Open

hyprcat wants to merge 1 commit into
iFurySt:mainfrom
hyprcat:feat/settle-wait

Conversation

@hyprcat

@hyprcat hyprcat commented Oct 22, 2026

Copy link
Copy Markdown
Contributor

What

get_app_state takes an optional settle_ms (macOS). Before reading, it polls a fingerprint of the target window about every 100 ms and reads once the fingerprint has stayed the same for settle_ms (capped at 2000), for at most 5 seconds. The fingerprint uses the same bounded AX walk as query: role, title, description, value and window-relative layout of every visited node. A note after the state text says whether the window settled and how long it waited. Read-only: no activation, no extra screenshot. JS: app.getAXState({ settleMs }). Linux/Windows reject settle_ms.

Why

After an action that loads or animates, agents guess a sleep before reading state. A still window now costs about settle_ms; a loading one is read once it stops changing; one that never stops returns its state after 5 s. The fingerprint uses accessibility data rather than pixels, since carets, video and CSS animation would never settle. The ceiling is fixed and documented, like query's 2 s deadline. Action read-back keeps its fixed 150 ms pause; using the wait there would change every action's latency.

Verification

  • swift test: 384 tests, 7 skipped, 0 failures. New tests cover the stability check with synthetic fingerprints and a fake clock (still, loading then stopping, a blip, never stopping, a quiet period longer than the ceiling), settle_ms validation, and the schema.
  • Cost per fingerprint (median / worst seen): small native window ~1 / 3.6 ms; WebKit page with ~400 rows 21.6 / 25.8 ms; TextEdit 18.2 / 30.8 ms; Finder list window 34.6 / 51.1 ms.
  • Live, settle_ms: 300: still window settled after 367 ms; a label changing for 2 s settled after 2343 ms; a web page adding rows for 2 s settled after 2127 ms with the loaded content; a never-ending label stopped at 4998 ms with "Not settled"; the same read without settle_ms took 97 ms.

Limits

Changes visible only in pixels (canvas, video) don't move the fingerprint, and only the first ~1000 characters of each value are compared.

After an action, agents guess a sleep before reading state. get_app_state
now takes settle_ms: before reading, it fingerprints the target window
about every 100 ms with the same bounded AX walk query uses (role, title,
description, value and window-relative layout of every visited node; no
records, no actions read) and reads once the fingerprint has stayed the
same for settle_ms (capped at 2000), for at most 5 seconds. A note after
the state says whether the window settled and how long it waited. The
wait is read-only: no activation, no capture.

The stability check is a pure function with an injectable clock, tested
with synthetic digests. Action read-back keeps its fixed short pause.
Linux and Windows reject settle_ms.
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.

1 participant