Skip to content

fix(browser): pin named browser_exec sessions to their own tab on shared browsers - #86924

Merged
teknium1 merged 1 commit into
mainfrom
fix/browser-exec-named-session-own-tab
Aug 15, 2026
Merged

fix(browser): pin named browser_exec sessions to their own tab on shared browsers#86924
teknium1 merged 1 commit into
mainfrom
fix/browser-exec-named-session-own-tab

Conversation

@teknium1

Copy link
Copy Markdown
Contributor

Summary

Named browser_exec sessions on a shared browser (local Chrome / /browser connect CDP) now pin themselves to a tab they created before any model code runs — closing the last clobber window left after #86916 and removing any dependence on the upstream browser-harness tab-isolation PR (browser-use/browser-harness#616).

Root cause of the residue: a fresh named daemon attaches to the first existing page of the shared browser, the same page a sibling daemon may hold. A named session that only issued js()/goto_url without ever calling new_tab() could still stomp another session's tab.

Changes

  • tools/browser_use_cli.py: _OWN_TAB_PREAMBLE prepended to model code for named sessions on shared browsers — once per daemon process (marker keyed uid + BU_NAME + daemon pid, so daemon restarts re-pin but mid-session tab switches are untouched), it Target.createTargets a fresh tab and switch_tab()s onto it. Best-effort: CDP failure degrades to pre-fix behavior, never blocks the exec.
  • Private per-name browsers skip the preamble via an internal env sentinel (_resolve_backend_cdp marks provider-keyed bu-named-* browsers and direct-API BU cloud; sentinel is popped before subprocess launch, never exported).
  • 5 new tests: preamble present for named+shared, absent for unnamed and for private provider browsers, sentinel never leaks into the subprocess env, preamble parses standalone and composed.

Validation

Result
tests/tools/test_browser_use_cli.py 92 passed
Sabotage (wiring removed) 2/5 new tests fail, pinning the fix
Live E2E, stock harness, shared Chrome, two named sessions with bare js() writes (no new_tab) EDGE-A / EDGE-B read back intact — PASS
Same E2E without the preamble reproduces the clobber (both sessions read EDGE-B)

Infographic

Own tab, every session

Follow-up to #86916. That fix gave named sessions their own daemon
(socket/log/pid) and their own provider browser — but on a SHARED local
Chrome / CDP browser, a fresh named daemon still attaches to the first
existing page, the same page a sibling daemon may hold. A named session
that never calls new_tab() could still stomp another's tab.

browser_exec now prepends a small preamble to the model's code for named
sessions on shared browsers: once per daemon process (marker keyed by
uid + BU_NAME + daemon pid), it creates a fresh tab via
Target.createTarget and switch_tab()s onto it before any model code
runs. Private per-name browsers (provider-keyed bu-named-<name>, or
direct-API Browser Use cloud) skip the preamble via an internal env
sentinel popped before launch — there's nobody to collide with, and the
extra tab would leak.

Best-effort by design: if the preamble's CDP calls fail, behavior
degrades to pre-fix, never blocks the exec.

E2E against a shared headless Chrome with the STOCK harness: two named
sessions issuing bare js() writes (no new_tab) kept distinct state
(EDGE-A/EDGE-B read back intact); the sabotage run without the preamble
reproduced the clobber (both read EDGE-B). Removes the dependency on the
upstream browser-harness tab-isolation PR for correctness.
@github-actions

github-actions Bot commented Aug 15, 2026

Copy link
Copy Markdown
Contributor

૮ >ﻌ< ა ci review

ran on 7641f28 — fix(browser): pin named sessions to their own tab on shared

⚠️ Warnings

OSV vulnerability scan · View job

5 known vulnerabilities found in pinned dependencies.

How to fix:

Review the findings in the Security tab. Update the affected dependencies if a patched version is available.


debug info

CI timings

CI timings · View report · View job

Wall time 3m43s vs 4m20s (-14.2%). 10 job(s) slower, 13 faster, 1 unchanged.

  • Python tests / Run tests slice 1/12: +54.0s
  • Python tests / Run tests slice 6/12: +39.0s
  • Python tests / Run tests slice 10/12: -39.0s
  • Python tests / Run tests slice 11/12: -19.0s
  • Check no committed infographics / check-no-committed-infographics: -19.0s

@alt-glitch alt-glitch added type/bug Something isn't working tool/browser Browser automation (CDP, Playwright) P2 Medium — degraded but workaround exists labels Aug 15, 2026
@alt-glitch

Copy link
Copy Markdown
Collaborator

This was generated by AI during triage.

Related to #86879, #83274, and #75597: these open PRs all address shared-CDP tab isolation through different mechanisms. This follow-up specifically protects a fresh named browser_exec daemon before its first new-tab call.

@teknium1
teknium1 merged commit c9a806e into main Aug 15, 2026
47 checks passed
@teknium1
teknium1 deleted the fix/browser-exec-named-session-own-tab branch August 15, 2026 11:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

P2 Medium — degraded but workaround exists tool/browser Browser automation (CDP, Playwright) type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants