Skip to content

fix(cua-driver): filter daemon overlay from window-change events + guard type_text against stale focus - #1700

Closed
hippoley wants to merge 1 commit into
trycua:mainfrom
hippoley:fix/window-change-detector-filter-own-pid
Closed

fix(cua-driver): filter daemon overlay from window-change events + guard type_text against stale focus#1700
hippoley wants to merge 1 commit into
trycua:mainfrom
hippoley:fix/window-change-detector-filter-own-pid

Conversation

@hippoley

@hippoley hippoley commented May 26, 2026

Copy link
Copy Markdown
Contributor

Fixes Bug 2 and Bug 3 from #1592.

Bug 2 — WindowChangeDetector reports own overlay as new window

Every click appended 🪟 Action opened new window(s): Cua Driver because detectChanges() saw AgentCursorOverlayWindow as a newly-appeared window.

Fix: filter newEvents by ProcessInfo.processInfo.processIdentifier so windows owned by the daemon itself are never reported as side-effects.

Bug 3 — type_text inserts into wrong AX element in modal sheet context

With a macOS Open dialog showing a 'Go to Folder' sheet, type_text inserted text into the sidebar AXOutline instead of the sheet's text field. AX focus tracking lags in sheet hierarchies.

Fix: after focusedElement(), check the role. If it is AXOutline, AXTable, AXList, AXBrowser, AXScrollArea, or AXSplitGroup, return an actionable error suggesting element_index targeting via get_window_state.

Fixes #1592 (Bug 2, Bug 3)

Summary by CodeRabbit

  • Bug Fixes
    • Improved text input validation to provide clearer error messages when attempting to type in non-text containers, guiding users to alternative targeting methods.
    • Fixed window detection to exclude internal application windows from change reports.

Review Change Stack

…ard type_text against stale focus

Fixes trycua#1592 Bug 2 and Bug 3.

Bug 2 — WindowChangeDetector reports own overlay as new window:
  Every click appended '🪟 Action opened new window(s): Cua Driver'
  because WindowChangeDetector.detectChanges() saw the
  AgentCursorOverlayWindow as a newly-appeared window.
  Fix: filter newEvents by daemonPid (ProcessInfo.processInfo.processIdentifier)
  so windows owned by the daemon itself are never reported as side-effects.

Bug 3 — type_text inserts into wrong AX element in modal sheet context:
  With a macOS Open dialog showing a 'Go to Folder' sheet, type_text
  inserted text into the sidebar AXOutline instead of the sheet's text
  field. AX focus tracking lags in sheet hierarchies — the previous
  focused element retains focus status even after the sheet appears.
  Fix: after focusedElement(), check the role. If it is AXOutline,
  AXTable, AXList, AXBrowser, AXScrollArea, or AXSplitGroup (non-text
  containers), return an actionable error suggesting element_index
  targeting via get_window_state instead of silently writing to the
  wrong element.
@vercel

vercel Bot commented May 26, 2026

Copy link
Copy Markdown
Contributor

@nishantpurohit04 is attempting to deploy a commit to the Cua Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai

coderabbitai Bot commented May 26, 2026

Copy link
Copy Markdown
Contributor

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 97c2ad30-831d-4e1d-af56-cd33276aca42

📥 Commits

Reviewing files that changed from the base of the PR and between f51ce80 and 21b3c59.

📒 Files selected for processing (2)
  • libs/cua-driver/swift/Sources/CuaDriverServer/Tools/TypeTextTool.swift
  • libs/cua-driver/swift/Sources/CuaDriverServer/Tools/WindowChangeDetector.swift

📝 Walkthrough

Walkthrough

This PR addresses two bugs in the CUA driver: TypeTextTool now validates that a focused AX element is text-editable before writing, returning an error if focus has landed on a non-text container; WindowChangeDetector filters out overlay windows owned by the daemon process itself to prevent false "new window" reports.

Changes

AX Focus Validation and Daemon Window Filtering

Layer / File(s) Summary
Non-text container guard in TypeTextTool
libs/cua-driver/swift/Sources/CuaDriverServer/Tools/TypeTextTool.swift
When using the AX bulk-insert path, the tool now determines the focused element's AX role and checks it against a set of non-text roles (outline, table, list, browser, scroll, split group). If a match is found, an error response is returned instructing the caller to use element_index targeting instead.
Daemon window filtering in WindowChangeDetector
libs/cua-driver/swift/Sources/CuaDriverServer/Tools/WindowChangeDetector.swift
When building new-window events, the detector now captures the daemon's PID and excludes candidate windows owned by that process, preventing overlay windows from being reported as side effects.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

  • trycua/cua#1416: Both PRs modify TypeTextTool's AX-first insertion flow to improve robustness around focused element context (retrieved PR adds AX→CGEvent fallback with delay_ms, main PR adds non-text container detection and error guidance).
  • trycua/cua#1477: Both PRs refine WindowChangeDetector.detectChanges behavior after UI actions (retrieved PR introduces window/foreground side-effect detection used by ClickTool; main PR excludes daemon-owned overlay windows from detection).
  • trycua/cua#1422: Main PR's TypeTextTool validation extends the Chrome AX "silent-accept" verification logic introduced in the retrieved PR.

Poem

🐰 A focus guard stands firm and true,
No non-text containers slip on through.
And daemon windows fade from sight—
The overlay dreams no longer blight!
✨ Two bugs fixed, the path runs clean.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the two main fixes in the changeset: filtering daemon overlay from window-change events and guarding type_text against stale focus.
Linked Issues check ✅ Passed The PR successfully implements fixes for Bug 2 and Bug 3 from #1592: WindowChangeDetector filters daemon windows, and TypeTextTool validates focused element roles against non-text containers.
Out of Scope Changes check ✅ Passed All changes are directly scoped to the objectives: WindowChangeDetector filters daemon overlay, and TypeTextTool guards against stale focus with non-text containers. Bug 1 coordinate space mismatch is not addressed, as intended.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@f-trycua

Copy link
Copy Markdown
Collaborator

Thanks @hippoley — closing as part of the Swift-backend retirement (see PR #1738 — cua-driver-rs is now the default backend, the Swift port is no longer the supported integration path).

For Bug 1 specifically (screenshot ↔ click coord mismatch): the Rust port doesn't have a standalone screenshot tool — it's unified into get_window_state which already applies max_image_dimension and registers the resize ratio via the shared ImageResizeRegistry equivalent in Rust. So the class of bug doesn't exist in the new default backend.

For Bugs 2 + 3 (daemon overlay as new window, type_text stale focus on modal sheets): I've filed a follow-up to audit the Rust port for parity gaps in tracking issue #1753. If those bugs exist in the Rust path we'll address them there.

Appreciate the patch — sorry we can't land this one. If you'd like to help port the fix to libs/cua-driver/rust/crates/platform-macos/src/, that would be hugely useful.

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.

screenshot tool returns native-resolution images incompatible with click coordinate system (+ two related bugs)

2 participants