Skip to content

[fix]: report cached browser start failures in browse doctor - #3423

Closed
kenneshagarg wants to merge 2 commits into
browserbase:mainfrom
kenneshagarg:fix/doctor-init-failure
Closed

kenneshagarg wants to merge 2 commits into
browserbase:mainfrom
kenneshagarg:fix/doctor-init-failure

Conversation

@kenneshagarg

@kenneshagarg kenneshagarg commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

why

When a session's browser fails to start, every browse command errors but browse doctor still reports all [ok]. DriverSessionManager keeps the failure for retry backoff, but status() doesn't expose it, so doctor can't tell a failed start from a daemon that hasn't started a browser yet. Root cause identified by @DevChiniwala in #3359.

Addresses part of #3359: this fixes the false all-clear from browse doctor, not the underlying ECONNREFUSED, which I haven't reproduced with a managed local browser.

what changed

  • status() now includes initError while a failed start is cached. it's absent otherwise, so existing status output doesn't change.
  • browse doctor reports the failure in the existing row for the session's target (browser, browserbase, or cdp), with the first line of the error, and puts the full error in --json details. it doesn't launch Chrome or retry the failed start.
  • no Fix: line, since the right fix depends on the cause.

I put this in status() rather than an explicit launch probe so doctor stays read-only. happy to change that if you'd prefer a probe.

test plan

  • driver-foundation.test.ts: a real DriverSessionManager with a rejected launch reports initError from status() without launching again, and reports none before any attempt.
  • doctor.test.ts: for each target kind, initError produces a fail verdict and exactly one row for that component, with the first-line message, the full error in details, and the rendered [fail] line. a running daemon without a failed start adds no component row.
  • both new tests fail without the source change.
  • ran the built CLI: browse open against a closed CDP port, then browse doctor, which printed [fail] cdp last start failed: Failed to open CDP WebSocket and exited 1.
  • pnpm check passes. CLI tests: 557 passed, 1 failed. that failure, cli-surface.test.ts > prints browse root help, also fails without this change. check-changesets also fails on main because of the existing agent-discoverability-metadata.md.

🤖 Generated with Claude Code


Summary by cubic

Fixes browse doctor reporting all [ok] when a session's browser failed to start, so the failure is no longer hidden. The daemon now exposes the cached start failure through status().initError, and browse doctor renders a [fail] in the session's target row (browser, browserbase, or cdp) with the first line of the error; the full error appears in --json details. The check is read-only and doesn't relaunch or retry the failed start. Addresses part of #3359.

Written for commit 4c4bcfa. Summary will update on new commits.

View guided diff

DriverSessionManager keeps the last init failure for retry backoff, but
status() did not expose it, so browse doctor reported a daemon whose
browser failed to start the same as one that had not started yet.

Addresses part of browserbase#3359.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@github-actions

github-actions Bot commented Nov 9, 2026

Copy link
Copy Markdown
Contributor

This PR is from an external contributor and must be approved by a stagehand team member with write access before CI can run.
Approving the latest commit mirrors it into an internal PR owned by the approver.
If new commits are pushed later, the internal PR stays open but is marked stale until someone approves the latest external commit and refreshes it.

@github-actions github-actions Bot added external-contributor Tracks PRs mirrored from external contributor forks. external-contributor:awaiting-approval Waiting for a stagehand team member to approve the latest external commit. labels Nov 9, 2026
@changeset-bot

changeset-bot Bot commented Nov 9, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 4c4bcfa

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

This PR includes changesets to release 1 package
Name Type
browse 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

Copy link
Copy Markdown
Collaborator

Thanks @Kennesha, this is a nice addition. Having doctor surface the last failed start is really useful. I have two pieces of feedback.

1. One row per component (for this PR). Right now a failed start shows up as a second browser row, so in managed-local mode the report contradicts itself:

Browse doctor

[ok]   runtime  node 22.11.0
[ok]   daemon   running, pid 48213
[ok]   browser  managed local browser, headless
[fail] browser  last start failed: Failed to launch the browser process

Status: fail

Doctor shows one row per component (daemon, browser, browserbase, cdp), so I'd rather the failure replace the existing row for whatever target you're using. Here's what we'd expect for a local browser:

Browse doctor

[ok]   runtime  node 22.11.0
[ok]   daemon   running, pid 48213
[fail] browser  last start failed: Failed to launch the browser process

Status: fail

And for a remote session:

Browse doctor

[ok]   runtime      node 22.11.0
[ok]   daemon       running, pid 48213
[fail] browserbase  last start failed: 401 Unauthorized

Status: fail

When there's no recorded failure, the output stays the same as today.

2. A Fix: hint (follow-up, not blocking). Other failing checks end with a suggested next step. For example, the cdp check prints Fix: start Chrome with --remote-debugging-port=9222. The new failure doesn't have one yet, so the report tells you something broke but not what to try. It might be worth looking into in a separate PR, since the right hint probably depends on the kind of error. Something like this:

[fail] browserbase  last start failed: 401 Unauthorized

Status: fail
Fix: check BROWSERBASE_API_KEY, then run `browse stop` and retry

Once #1 is in and CI is approved and green, this should be good to go.

Show the cached start failure in the existing component row for the
session's target (browser, browserbase, or cdp) instead of always adding
a separate browser row.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@kenneshagarg

Copy link
Copy Markdown
Contributor Author

Thanks @shrey150! Updated in 4c4bcfa: the failure now replaces the component row for the session's target (browser for managed-local, browserbase for remote, cdp for CDP and auto-connect), and output with no recorded failure is unchanged. The doctor tests cover each target kind and check there's exactly one row per component. I'll leave the Fix: hint for a follow-up as you suggested.

@shrey150 shrey150 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks for the quick fix! Verified end to end: a failed start now replaces the target's doctor row (browser / browserbase / cdp) instead of adding a duplicate.

@github-actions github-actions Bot added external-contributor:mirrored An internal mirrored PR currently exists for this external contributor PR. and removed external-contributor:awaiting-approval Waiting for a stagehand team member to approve the latest external commit. labels Nov 10, 2026
@github-actions

Copy link
Copy Markdown
Contributor

This PR was approved by @shrey150 and mirrored to #3439. All further discussion should happen on that PR.

@github-actions github-actions Bot closed this Nov 10, 2026
shrey150 pushed a commit that referenced this pull request Nov 10, 2026
… doctor (#3439)

Mirrored from external contributor PR #3423 after approval by @shrey150.

Original author: @kenneshagarg
Original PR: #3423
Approved source head SHA: `4c4bcfa62a31868364139ab8a1e7f1df1c464dfe`

@kenneshagarg, please continue any follow-up discussion on this mirrored
PR. When the external PR gets new commits, this same internal PR will be
marked stale until the latest external commit is approved and refreshed
here.

## Original description
# why

When a session's browser fails to start, every `browse` command errors
but `browse doctor` still reports all `[ok]`. `DriverSessionManager`
keeps the failure for retry backoff, but `status()` doesn't expose it,
so doctor can't tell a failed start from a daemon that hasn't started a
browser yet. Root cause identified by @DevChiniwala in #3359.

Addresses part of #3359: this fixes the false all-clear from `browse
doctor`, not the underlying `ECONNREFUSED`, which I haven't reproduced
with a managed local browser.

# what changed

- `status()` now includes `initError` while a failed start is cached.
it's absent otherwise, so existing `status` output doesn't change.
- `browse doctor` reports the failure in the existing row for the
session's target (`browser`, `browserbase`, or `cdp`), with the first
line of the error, and puts the full error in `--json` details. it
doesn't launch Chrome or retry the failed start.
- no `Fix:` line, since the right fix depends on the cause.

I put this in `status()` rather than an explicit launch probe so doctor
stays read-only. happy to change that if you'd prefer a probe.

# test plan

- `driver-foundation.test.ts`: a real `DriverSessionManager` with a
rejected launch reports `initError` from `status()` without launching
again, and reports none before any attempt.
- `doctor.test.ts`: for each target kind, `initError` produces a `fail`
verdict and exactly one row for that component, with the first-line
message, the full error in details, and the rendered `[fail]` line. a
running daemon without a failed start adds no component row.
- both new tests fail without the source change.
- ran the built CLI: `browse open` against a closed CDP port, then
`browse doctor`, which printed `[fail] cdp last start failed: Failed to
open CDP WebSocket` and exited 1.
- `pnpm check` passes. CLI tests: 557 passed, 1 failed. that failure,
`cli-surface.test.ts > prints browse root help`, also fails without this
change. `check-changesets` also fails on `main` because of the existing
`agent-discoverability-metadata.md`.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

<!-- This is an auto-generated description by cubic. -->
---
## Summary by cubic
Fixes `browse doctor` reporting all `[ok]` when a session's browser
failed to start, so the failure is no longer hidden. The daemon now
exposes the cached start failure through `status().initError`, and
`browse doctor` renders a `[fail]` in the session's target row
(`browser`, `browserbase`, or `cdp`) with the first line of the error;
the full error appears in `--json` details. The check is read-only and
doesn't relaunch or retry the failed start. Addresses part of #3359.

<sup>Written for commit 4c4bcfa.
Summary will update on new commits.</sup>

<a
href="https://cubic.dev/pr/browserbase/stagehand/pull/3423?utm_source=github"
target="_blank" rel="noopener noreferrer"
data-no-image-dialog="true"><picture><source
media="(prefers-color-scheme: dark)"
srcset="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"><source
media="(prefers-color-scheme: light)"
srcset="https://www.cubic.dev/buttons/review-in-cubic-light.svg"><img
alt="View guided diff"
src="https://www.cubic.dev/buttons/review-in-cubic-light.svg"></picture></a>

<!-- End of auto-generated description by cubic. -->

<!-- external-contributor-pr:owned source-pr=3423
source-sha=4c4bcfa62a31868364139ab8a1e7f1df1c464dfe claimer=shrey150 -->

---------

Co-authored-by: kenneshagarg <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
@github-actions github-actions Bot added external-contributor:completed The mirrored PR has been merged and the external contributor flow is complete. and removed external-contributor:mirrored An internal mirrored PR currently exists for this external contributor PR. labels Nov 10, 2026
@github-actions

Copy link
Copy Markdown
Contributor

The mirrored PR #3439 has been merged into main. This original external contributor PR will stay closed as completed.

aryansahai22 added a commit to aryansahai22/stagehand that referenced this pull request Nov 15, 2026
…ch the fix hint to the target's doctor row
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

external-contributor:completed The mirrored PR has been merged and the external contributor flow is complete. external-contributor Tracks PRs mirrored from external contributor forks.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants