Skip to content

fix(cua-driver): preserve foreground focus during macOS clicks - #3530

Draft
RubinCarter wants to merge 2 commits into
trycua:mainfrom
RubinCarter:fix/macos-target-only-synthetic-focus
Draft

RubinCarter wants to merge 2 commits into
trycua:mainfrom
RubinCarter:fix/macos-target-only-synthetic-focus

Conversation

@RubinCarter

@RubinCarter RubinCarter commented Sep 3, 2026 •

Copy link
Copy Markdown

Summary

  • replace the macOS background pixel-click focus-without-raise sequence with target-only synthetic focus
  • never send defocus or restore records to the user foreground process
  • skip target deactivation if the user genuinely activates that target while the click is in flight
  • fail closed when the private target-only route is unavailable and clean up target state on errors
  • keep target activation under the existing strict focus-suppression observer
  • extend the foreground sentinel with native BrowserWindow blur so AppKit-level loss cannot hide behind unchanged DOM focus
  • require the existing background raw-double-click E2E cell to attest that it used target-only synthetic focus

Refs #3331

Salvaged from iFurySt/open-codex-computer-use#48.

Validation

  • cargo fmt --all -- --check
  • cargo test -p platform-macos (362 passed, 2 ignored)
  • cargo test -p cua-driver-testkit (56 unit tests and 2 integration-schema tests passed)
  • cargo test -p cua-driver --test harness_appkit_test --no-run
  • node --check libs/cua-driver/tests/fixtures/apps/cross-platform/electron/main.js
  • focused target-only record, plan, user-takeover cleanup, and native-sentinel classification tests pass

Pending native evidence

The local console session is currently locked (CGSSessionScreenIsLocked=Yes). The covered-target focus test cannot establish an active/key foreground sentinel while locked, so no native focus-preservation result is claimed yet. After unlock the sentinel first runs a deliberate focus-loss/input-leak canary, then the background raw double click must prove target effect, target-only route use, unchanged frontmost PID, no native or DOM blur, unchanged real pointer, unchanged z-order, and safe user takeover.

Known unrelated validation noise

cargo clippy -p platform-macos --all-targets -- -D warnings is currently blocked by pre-existing lints in cursor-overlay and other untouched platform-macos files under Rust 1.98.

@RubinCarter
RubinCarter force-pushed the fix/macos-target-only-synthetic-focus branch 2 times, most recently from 945a6a5 to 75cc516 Compare September 3, 2026 18:42
Replace the background pixel-click focus-without-raise sequence with target-only synthetic focus. The action now fails closed when that route is unavailable and always tears down the target state without defocusing or reactivating the user foreground app.

Salvaged from iFurySt/open-codex-computer-use#48.

Co-authored-by: tisfeng <25194972+tisfeng@users.noreply.github.com>
@RubinCarter
RubinCarter force-pushed the fix/macos-target-only-synthetic-focus branch from 9134033 to b28de77 Compare September 3, 2026 18:47
Journal Electron BrowserWindow focus transitions independently of DOM blur and require the macOS focus-loss canary to trigger the native signal. This catches AppKit resign/key-window regressions that leave document.hasFocus unchanged.
@RubinCarter
RubinCarter force-pushed the fix/macos-target-only-synthetic-focus branch from b28de77 to f9325c8 Compare September 3, 2026 18:50
This was referenced Sep 16, 2026

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