Skip to content

fix(macos): list windows on another Space and keep window titles out of ambiguity errors - #325

Open
gshost1 wants to merge 8 commits into
mainfrom
fix/macos-off-space-windows
Open

gshost1 wants to merge 8 commits into
mainfrom
fix/macos-off-space-windows

Conversation

@gshost1

@gshost1 gshost1 commented Nov 26, 2026

Copy link
Copy Markdown
Owner

What and why

Field test (macOS 26, a browser on another Space): list-windows --app returned []. Snapshots failed WINDOW_NOT_FOUND with "wait for the app to present a window". screenshot --window-id failed. screenshot --app failed AMBIGUOUS_TARGET with 16 candidates whose titles were the user's open tabs.

Root cause: narrow_to_real_windows (window_inventory.rs) keeps a window only when it is visible or has a minimized state. macOS drops a window on another Space from AXWindows, so it had neither and was dropped as if the app had ordered it out. CoreGraphics still lists it (the list option is kCGWindowListOptionAll, so CG is not the cause).

Changes:

  • Core WindowState.on_other_space: Option<bool>, serialized only when known.
  • macOS scoped inventory: for off-screen windows that are not minimized and not in AX, ask CGSCopySpacesForWindows. A window on some Space but not the current one is kept with on_other_space: true. At most 32 windows per inventory, one worker, 100 ms budget. An inventory with no such windows makes no call.
  • snapshot and find on such a window: ACTION_NOT_SUPPORTED window_on_other_space, naming focus-window.
  • focus-window: activates the app so macOS switches Spaces, waits up to 1.5 s for the AX element, then raises the window. If the window stays away, the error adds application_activated: true.
  • screenshot --app picks among the app-scoped windows, not every off-screen window of the process.
  • Window AMBIGUOUS_TARGET candidates are {id, is_focused, visible, on_other_space?}, with no titles. The macOS verified_window_title_ambiguous error names the window id instead of the title.
  • The app_has_no_window suggestion now names list-windows and focus-window.

How tested

  • cargo clippy -p agent-desktop-macos -p agent-desktop-core -p agent-desktop -p agent-desktop-ffi --target aarch64-apple-darwin --all-targets -- -D warnings: clean (xcrun shim, check only).
  • cargo check -p agent-desktop-windows -p agent-desktop-core --target x86_64-pc-windows-msvc --all-targets: clean.
  • Linux: clippy over the host set, then scripts/cargo-test-isolated-home.sh test over the host set: all passed (core 2350). Pre-commit gates passed.
  • New macOS tests: window_inventory_space_tests, window_space_tests, focus_other_space_tests, window_resolve_liveness_tests. They run in macOS CI only.
  • Not run: macOS unit tests, e2e, perf A/B, and a live probe.

Risks / to confirm on the Mac

  • The CGSCopySpacesForWindows masks (all = 7, current = 5) come from public reverse-engineered headers. Confirm them live: one window on Space 2 should show on_other_space: true, and the same window on screen should not appear as on another Space. Also check with two displays.
  • list-windows --app latency when an app owns many off-screen helper windows (browsers). Run perf-baseline-compare.sh --apps "Google Chrome".
  • focus-window now activates the app before the window has an AX element. This is a visible Space switch, and only happens for a window already known to be on another Space.

…of ambiguity errors

An app whose windows were all on another Space listed no windows, so
snapshot and screenshot failed with advice to wait. The window server
still places those windows on a Space; list them as on_other_space,
say so when a tree read cannot reach them, and let focus-window switch
to them. A window AMBIGUOUS_TARGET listed titles, which in a browser
are the user's open tabs.
Bring in #322-#324 and #326 so the PR is tested against current main.

# Conflicts:
#	docs/json-output.md
…indow errors

Review of #325 found that the new window_on_other_space kind broke paths that
treated a window without an accessibility tree as temporary:

- wait and post-action observation now keep polling through
  window_on_other_space, and the owned-surface fallback accepts it, as they
  already did for window_without_accessibility_element.
- The app-scoped inventory remembers the last Space placement per window
  number, so a window does not drop out of one poll and return in the next when
  that poll's best-effort Space read times out (spurious window events).
- The Space read worker stops at three quarters of the budget, so the
  placements it already read reach the caller instead of being lost.
- focus-window: errors after the activation are annotated as delivered, the
  command deadline running out is a TIMEOUT (window_space_switch), a window on
  screen without its element keeps that error, and the suggestion says macOS
  only switches Spaces when the app has no window on the Space on screen.
- screenshot --app uses the app-scoped inventory only where the adapter says
  so (macOS); Linux and Windows keep the process-wide lookup.
Second review round on #325's other-Space handling:

- A lookup that fails because the command deadline ran out during the Space
  switch wait now becomes the window_space_switch TIMEOUT instead of the
  generic deadline error, and that timeout suggests a longer --timeout.
- A window seen on another Space at any point in the wait is reported as having
  stayed there, so a Space read that times out on the last poll does not
  turn it into "not exposed through accessibility".
- application_activated reflects whether the activation started.
- A sheet, popover or alert read for a window on another Space keeps
  window_on_other_space when the current-Space fallback finds nothing,
  instead of ELEMENT_NOT_FOUND.
- The remembered Space placements cover windows past the 32-read cap, and
  the shared memory is no longer locked while the read waits.
…r-Space error

ErrorCode is not Copy; the previous commit took it from a borrowed error.
… in hand

Removes the expect() the workspace lints forbid.

This branch has not been deployed

No deployments
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