Skip to content

fix: preserve keep-alive browser event bus#5031

Open
he-yufeng wants to merge 1 commit into
browser-use:mainfrom
he-yufeng:fix/keep-alive-preserve-event-bus
Open

fix: preserve keep-alive browser event bus#5031
he-yufeng wants to merge 1 commit into
browser-use:mainfrom
he-yufeng:fix/keep-alive-preserve-event-bus

Conversation

@he-yufeng

@he-yufeng he-yufeng commented Jun 12, 2026

Copy link
Copy Markdown

Summary

  • keep Agent.close() from stopping the browser event bus when keep_alive=True
  • preserve the event queue and idle callback so CDP WebSocket handlers remain attached for the next agent run
  • add close-lifecycle tests for both keep-alive and non-keep-alive browser sessions

Fixes #4374.

Test plan

  • python -m py_compile browser_use/agent/service.py tests/ci/test_agent_close.py
  • python -m pytest tests/ci/test_agent_close.py -q
  • python -m ruff check browser_use/agent/service.py tests/ci/test_agent_close.py --no-fix
  • git diff --check

Summary by cubic

Keeps the browser event bus alive during Agent.close() when keep_alive=True, preserving the event queue and idle callback so CDP WebSocket handlers persist into the next run. Adds tests for both keep-alive and non-keep-alive close behavior.

  • Bug Fixes
    • Keep-alive: do not stop the event bus; preserve event_queue and _on_idle.
    • Non-keep-alive: still kill the browser session. Tests cover both modes.

Written for commit 856e3f2. Summary will update on new commits.

Review in cubic

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

No issues found across 2 files

Re-trigger cubic

Signed-off-by: Yufeng He <40085740+he-yufeng@users.noreply.github.com>
@he-yufeng he-yufeng force-pushed the fix/keep-alive-preserve-event-bus branch from 1e82e22 to 856e3f2 Compare June 12, 2026 23:55
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.

Bug: Agent.close() with keep_alive=True drops CDP WebSocket connections, triggering unnecessary reconnection cycle

1 participant