Skip to content

fix(core): clear page_history on reset and close - #436

Open
sripadha wants to merge 1 commit into
ServiceNow:mainfrom
sripadha:fix/reset-page-history
Open

sripadha wants to merge 1 commit into
ServiceNow:mainfrom
sripadha:fix/reset-page-history

Conversation

@sripadha

Copy link
Copy Markdown

Fixes #435

BrowserEnv.reset() closes the previous browser, context and chat, but it kept every page in self.page_history. Each episode left a Page in the dict, and through it the closed BrowserContext and Browser. _active_page_check() could also fall back to one of those old pages. This change clears page_history in reset() once the old context is closed, and clears page and page_history in close().

Measured with 20 extra resets of browsergym/openended (headless Chromium, playwright 1.44):

live Page / BrowserContext / Browser gc objects
main 2 → 22 each +4218
this PR 2 → 2 each +98

Added test_page_history_reset_between_episodes in tests/core/test_gym_envs.py. It fails on main (history holds pages from the previous episode's closed context) and passes here.

Local checks (Python 3.12, playwright 1.44): tests/core/test_gym_envs.py, test_task.py and test_registration.py pass, as do the tab action tests in test_actions_highlevel.py. black==24.2.0 --check is clean. One run of test_mock_image_goal_task timed out loading google.com; it passed on rerun, both on main and on this branch.

reset() closed the previous browser and context but kept every page in
page_history, so each episode left a Page (and its BrowserContext and
Browser) reachable. Clear the history once the old context is closed,
and in close().

Fixes ServiceNow#435
@sripadha

Copy link
Copy Markdown
Author

Hi @Surya-5555, the Unit tests workflow on 4c7d81e is waiting for approval since this is my first PR here. Locally, tests/core/test_gym_envs.py, test_task.py and test_registration.py pass, and black --check is clean. Could you approve the run when you have time? I'll mark the PR ready once it's green.

@sripadha
sripadha marked this pull request as ready for review December 1, 2026 03:14

This branch has not been deployed

No deployments
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.

BrowserEnv.reset() keeps page_history from previous episodes, so closed browsers and contexts are never freed

1 participant