Skip to content

Open-source Python library for AI browser agents, plus Browser Use Cloud: stealth browsers and a hosted agent API.

style: tighten ResilientEventBus docstring and comments

Saurav Panda5123e4fc087c
diff --git a/browser_use/browser/session.py b/browser_use/browser/session.py
index fb0209d1b..6a3def62e 100644
--- a/browser_use/browser/session.py
+++ b/browser_use/browser/session.py
@@ -104,27 +104,16 @@ class CDPSession(BaseModel):
class ResilientEventBus(EventBus):
- """``EventBus`` whose ``step()``/``wait_until_idle()`` tolerate a torn-down bus.
-
- On a warm-Lambda resume the V2 worker can reuse a ``keep_alive`` ``BrowserSession``
- whose event bus was already stopped and had its async primitives (``event_queue`` /
- ``_on_idle``) nulled out by ``Agent.close()`` (done to release the event loop). In that
- state bubus's ``EventBus.step()`` asserts ``EventBus._start() must be called before
- step()``, which crashed the worker mid-run and dead-lettered the task (ENG-5280).
-
- The nulling is deliberate — it lets the next ``dispatch()`` recreate a fresh queue and
- ``_start()`` the bus again — so instead of changing teardown we make ``step()`` and
- ``wait_until_idle()`` safe no-ops when the bus has not been started. A later
- ``dispatch()`` still restarts the bus as usual.
+ """EventBus whose step()/wait_until_idle() no-op on a torn-down bus instead of asserting.
+
+ Agent.close() stops a keep_alive session's bus and nulls its async primitives to release
+ the event loop. On warm-Lambda resume the worker can step() it before a dispatch() restarts
+ it; stock bubus then asserts "_start() must be called before step()" (ENG-5280).
"""
def __init__(self, name: str | None = None, **kwargs: Any) -> None:
- # bubus derives the default bus name from the class name, which would make session
- # buses ``ResilientEventBus_*`` instead of ``EventBus_*``. Keep the original prefix so
- # bus names stay stable for logging/identification (matches EventBus's own scheme).
- if name is None:
- name = f'EventBus_{uuid7str()[-8:]}'
- super().__init__(name=name, **kwargs)
+ # Keep the EventBus_ name prefix (bubus would otherwise derive it from the class name).
+ super().__init__(name=name or f'EventBus_{uuid7str()[-8:]}', **kwargs)
async def step(
self,
diff --git a/tests/ci/test_event_bus_resilience.py b/tests/ci/test_event_bus_resilience.py
index 17445ea3a..0eaa206c3 100644
--- a/tests/ci/test_event_bus_resilience.py
+++ b/tests/ci/test_event_bus_resilience.py
@@ -1,13 +1,8 @@
"""Regression tests for ENG-5280: V2 worker crash on warm-Lambda resume.
-When a ``keep_alive`` ``BrowserSession`` is reused across warm Lambda invocations, its
-event bus is stopped and has its async primitives (``event_queue`` / ``_on_idle``) nulled
-out by ``Agent.close()`` to release the event loop. On resume the worker can ``step()`` the
-torn-down bus before any ``dispatch()`` restarts it. Stock ``bubus.EventBus.step()`` asserts
-``EventBus._start() must be called before step()`` in that state, crashing the run.
-
-``BrowserSession`` therefore uses ``ResilientEventBus``, whose ``step()`` / ``wait_until_idle()``
-are safe no-ops on a torn-down bus while a later ``dispatch()`` still restarts it.
+A reused keep_alive session bus is stopped and nulled by Agent.close(); on resume the worker
+can step() it before a dispatch() restarts it, which makes stock bubus assert. ResilientEventBus
+no-ops step()/wait_until_idle() in that state while still restarting on the next dispatch().
"""
import asyncio