fix(computer-use): surface app=… filter no-match instead of silently using frontmost (#24170 bug 1)#30051
Merged
Merged
Conversation
…using frontmost (#24170 bug 1) `CuaDriverBackend.capture(app=X)` and `focus_app(app=X)` silently fell back to the frontmost on-screen window when X matched no app — typically a menu-bar utility (e.g. "Fuwari" in the bug reporter's case) rather than the requested app. The agent then received UI elements for the wrong app and clicked / typed into it. The root cause is a localized macOS app name mismatch: `list_windows` returns the localized `app_name` (e.g. "計算機" on a Japanese/Chinese system) but callers naturally pass the English name ("Calculator"). The substring filter doesn't match, and the code falls through to picking the frontmost window with no signal that the filter was effectively dropped. Fix: - `capture(app=…)`: when the filter matches nothing, return a `CaptureResult` with empty `app`/`elements` and a diagnostic `window_title` pointing the caller at `list_apps` and noting the localized-name convention. `_active_pid` / `_active_window_id` are left untouched so a subsequent action doesn't inadvertently hit the wrong process. - `focus_app(app=…)`: when the filter matches nothing, set `target = None` and let the existing `return ActionResult(ok=False, …, "No on-screen window found for app …")` path fire instead of falsely reporting success on the frontmost window. This addresses bug 1 only from #24170. Bugs 2 & 5 are addressed in #30046; bugs 3 & 4 in #30032.
Contributor
🔎 Lint report:
|
Collaborator
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.
Salvages #24324 onto current main. Fixes the final bug in #24170 — together with #30032 (bugs 3 & 4) and #30046 (bugs 2 & 5), this fully closes #24170.
Changes
tools/computer_use/cua_backend.py—capture(app=…): when the filter matches nothing, return aCaptureResultwith emptyapp/elementsand a diagnosticwindow_titlepointing the caller atlist_appsand noting the localized-name convention._active_pid/_active_window_idare left untouched so a subsequent action doesn't inadvertently hit the wrong process.focus_app(app=…): when the filter matches nothing, settarget = Noneand let the existingActionResult(ok=False, "No on-screen window found for app …")path fire instead of falsely reporting success on the frontmost window.tests/tools/test_computer_use.py— 5 regression tests (capture no-match diagnostic, capture match still works, no-filter still picks frontmost, focus_app no-match returns ok=False, focus_app match still works).Bug fixed
CuaDriverBackend.capture(app=X)andfocus_app(app=X)silently fell back to the frontmost on-screen window when X matched no app — typically a menu-bar utility (e.g. "Fuwari" in the reporter's case) rather than the requested app. Root cause:list_windowsreturns macOS-localizedapp_name(e.g. "計算機"), but callers naturally pass the English name ("Calculator"). The substring filter doesn't match, the code falls through, and the agent receives UI elements for the wrong window with no signal that theapp=filter was effectively dropped.Validation
tests/tools/test_computer_use.py— 61/61 passing (51 baseline + 5 from fix(computer_use): preserve app context for capture_after; fix element label parsing (#24170 bugs 2 & 5) #30046 + 5 from this PR).Co-Authored-By: Claude Opus 4.7line from the original commit message (per project convention) and completed a dangling cross-reference sentence ("Bugs 2 & 5 are addressed in" → "in fix(computer_use): preserve app context for capture_after; fix element label parsing (#24170 bugs 2 & 5) #30046; bugs 3 & 4 in fix(computer_use): correct type_text MCP tool name and implement drag action (#24170 bugs 3 & 4) #30032").#24170 coverage map (full closure)
Credit @briandevans (PR #24324).
Closes #24324, closes #24170.
Infographic