-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Make browser session ownership and facade mounts explicit #2892
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
miguelg719
wants to merge
10
commits into
evals/consolidation-01-hardbench
from
evals/consolidation-02-session-ownership
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
1381aa8
Make browser session ownership and facade mounts explicit
miguelg719 958e120
Fix facade ownership, artifact, and launch boundaries
miguelg719 3543024
Merge branch 'evals/consolidation-01-hardbench' into evals/consolidat…
miguelg719 be33a1e
Merge branch 'evals/consolidation-01-hardbench' into evals/consolidat…
miguelg719 90c20c1
Merge branch 'evals/consolidation-01-hardbench' into evals/consolidat…
miguelg719 de29b51
Merge branch 'evals/consolidation-01-hardbench' into evals/consolidat…
miguelg719 ef260fa
Merge commit '405d108381fb55cbcad9eef813ceda831c7af190' into HEAD
miguelg719 26a8845
Apply suggestion from @miguelg719
miguelg719 6c1c5d9
Merge commit '82e2562bc80878cf9bfafe951a3864008896e33e' into HEAD
miguelg719 0679a58
Keep general CLI help independent of harness startup
miguelg719 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "@browserbasehq/stagehand": patch | ||
| --- | ||
|
|
||
| Release a newly created Browserbase session when initial attachment fails, and support upload retries |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| import { EvalsError } from "../../errors.js"; | ||
|
|
||
| /** | ||
| * Browserbase's project default session timeout (15 min) is shorter than many | ||
| * benchmark tasks; every eval session gets an explicit one. Seconds, mirroring | ||
| * the Browserbase API. | ||
| */ | ||
| export const DEFAULT_EVAL_BROWSERBASE_SESSION_TIMEOUT_SECONDS = 3600; | ||
| const MAX_BROWSERBASE_SESSION_TIMEOUT_SECONDS = 21_600; | ||
|
|
||
| export function evalBrowserbaseSessionTimeoutSeconds(raw: string | undefined): number { | ||
|
miguelg719 marked this conversation as resolved.
|
||
| const value = raw?.trim(); | ||
| if (!value) return DEFAULT_EVAL_BROWSERBASE_SESSION_TIMEOUT_SECONDS; | ||
| const parsed = Number(value); | ||
| if ( | ||
| !/^\d+$/u.test(value) || | ||
| !Number.isSafeInteger(parsed) || | ||
| parsed < 60 || | ||
| parsed > MAX_BROWSERBASE_SESSION_TIMEOUT_SECONDS | ||
| ) { | ||
| throw new EvalsError( | ||
| `EVAL_BROWSERBASE_SESSION_TIMEOUT_SECONDS must be an integer between 60 and ${MAX_BROWSERBASE_SESSION_TIMEOUT_SECONDS} seconds (got "${value}").`, | ||
| ); | ||
| } | ||
| return parsed; | ||
| } | ||
|
|
||
| export function evalBooleanEnv(raw: string | undefined, fallback: boolean): boolean { | ||
| const v = raw?.trim().toLowerCase(); | ||
| if (!v) return fallback; | ||
| if (v === "1" || v === "true" || v === "yes" || v === "on") return true; | ||
| if (v === "0" || v === "false" || v === "no" || v === "off") return false; | ||
| throw new EvalsError(`Expected a boolean env value, got "${raw}".`); | ||
| } | ||
|
|
||
| /** | ||
| * Session settings shared by every Browserbase path the evals own — the | ||
| * Stagehand facade (via STAGEHAND_* env) and the runner-provided CDP target | ||
| * (playwright_mcp, chrome_devtools_mcp, playwright_code). Parity with the | ||
| * native Stagehand agent path: proxied + verified sessions, explicit timeout. | ||
| * EVAL_BROWSERBASE_PROXIES / _VERIFIED=0 to disable. | ||
| */ | ||
| export function evalBrowserbaseSessionOptions(env: NodeJS.ProcessEnv = process.env): { | ||
| timeoutSeconds: number; | ||
| proxies: boolean; | ||
| verified: boolean; | ||
| } { | ||
| return { | ||
| timeoutSeconds: evalBrowserbaseSessionTimeoutSeconds( | ||
| env.EVAL_BROWSERBASE_SESSION_TIMEOUT_SECONDS, | ||
| ), | ||
| proxies: evalBooleanEnv(env.EVAL_BROWSERBASE_PROXIES, true), | ||
| verified: evalBooleanEnv(env.EVAL_BROWSERBASE_VERIFIED, true), | ||
| }; | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| import { sanitizeErrorMessage } from "@browserbasehq/stagehand-integrations/harness"; | ||
| import type { BrowserSessionLoss } from "../contracts/tool.js"; | ||
|
|
||
| /** | ||
| * Wire strings the facade stdio server emits when its browser session is gone. | ||
| * Source of truth: packages/integrations/core/src/facade/contract.ts | ||
| * (BROWSER_SESSION_LOST_ERROR_PREFIX, SESSION_LOST_TELEMETRY_PREFIX). Mirrored | ||
| * here because evals consumes the integrations package through its built dist, | ||
| * and a facade build is allowed to lag behind the runner. | ||
| */ | ||
| export const BROWSER_SESSION_LOST_ERROR_PREFIX = "Browser session lost ("; | ||
| export const SESSION_LOST_TELEMETRY_PREFIX = "stagehand_facade_session_lost "; | ||
|
|
||
| export function isBrowserSessionLostError(message: string): boolean { | ||
| return message.startsWith(BROWSER_SESSION_LOST_ERROR_PREFIX); | ||
|
miguelg719 marked this conversation as resolved.
|
||
| } | ||
|
|
||
| /** Extracts the cause from "Browser session lost (<cause>). ..." */ | ||
| export function browserSessionLostCause(message: string): string | undefined { | ||
| if (!isBrowserSessionLostError(message)) return undefined; | ||
| return sanitizeErrorMessage(/^Browser session lost \((.*?)\)\./su.exec(message)?.[1] ?? message); | ||
| } | ||
|
|
||
| export function parseSessionLossTelemetry(line: string): BrowserSessionLoss | undefined { | ||
| if (!line.startsWith(SESSION_LOST_TELEMETRY_PREFIX)) return undefined; | ||
| try { | ||
| const parsed = JSON.parse(line.slice(SESSION_LOST_TELEMETRY_PREFIX.length)) as Record< | ||
| string, | ||
| unknown | ||
| >; | ||
| if (typeof parsed.cause !== "string") return undefined; | ||
| return { | ||
| cause: sanitizeErrorMessage(parsed.cause), | ||
| ...(typeof parsed.tool === "string" && { tool: parsed.tool }), | ||
| ...(typeof parsed.at === "string" && { at: parsed.at }), | ||
| }; | ||
| } catch { | ||
| return undefined; | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.