Bug: StorageStateWatchdog logs ERROR every auto-save interval once the CDP client is gone, and reset() leaves its loop running

Author: HardMax71Created Sep 25, 2026Updated Sep 25, 2026

Browser Use Version

0.13.10 and main at d8110c5 (same on 0.13.1)

Bug Description, Steps to Reproduce, Screenshots

Once a session loses its CDP client, StorageStateWatchdog's auto-save loop logs [StorageStateWatchdog] Error in monitoring loop: CDP client not initialized - browser may not be connected yet at ERROR every auto_save_interval (60 s as BrowserSession sets it up), and never stops on its own.

Two things combine:

  1. The "no client" guards in the watchdog are if not self.browser_session.cdp_client: (storage_state_watchdog.py#L137, also #L226, #L349, #L362), but BrowserSession.cdp_client is a property that asserts the client exists (session.py#L1339-L1342). So with no client the guard raises AssertionError instead of returning, and _monitor_storage_changes catches it and logs ERROR (#L119-L133). Called directly, get_current_cookies() and add_cookies() raise the same way instead of returning [] / warning (events are fine: watchdog_base already skips handlers while is_cdp_connected is False).
  2. BrowserSession.reset() clears _cdp_client_root and sets _storage_state_watchdog = None without stopping the watchdog's monitoring task (session.py#L662, #L676). The task is only cancelled from on_BrowserStopEvent, so when a reset happens without that event reaching the watchdog (a crash, a stop that did not go through BrowserStopEvent), the loop keeps running on the reset session, and keeps it referenced.

The repro below needs no browser: it starts monitoring with a stand-in client, then drops the client the way reset() does.

Failing Python Code

python
import asyncio
import logging
from importlib.metadata import version

from browser_use.browser.session import BrowserSession
from browser_use.browser.watchdogs.storage_state_watchdog import StorageStateWatchdog


class Capture(logging.Handler):
    def __init__(self) -> None:
        super().__init__(level=logging.DEBUG)
        self.records: list[logging.LogRecord] = []

    def emit(self, record: logging.LogRecord) -> None:
        self.records.append(record)


async def main() -> None:
    print("browser-use", version("browser-use"))
    session = BrowserSession(headless=True)
    StorageStateWatchdog.model_rebuild()
    wd = StorageStateWatchdog(event_bus=session.event_bus, browser_session=session, auto_save_interval=0.05)

    try:
        changed = await wd._have_cookies_changed()
        print("guard returned", changed)
    except AssertionError as e:
        print("guard raised AssertionError:", e)

    cap = Capture()
    logging.getLogger("browser_use").addHandler(cap)
    session._cdp_client_root = object()  # stand-in for a connected client
    await wd._start_monitoring()
    session._cdp_client_root = None  # what reset() does
    await asyncio.sleep(0.6)
    errors = [r for r in cap.records if r.levelno >= logging.ERROR and "monitoring loop" in r.getMessage()]
    print(f"monitoring loop ERROR lines in 0.6 s at 0.05 s interval: {len(errors)}")
    if errors:
        print("first:", errors[0].getMessage())
    await wd._stop_monitoring()


asyncio.run(main())

LLM Model

None (no agent or LLM involved)

Operating System & Browser Versions

macOS, Python 3.12; the repro launches no browser

Full DEBUG Log Output

browser-use 0.13.10
guard raised AssertionError: CDP client not initialized - browser may not be connected yet
monitoring loop ERROR lines in 0.6 s at 0.05 s interval: 11
first: [StorageStateWatchdog] Error in monitoring loop: CDP client not initialized - browser may not be connected yet

Fix: use the non-asserting browser_session.is_cdp_connected in the four guards, as AboutBlankWatchdog and watchdog_base already do, and stop the watchdog's monitoring in reset() before it is dropped. PR follows.