hermes - 💡(How to fix) Fix Bug: CDP Browser Mode Does Not Close Tabs on Cleanup

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…

CDP browser mode (when connected to an existing Chrome instance via cdp_url or /browser connect) does not close browser tabs when the browser session is cleaned up. This causes tabs to accumulate indefinitely in the user's Chrome instance, leading to memory exhaustion and making CDP mode unsuitable for automated workflows like cron jobs.

Root Cause

In tools/browser_tool.py:

  1. _create_cdp_session creates fake session names like "cdp_{uuid}" for CDP connections, with no corresponding agent-browser daemon process:

  2. _cleanup_single_browser_session attempts to kill a daemon process by PID from agent-browser-{session_name}/{session_name}.pid — but this PID file never exists for CDP sessions because there's no daemon. The SIGTERM fails silently, then agent-browser close is called which only disconnects the WebSocket without closing actual browser tabs.

  3. Missing CDP call: No Page.close or Target.closeTarget CDP command is issued to close the tab before disconnecting.

Fix Action

Workaround

For automated cron jobs, use Local headless mode (remove cdp_url config) which auto-cleans after 5min inactivity timeout, or use Cloud provider mode.

Code Example

google-chrome --remote-debugging-port=9222
RAW_BUFFERClick to expand / collapse

Summary

CDP browser mode (when connected to an existing Chrome instance via cdp_url or /browser connect) does not close browser tabs when the browser session is cleaned up. This causes tabs to accumulate indefinitely in the user's Chrome instance, leading to memory exhaustion and making CDP mode unsuitable for automated workflows like cron jobs.

Root Cause

In tools/browser_tool.py:

  1. _create_cdp_session creates fake session names like "cdp_{uuid}" for CDP connections, with no corresponding agent-browser daemon process:

  2. _cleanup_single_browser_session attempts to kill a daemon process by PID from agent-browser-{session_name}/{session_name}.pid — but this PID file never exists for CDP sessions because there's no daemon. The SIGTERM fails silently, then agent-browser close is called which only disconnects the WebSocket without closing actual browser tabs.

  3. Missing CDP call: No Page.close or Target.closeTarget CDP command is issued to close the tab before disconnecting.

Impact

  • Each browser_navigate() call in CDP mode creates a new tab
  • Tabs accumulate indefinitely in user's Chrome instance
  • Chrome memory exhaustion over time
  • Makes CDP mode unsuitable for automated cron jobs that run repeatedly

Proposed Fixes

Option A: Explicit tab close Add explicit CDP Page.close call before WebSocket disconnect for CDP sessions.

Option B: Config flag Add browser.cdp_close_tabs_on_cleanup: bool (default false for backward compatibility with users who expect tabs to persist).

Environment

  • Hermes Agent version: latest main
  • Chrome: any with --remote-debugging-port
  • Mode: CDP (live CDP connection via cdp_url)

Related

  • PR #11916: fail safe on shared live CDP browser tasks
  • PR #11917: reuse persistent live CDP session
  • Issue #11020: Browser session lifecycle bugs

Verification Steps

  1. Start Chrome with remote debugging:

    google-chrome --remote-debugging-port=9222
  2. Run multiple browser_navigate calls in CDP mode

  3. Observe tabs accumulating in Chrome (Window menu or chrome://inspect)

Workaround

For automated cron jobs, use Local headless mode (remove cdp_url config) which auto-cleans after 5min inactivity timeout, or use Cloud provider mode.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING