Skip to content

fix(computer-use): surface app=… filter no-match instead of silently using frontmost (#24170 bug 1)#30051

Merged
teknium1 merged 1 commit into
mainfrom
hermes/hermes-02d0efaa
May 22, 2026
Merged

fix(computer-use): surface app=… filter no-match instead of silently using frontmost (#24170 bug 1)#30051
teknium1 merged 1 commit into
mainfrom
hermes/hermes-02d0efaa

Conversation

@teknium1

Copy link
Copy Markdown
Contributor

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.pycapture(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 ActionResult(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

  • 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 reporter's case) rather than the requested app. Root cause: list_windows returns macOS-localized app_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 the app= filter was effectively dropped.

Validation

#24170 coverage map (full closure)

Credit @briandevans (PR #24324).

Closes #24324, closes #24170.

Infographic

pr-24324-computer-use-app-filter

…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.
@github-actions

Copy link
Copy Markdown
Contributor

🔎 Lint report: hermes/hermes-02d0efaa vs origin/main

ruff

Total: 0 on HEAD, 0 on base (➖ 0)

🆕 New issues: none

✅ Fixed issues: none

Unchanged: 0 pre-existing issues carried over.

ty (type checker)

Total: 9004 on HEAD, 9004 on base (➖ 0)

🆕 New issues: none

✅ Fixed issues: none

Unchanged: 4758 pre-existing issues carried over.

Diagnostics are surfaced as warnings — this check never fails the build.

@alt-glitch alt-glitch added type/bug Something isn't working comp/tools Tool registry, model_tools, toolsets P2 Medium — degraded but workaround exists labels May 21, 2026
@alt-glitch

Copy link
Copy Markdown
Collaborator

This is a salvage of open PR #24324 (same title, same fix for #24170 bug 1). Consider closing #24324 in favor of this updated branch if this one is preferred, or vice versa.

@teknium1 teknium1 merged commit 5aa4727 into main May 22, 2026
20 of 21 checks passed
@teknium1 teknium1 deleted the hermes/hermes-02d0efaa branch May 22, 2026 00:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/tools Tool registry, model_tools, toolsets P2 Medium — degraded but workaround exists type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] computer_use toolset: 5 bugs found during hands-on testing (macOS 26.4.1, cua-driver v0.1.6)

3 participants