fix(browser): kill orphaned Chrome processes on Windows cleanup - #59754
Closed
Younest-git wants to merge 2 commits into
Closed
fix(browser): kill orphaned Chrome processes on Windows cleanup#59754Younest-git wants to merge 2 commits into
Younest-git wants to merge 2 commits into
Conversation
On Windows, killing the agent-browser daemon process does NOT automatically terminate its child Chrome processes. These orphaned chrome.exe processes accumulate over multiple browser_navigate calls, consuming GBs of RAM. Two changes: 1. In _cleanup_single_browser_session(): after killing the daemon and cleaning up the socket directory, run taskkill /f /im chrome.exe to ensure any leftover Chrome child processes are terminated. This is Windows-only (sys.platform == 'win32'). 2. Lower DEFAULT_SESSION_INACTIVITY_TIMEOUT from 120s to 30s so the inactivity-based cleanup reaps sessions faster, reducing the window in which orphans can accumulate.
Collaborator
Related: competes with #43577 for the same Windows orphaned-Chrome cleanup goal. This PR runs a blanket |
The _build_browser_env() function strips credentials from the subprocess environment and only re-adds keys in _BROWSER_PASSTHROUGH_KEYS. AGENT_BROWSER_EXECUTABLE_PATH and AGENT_BROWSER_ARGS were missing from this allowlist, so user-configured env vars from .env never reached the agent-browser CLI. Add both keys so that: - AGENT_BROWSER_EXECUTABLE_PATH actually points Playwright's Chromium - AGENT_BROWSER_ARGS (e.g. --no-sandbox) are passed to the Chrome binary
Younest-git
added a commit
to Younest-git/hermes-agent
that referenced
this pull request
Jul 6, 2026
This was referenced Jul 30, 2026
Open
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.
Summary
On Windows,
browser_navigate()starts a headless Chromium via agent-browser. When the browser session is cleaned up (via inactivity timeout, explicitcleanup_browser(), or Hermes shutdown), the agent-browser daemon is killed — but its child Chrome processes remain running because Windows does not automatically terminate child processes when the parent is killed.Over multiple calls (and across sessions), these orphaned
chrome.exeprocesses accumulate: users report 60–150+ chrome.exe zombies consuming GBs of RAM until they manually runtaskkill /f /im chrome.exe.Changes
1.
_cleanup_single_browser_session()— Windows-specific Chrome killAfter killing the agent-browser daemon and cleaning up the socket directory, run
taskkill /f /im chrome.exeon Windows to terminate any leftover Chrome child processes. The call is wrapped in a try/except so it never blocks cleanup:2. Lower
DEFAULT_SESSION_INACTIVITY_TIMEOUTfrom 120s → 30sThe inactivity-based cleanup thread runs every 30s. With a 120s timeout, orphaned sessions can survive for up to 2 minutes. Reducing to 30s tightens the window significantly without risking premature reaping during normal use.
Testing
browser_navigate()+ inactivity timeout triggers cleanup, and thattaskkillremoves allchrome.exeprocessessys.platform == "win32"guard ensures no behavioral changesubprocess.run()call has a 5-second timeout and is wrapped intry/except— a hungtaskkillcannot block cleanupRelated
Fixes the long-standing issue documented in the
cleanup-chromium-leftoverscommunity skill, where users had to rely on external scripts or manualtaskkillto reclaim RAM.