fix(tools): improve cua window targeting#24919
Open
davetist wants to merge 1 commit into
Open
Conversation
Prevent explicit computer_use app requests from falling back to unrelated windows, preserve active-window captures after actions, and add regression coverage for generic cua-driver window matching.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do?
Fixes generic cua-driver window targeting issues in the
computer_usebackend:capture(app=...)andfocus_app(app=...)requests no longer silently fall back to an unrelated frontmost windowlist_appsmetadata, and window titlecapture_after=truepreferscapture_active()when the backend supports it, preserving the active target after actionsThe change is deliberately generic. It does not special-case any app or bundle ID.
Related Issue
Related to #24170.
Also searched related open PRs before opening this draft:
type/dragcua-driver behaviorcapture(app=...)This draft is narrower than a full issue rollup but broader than a single-app workaround: it focuses on generic app/window selection and active capture semantics.
Type of Change
Changes Made
tools/computer_use/cua_backend.pylist_appsmetadata into window records by PIDcapture_active()to preserve the selected pid/window after actionstools/computer_use/tool.pycapture_afterhandling to call backendcapture_active()when availabletests/tools/test_computer_use.pyfocus_app, andcapture_afterHow to Test
Run targeted backend tests:
python -m compileall -q tools/computer_use/cua_backend.py tests/tools/test_computer_use.py python -m pytest tests/tools/test_computer_use.py -q -o 'addopts=' git diff --check -- tools/computer_use/cua_backend.py tools/computer_use/tool.py tests/tools/test_computer_use.pyRun lint/static guardrails:
ruff check . python scripts/check-windows-footguns.py --allManual macOS verification with cua-driver-backed
computer_use:capture(app="<target app>")returns the requested app/window instead of a random frontmost appfocus_app(app="<target app>")targets the requested app or returns a no-window-found errorcapture_after=truecapture the active target instead of reselecting an unrelated windowChecklist
Code
fix(scope):,feat(scope):, etc.)pytest tests/ -qand all tests passDocumentation & Housekeeping
docs/, docstrings) — or N/Acli-config.yaml.exampleif I added/changed config keys — or N/ACONTRIBUTING.mdorAGENTS.mdif I changed architecture or workflows — or N/AFor New Skills
N/A.
Current CI Note
The PR
testjob is failing with unrelated suite-wide failures that also reproduce on currentmain's latest push CI (25782318256), including missing optional dependencies (botocore,faster_whisper,numpy) and unrelated DingTalk/Feishu/CLI failures. The touchedcomputer_usetests pass locally, and the other PR checks are green.Screenshots / Logs
Validation run:
Note: I attempted a local full-suite run with
python -m pytest tests/ -q --ignore=tests/integration --ignore=tests/e2e --tb=short -n auto, then with-n 4. Those local runs did not complete cleanly on this macOS checkout due unrelated large-suite failures/hangs, including an initialToo many open filesfailure under-n auto. This draft keeps the full-suite checkbox unchecked pending CI or a cleaner local full-suite run.