-
Notifications
You must be signed in to change notification settings - Fork 228
autobrowse: tear down self-owned browser session on exit #123
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -271,6 +271,27 @@ function executeCommand(command) { | |
| } | ||
| } | ||
|
|
||
| // evaluate.mjs leaves the browser session running by default so a caller can | ||
| // attach (e.g. browser-trace bisect in the browse.sh pipeline). But when WE | ||
| // created the session — no caller-managed session attached via BROWSE_SESSION | ||
| // or --session — nothing else will clean it up, and the inner agent only | ||
| // *might* run `browse stop` (LLMs routinely skip the trailing cleanup step). | ||
| // So tear down the daemon ourselves: killing it drops the CDP connection, and | ||
| // our own `browse open` runs without --keep-alive, so the remote session ends. | ||
| function ownsSession() { | ||
| return !process.env.BROWSE_SESSION && !getArg("session"); | ||
| } | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Equals-form session flag ignoredMedium Severity
Reviewed by Cursor Bugbot for commit e473b74. Configure here. |
||
|
|
||
| function teardownOwnedSession() { | ||
| if (!ownsSession()) return; | ||
| try { | ||
| execFileSync("browse", ["stop"], { timeout: 15_000, stdio: "ignore" }); | ||
| console.error("Stopped browser session (evaluate.mjs owned it)."); | ||
| } catch { | ||
| // best-effort — never fail the run over cleanup | ||
| } | ||
| } | ||
|
|
||
| function buildSystemPrompt(strategy, traceDir, browseEnv) { | ||
| const openFlag = browseEnv === "remote" ? "--remote" : "--local"; | ||
| const envDesc = browseEnv === "remote" | ||
|
|
@@ -610,10 +631,12 @@ async function main() { | |
| tokens_out: totalOutputTokens, | ||
| trace_dir: traceDir, | ||
| }; | ||
| teardownOwnedSession(); | ||
| console.log(JSON.stringify(result)); | ||
| } | ||
|
|
||
| main().catch((err) => { | ||
| console.error("Fatal error:", err); | ||
| teardownOwnedSession(); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Interrupt exits skip session teardownMedium Severity This change adds Reviewed by Cursor Bugbot for commit e473b74. Configure here. |
||
| process.exit(1); | ||
| }); | ||


There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Session flag skips teardown only
Medium Severity
ownsSession()treats a--sessionCLI value like caller-managed attachment (same asBROWSE_SESSION), but the harness never copies that flag intoprocess.env.BROWSE_SESSION. The inner agent’sbrowsesubprocesses still use the default session, while exit skipsteardownOwnedSession(), so a remote Browserbase session opened during the run can keep running and billing afterevaluate.mjsexits.Reviewed by Cursor Bugbot for commit e473b74. Configure here.