Skip to content

Conversation

@seanmcguire12
Copy link
Member

why

  • if a Browserbase session times out, we are currently logging a generic CDP transport closed message

what changed

  • we can grab the status of the session from the BB API and yield a more informative log

test plan

  • unit tests

@changeset-bot
Copy link

changeset-bot bot commented Nov 21, 2025

🦋 Changeset detected

Latest commit: 45ec7f5

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
@browserbasehq/stagehand Patch
@browserbasehq/stagehand-evals Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@greptile-apps
Copy link
Contributor

greptile-apps bot commented Nov 21, 2025

Greptile Overview

Greptile Summary

Enhanced Browserbase session timeout error logging by querying session status from the Browserbase API when CDP transport closes, replacing generic "CDP transport closed" messages with informative session-specific status messages.

  • Added _logBrowserbaseSessionStatus() method that retrieves session status via Browserbase API
  • Integrated non-blocking session status logging into the _onCdpClosed() handler for Browserbase sessions
  • Properly handles API failures gracefully with try-catch to ensure shutdown isn't blocked

Confidence Score: 5/5

  • This PR is safe to merge with minimal risk
  • The changes are straightforward and well-implemented: adds observability without affecting core functionality, uses fire-and-forget pattern appropriately to avoid blocking shutdown, handles errors gracefully, and includes proper type checking
  • No files require special attention

Important Files Changed

File Analysis

Filename Score Overview
packages/core/lib/v3/v3.ts 5/5 Added Browserbase session status logging when CDP transport closes, improving observability for timeout scenarios

Sequence Diagram

sequenceDiagram
    participant CDP as CDP Transport
    participant V3 as V3 Instance
    participant BB as Browserbase API
    participant Logger as Logger

    Note over CDP,Logger: Session Timeout Scenario
    
    CDP->>V3: Transport closed event (why: "session timeout")
    V3->>V3: _onCdpClosed(why)
    
    alt state.kind === "BROWSERBASE"
        V3->>V3: void _logBrowserbaseSessionStatus()
        Note over V3: Fire-and-forget call (non-blocking)
        
        par Async Logging
            V3->>BB: sessions.retrieve(sessionId)
            BB-->>V3: { id, status: "TIMED_OUT" }
            V3->>Logger: log("Browserbase session timed out")
        and Immediate Shutdown
            V3->>V3: _immediateShutdown("CDP transport closed: session timeout")
            V3->>Logger: log("initiating shutdown")
            V3->>Logger: log("closing resources")
            V3->>V3: close({ force: true })
        end
    else state.kind !== "BROWSERBASE"
        V3->>V3: _immediateShutdown("CDP transport closed: session timeout")
    end
Loading

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

1 file reviewed, no comments

Edit Code Review Agent Settings | Greptile

@seanmcguire12 seanmcguire12 merged commit 1dd7d43 into main Nov 21, 2025
27 of 28 checks passed
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.

3 participants