Skip to content

fix(browserbase): disable Stagehand hosted API to unblock connect#3230

Merged
tofikwest merged 2 commits into
mainfrom
tofik/browserbase-disable-hosted-api
Jun 22, 2026
Merged

fix(browserbase): disable Stagehand hosted API to unblock connect#3230
tofikwest merged 2 commits into
mainfrom
tofik/browserbase-disable-hosted-api

Conversation

@tofikwest

@tofikwest tofikwest commented Jun 22, 2026

Copy link
Copy Markdown
Contributor

Problem

Browser Automations won't connect — clicking Connect fails with "Unknown error: 400". This is a different failure from the premature-close one fixed in #3225.

Root cause (verified)

/navigatecreateStagehand()stagehand.init(). With disableAPI left at its default (false), Stagehand first calls its hosted managed API (POST https://api.stagehand.browserbase.com/v1/sessions/start) before connecting via CDP. That hosted call returns a 400, and Stagehand throws "Unknown error: 400" after stripping the real reason out of the error (@browserbasehq/stagehand/.../v3/api.js:85-92).

The key insight from a full audit of the feature: this feature needs nothing from the hosted API.

  • navigateToUrl only does page.goto() + sendCDP() — pure CDP, no LLM.
  • checkLoginStatus (verify) and evidence runs use extract / agent({cua}), which run against local handlers + our ANTHROPIC_API_KEY.

All three paths route through createStagehand, so the hosted-API round-trip is the single point of failure for connect, login-verify, and scheduled evidence runs.

Fix

Set disableAPI: true in the Stagehand constructor. Verified against Stagehand v3.3.0 internals:

  • apiClient is built only inside the if (!disableAPI && !experimental) block (v3.js:826/827), so disableAPI:trueapiClient stays null → no /sessions/start call → the 400 cannot occur.
  • The Browserbase session still resumes over CDP (createBrowserbaseSession runs unconditionally at v3.js:865).
  • extract (v3.js:1110 else-branch) and the CUA agent (v3.js:1594 else-branch) fall back to local handlers when apiClient is null; anthropic/claude-sonnet-4-6 is in AVAILABLE_CUA_MODELS and resolves via @ai-sdk/anthropic (dep present).

Also in this PR:

  • Forward Stagehand's own error logs into the NestJS logger (logger constructor hook). Stagehand strips upstream error bodies from its throws, so without this we're blind — this is why "Unknown error: 400" was opaque. Now the real reason lands in our logs.
  • Fix Trigger.dev maxDuration units for the scheduled runner + orchestrator: they were 1000*60*N (≈166h / 500h), so the intended 10-/30-minute safety abort never tripped. maxDuration is in seconds (matches the convention in run-device-sync.ts and its spec).

The init() retry from #3225 is kept — it still protects the CDP session-resume round-trip (a different upstream than the hosted API).

Testing

  • New test asserts createStagehand constructs Stagehand with disableAPI: true.
  • All 86 browserbase + trigger/browser-automation tests pass; typecheck clean for changed files.

Honest caveat

I verified in code that extract/CUA fall back to local handlers, but I could not exercise a live Browserbase run. Connect/navigate is no-LLM and fully unblocked; please confirm one verify ("Check & Save") and one evidence run so we validate local-inference parity. If anything still fails, the new logger forwarding will now surface the real reason in the API logs instead of "Unknown error: 400".

🤖 Generated with Claude Code

https://claude.ai/code/session_013zSwXMqVNvWLJBZEot9x12


Summary by cubic

Disable Stagehand’s hosted API to stop “Unknown error: 400” on Connect and run automations via CDP + local inference. Also fix task timeouts and forward Stagehand logs for clearer errors.

  • Bug Fixes
    • Pass disableAPI: true to Stagehand so it skips POST /sessions/start; CDP resume still works and extract/CUA run locally with ANTHROPIC_API_KEY.
    • Forward Stagehand error logs to the NestJS logger via the logger hook to surface real upstream reasons.
    • Keep init() retry for CDP session resume.
    • Set maxDuration in seconds in run-browser-automation (10m) and browser-automations-schedule (30m).

Written for commit d74c644. Summary will update on new commits.

Review in cubic

"Unknown error: 400" on Connect came from Stagehand's hosted API
(POST /sessions/start) — a separate upstream from the premature-close
fix. We create and own the Browserbase session ourselves and only need
CDP navigation plus local inference, so the hosted-API round-trip is
both unnecessary and the single point of failure for connect,
login-check, and evidence runs (all route through createStagehand).

Set disableAPI:true so Stagehand skips /sessions/start: the session
still resumes over CDP, and extract/act/agent run locally against
ANTHROPIC_API_KEY (verified: apiClient is only built inside the
!disableAPI guard, and extract/agent fall back to local handlers when
it is null). Also forward Stagehand's own error logs into the NestJS
logger, because it strips upstream error bodies from its throws — so a
future failure surfaces the real reason instead of "Unknown error: 400".

Also fix the Trigger.dev maxDuration units for the scheduled runner and
orchestrator: they were 1000*60*N (~166h / ~500h), so the intended
10/30-minute safety abort never tripped. maxDuration is in SECONDS.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013zSwXMqVNvWLJBZEot9x12
@vercel

vercel Bot commented Jun 22, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
comp-framework-editor Ready Ready Preview, Comment Jun 22, 2026 7:15pm
2 Skipped Deployments
Project Deployment Actions Updated (UTC)
app Skipped Skipped Jun 22, 2026 7:15pm
portal Skipped Skipped Jun 22, 2026 7:15pm

Request Review

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

No issues found across 4 files

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

Re-trigger cubic

@vercel vercel Bot temporarily deployed to Preview – app June 22, 2026 19:14 Inactive
@vercel vercel Bot temporarily deployed to Preview – portal June 22, 2026 19:14 Inactive
@tofikwest tofikwest merged commit 47943de into main Jun 22, 2026
10 checks passed
@tofikwest tofikwest deleted the tofik/browserbase-disable-hosted-api branch June 22, 2026 19:17
@claudfuen

Copy link
Copy Markdown
Contributor

🎉 This PR is included in version 3.87.2 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants