feat: add session tracking and fix reinitialization for AgentCoreBrowser #319
+174
−92
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.
Description
This PR adds session lifecycle management for AgentCoreBrowser and fixes a bug preventing session reinitialization after close.
Changes
Session Tracking and Cleanup
_client_dictto track active browser sessions by session_id_client_dictincreate_browser_session()for proper session tracking__init__()to ensure cleanup on process exitBug Fix: Session Reinitialization
_started = Falsein_async_cleanup()to allow playwright to reinitialize_startedremainedTrueafter cleanup, preventing_start()from being called againTesting
test_bedrock_browser_create_browser_session_hydrates_client_dict: Verifies_client_dictis populated when sessions are createdtest_bedrock_browser_registers_atexit_handler: Confirms cleanup handler is registered at initializationtest_bedrock_browser_reinitializes_playwright_after_close: Verifies sessions can be created, closed, and recreated successfullyAll tests pass locally with
hatch test tests/browser/test_agent_core_browser.pyChecklist
hatch fmt --formatter)hatch fmt --linter)hatch test)Related Issues
Closes #286
Closes #205