D4Vinci/Scrapling · error · ValueError

Session '{session_id}' is no longer alive. Open a new sessio

Error message

Session '{session_id}' is no longer alive. Open a new session.

What it means

A session can exist in the registry but have a dead underlying browser (the session object's _is_alive flag is False) — typically because the Playwright browser/context crashed, was closed externally, or the page it was tracking closed. _get_session refuses to operate on it and tells the caller to reopen. The entry stays in the dict, which is why this is distinct from 'not found'.

Source

Thrown at scrapling/core/ai.py:167

        :param auth_token: Optional shared token that clients must send as `Authorization: Bearer <token>`.
            If omitted, the SCRAPLING_MCP_AUTH_TOKEN environment variable is used when set. It only applies
            to the streamable-http transport.
        """
        self._sessions: Dict[str, _SessionEntry] = {}
        self._executable_path = executable_path or environ.get(MCP_EXECUTABLE_PATH_ENV) or None
        self._auth_token = auth_token or environ.get(MCP_AUTH_TOKEN_ENV) or None

    def _resolve_executable_path(self, executable_path: Optional[str]) -> Optional[str]:
        """Return a per-call executable path or the server-wide default."""
        return executable_path or self._executable_path

    def _get_session(self, session_id: str, expected_type: Optional[SessionType]) -> _SessionEntry:
        """Look up a session by ID, optionally validating its type. Pass `None` to skip the type check."""
        entry = self._sessions.get(session_id)
        if entry is None:
            raise ValueError(f"Session '{session_id}' not found. Use list_sessions to see active sessions.")
        if not entry.session._is_alive:
            raise ValueError(f"Session '{session_id}' is no longer alive. Open a new session.")
        if expected_type is not None and entry.session_type != expected_type:
            raise ValueError(
                f"Session '{session_id}' is a '{entry.session_type}' session, but this tool requires a "
                f"'{expected_type}' session. Use the matching fetch tool for your session type."
            )
        return entry

    async def open_session(
        self,
        session_type: SessionType,
        session_id: Optional[str] = None,
        headless: bool = True,
        google_search: bool = True,
        real_chrome: bool = False,
        wait: int | float = 0,
        proxy: Optional[str | Dict[str, str]] = None,
        timezone_id: str | None = None,
        locale: str | None = None,

View on GitHub (pinned to 5d213a2d47)

Solutions

  1. Close the dead entry: close_session(session_id) to free the registry slot, then open_session again
  2. Check container/browser health: memory limits, --no-sandbox requirements, missing libs, and Docker seccomp settings for Chrome
  3. Structure agent code to reopen transparently when this error is raised

Example fix

# before
await fetch_with_session(session_id=sid, url=...)  # ValueError: no longer alive

# after
try:
    await fetch_with_session(session_id=sid, url=url)
except ValueError:
    await close_session(sid)
    sid = (await open_session(session_type='dynamic')).session_id
    await fetch_with_session(session_id=sid, url=url)
Defensive patterns

Strategy: fallback

Validate before calling

infos = {s.session_id for s in await list_sessions()}
if sid not in infos:
    sid = (await open_session(session_type='dynamic')).session_id

Try / catch

try:
    await fetch_with_session(session_id=sid, url=url)
except ValueError as e:
    if 'no longer alive' in str(e):
        await close_session(sid)  # free the dead entry (ignore 'not found')
        sid = (await open_session(session_type='dynamic')).session_id
        await fetch_with_session(session_id=sid, url=url)
    else:
        raise

Prevention

When it happens

Trigger: The browser process for the session crashed (OOM, killed, display server failure in headless containers), or the session was closed at the Playwright level while the MCP entry remained. The next fetch/screenshot on that session_id raises this.

Common situations: Long-lived agent sessions in CI containers where Chrome gets OOM-killed or sandbox restrictions kill the browser, stale sessions left after exceptions, or docker images missing shared libraries causing delayed browser death.

Related errors


AI-assisted analysis of D4Vinci/Scrapling@5d213a2d47 (2026-08-14). Data as JSON: /api/errors/44176ba1c546134a. Report an issue: GitHub.