Skip to content

Fix macOS app PID selection to avoid helper processes#28

Open
gambit36 wants to merge 1 commit intobrowser-use:mainfrom
gambit36:fix/macos-app-pid-selection
Open

Fix macOS app PID selection to avoid helper processes#28
gambit36 wants to merge 1 commit intobrowser-use:mainfrom
gambit36:fix/macos-app-pid-selection

Conversation

@gambit36
Copy link

@gambit36 gambit36 commented Mar 12, 2026

Summary

  • prefer the real foreground app process over helper/background processes
  • avoid selecting helper, PlatformSupport, and Web Content processes when resolving app PIDs
  • update the print_app_tree example to use the same selection logic

Why

When opening Safari, the previous bundle-id substring match could resolve to com.apple.SafariPlatformSupport.Helper instead of the main Safari app. That caused UI tree reads to miss the real window content.

Validation

  • reproduced the issue with Safari selecting the helper process
  • after this change, print_app_tree.py resolves the main Safari app and returns interactive elements from the real window

Summary by cubic

Fixes macOS PID resolution to pick the main foreground app instead of helper/background processes, so UI tree reads target the actual window (e.g., Safari’s main process, not PlatformSupport.Helper).

  • Bug Fixes
    • Added a scoring-based selector to prefer the primary app by name/bundle ID and penalize "Helper", "PlatformSupport", and "Web Content".
    • Integrated the selector in app launch flow and the print_app_tree.py example.
    • Verified with Safari: now resolves the main app PID and returns interactive elements from the real window.

Written for commit 16d710a. Summary will update on new commits.

@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

Copy link

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 issue found across 2 files

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="mlx_use/controller/service.py">

<violation number="1" location="mlx_use/controller/service.py:52">
P2: When scored selection returns `None`, fallback `pgrep` picks the first matching PID without helper/background filtering, reintroducing wrong app PID selection.</violation>
</file>

Since this is your first cubic review, here's how it works:

  • cubic automatically reviews your code and comments on bugs and improvements
  • Teach cubic by replying to its comments. cubic learns from your replies and gets better over time
  • Add one-off context when rerunning by tagging @cubic-dev-ai with guidance or docs links (including llms.txt)
  • Ask questions if you need clarification on any suggestion

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

return None
scored.sort(key=lambda item: item[0], reverse=True)
best_score, best_app = scored[0]
return best_app if best_score > 0 else None
Copy link

@cubic-dev-ai cubic-dev-ai bot Mar 12, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: When scored selection returns None, fallback pgrep picks the first matching PID without helper/background filtering, reintroducing wrong app PID selection.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At mlx_use/controller/service.py, line 52:

<comment>When scored selection returns `None`, fallback `pgrep` picks the first matching PID without helper/background filtering, reintroducing wrong app PID selection.</comment>

<file context>
@@ -7,6 +7,50 @@
+		return None
+	scored.sort(key=lambda item: item[0], reverse=True)
+	best_score, best_app = scored[0]
+	return best_app if best_score > 0 else None
+
 from mlx_use.agent.views import ActionModel, ActionResult
</file context>
Fix with Cubic

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.

2 participants