Conversation
|
ben-reitz
added this pull request to stack #2373
September 25, 2026 08:21
Contributor
|
✅ agents import sizes: no significant changes ( |
agents
@cloudflare/ai-chat
@cloudflare/codemode
hono-agents
@cloudflare/shell
@cloudflare/think
@cloudflare/voice
@cloudflare/worker-bundler
commit: |
ben-reitz
force-pushed
the
feat/browser-session-active-tab
branch
2 times, most recently
from
September 25, 2026 11:27
9277c20 to
5eee444
Compare
ben-reitz
force-pushed
the
feat/browser-session-active-tab
branch
2 times, most recently
from
September 25, 2026 11:32
5eee444 to
88de7c7
Compare
ben-reitz
marked this pull request as ready for review
September 25, 2026 13:12
ben-reitz
force-pushed
the
feat/browser-session-active-tab
branch
from
September 25, 2026 13:48
88de7c7 to
5306161
Compare
ben-reitz
force-pushed
the
feat/browser-session-active-tab
branch
2 times, most recently
from
September 25, 2026 14:54
98e8640 to
dd053df
Compare
ben-reitz
force-pushed
the
feat/browser-session-active-tab
branch
3 times, most recently
from
September 28, 2026 12:08
0775b7e to
fb340bb
Compare
Named session records gain an optional activeTargetId, and connect() returns setActiveTarget(), which writes it only while the record still holds the same browser, so a stale connection never resurrects a closed or replaced session. A replacement browser starts with no active tab. NamedBrowserSessions and BrowserSessions also expose their binding through a browser getter. Internal; used by the persistent browser connector.
ben-reitz
force-pushed
the
feat/browser-session-active-tab
branch
from
September 28, 2026 12:29
fb340bb to
d9e5c51
Compare
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
TL;DR: makes sessions remember the current tab.
Named sessions now remember the agent's current tab, so when the model references
sessionId: "active"with the new connector we add in #2371, it will point at the same tab from one execution to the next. The record stores the tab'stargetIdbecause targets survive reconnects and CDP session ids don't.StoredBrowserSession { sessionId, createdAt, updatedAt, closedAt?, + activeTargetId? } connect(name) → { name, sessionId, restarted, cdp, + activeTargetId?, + setActiveTarget(targetId | undefined): Promise<boolean>, + spec(): Promise<SearchableCdpSpec> }setActiveTargetand the activity touch share one#updatehelper. It writes under the per-name lock only while the record still holds the same browser, and returnsfalseotherwise. A closed or replaced session is never brought back.spec()reads the CDP protocol from this connection's own browser (the path added in refactor(agents): share connector validation and load the CDP spec from a live session #2369). The connector uses it without ever seeing the Browser Run binding.Everything here is internal.
BrowserSessionsgets exported in #2372.Architecture diff
Each outlined box is a component this PR changes, with one green box per change. Grey boxes are unchanged, and dashed boxes arrive later in the stack.
flowchart TB classDef ctx fill:none,stroke:#8c959f,color:#8c959f classDef changes fill:#dafbe1,stroke:#1a7f37,color:#1f2328 classDef later fill:none,stroke:#8c959f,stroke-dasharray:4 3,color:#57606a Agent["Agent (host Durable Object)"]:::ctx BS["BrowserSessions · capability.ts"]:::ctx subgraph NBS["NamedBrowserSessions · session-core.ts"] direction TB N1["+ connect() returns activeTargetId, setActiveTarget()"]:::changes N2["+ connected session gets spec()"]:::changes N3["+ stale connections can't write the record"]:::changes N1 ~~~ N2 ~~~ N3 end subgraph Store["StoredBrowserSession · session-manager.ts"] Sc["+ activeTargetId?"]:::changes end BR["Browser Run"]:::ctx Spec["loadCdpSpec · spec.ts"]:::ctx Next["BrowserSessionConnector (next PR)<br/>reads and saves the active tab"]:::later Agent -->|lifecycle.use| BS BS --> NBS NBS -->|"one record per name"| Store NBS -->|"create · probe · CDP socket"| BR NBS -->|"spec() for this sessionId"| Spec Next -.-> BS style NBS stroke:#1a7f37,stroke-width:2px style Store stroke:#1a7f37,stroke-width:2px