Repository navigation
feat(browser): browser/v1 contexts, leased beside the default one (M8.15) - #642
Draft
earakely-scale wants to merge 3 commits into
Draft
earakely-scale wants to merge 3 commits into
earakely-scale wants to merge 3 commits into
Conversation
A website browser now leases browser contexts by a label: each has its own cookies, local storage, tabs and a downloads folder in ~/Contexts/<label>/Downloads. contexts/lease is idempotent, contexts/grant records the agents a lease is for (not enforced yet), contexts/release ends it and contexts/list lists them. The tabs, cookies, local_storage and downloads ops take a context, else act on the default context as before. A context an agent makes over its CDP address is leased to it as agent-<user>-<n>; only that agent may dispose it, and a lease's downloads stay pinned to its folder. A reset or relaunch of the browser ends every lease. data/get carries each lease under contexts, with its downloads, and data/add leases any it names that are missing, so a snapshot round-trips. Task steps: browser_lease_context and browser_release_context, and a context on the cookie, local storage, tab and sign-in steps. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…nd clear leftover folders before each launch Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…2-m815-browserv1-contexts-leases-grants # Conflicts: # packages/agentenv-protocol/src/agentenv_protocol/website_browser/environment.py # src/agent_env/task/episode/rules.py
This branch has not been deployed
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.
What and why
M8.15 (FD-4962): a website browser leases browser contexts beside its default one.
Until now a website browser had one set of cookies, local storage, tabs and downloads, so a task couldn't sign two users in at once, and contexts an agent made over CDP were invisible to agentenv. Now a task leases a context by a label, and each lease has its own cookies, local storage, tabs and downloads folder in the same Chromium.
Design note: M8.15: browser/v1 contexts, decisions 1a, 2a, 3a, 4b and 5a.
What changes
contexts/lease {label}returns{context, id}. Leasing the same label again returns the same lease, so a retried step is harmless.contexts/grant {context, user}records an agent a lease is for. Nothing enforces grants yet; M8.16 will (decision 1a).contexts/release {context}closes the lease's tabs, disposes the context and deletes its folder. Releasing a label that isn't leased does nothing.contexts/listlists every lease with who made it and its grants.-, at most 40 characters. A task's label can't start withagent-(decision 2a).contexton the existing ops:tabs/*,cookies/*,local_storage/*,downloads/listanddownloads/gettake an optionalcontext, a lease's label. Without one they act on the default context exactly as before, error messages included.~/Contexts/<label>/Downloads/, and~/Downloadsstays the default context's (decision 4b). Uploads stay shared. Each download and tab inrecordnames its context.agent-<user>-<n>and granted to it. One made where the relay didn't see is listed asagent-unknown-<n>, granted to nobody.setDownloadBehaviorfor a lease is pinned to that lease's folder.data/getgainscontexts: each lease's cookies, local storage, tabs, downloads, grants and who made it. Each lease's finished downloads are among the files.data/addleases any context it names that isn't leased, then loads its cookies, local storage and tabs. A snapshot therefore round-trips (decision 5a). Files underContexts/<label>/Downloads/load into that lease.browser_lease_context {label, grants?}andbrowser_release_context {label}are new.context.to_dictonly gainscontextwhen it's set, so tasks saved before this don't get new versions.Decided while building, for your review
disposeOnDetach: an agent context made with it (Playwright's default) ends its lease when that agent's connection closes, as Chromium disposes it.~/Contextsis cleared before each launch, since a killed app server can't clean up after itself.data/gettop level:closed_tabsstays the browser's whole history, each tab naming its context.cookies,local_storage,tabsanddownloadsare the default context's.target_unavailable. The note saidnot_found; this uses the computer error that already exists.label, and the other steps name a lease ascontext.How it was tested
test_browser_contexts.py, new, 24 tests:disposeOnDetachcontext ends on disconnect.contexton cookies and tabs, a browser that leases none, config problems, round trips, and sign-in into a lease.tst/unit/task_step+tst/unit/task, 4,523 passed.browser_computer_test.py:agent-ada-1; bob can't dispose it, and ada can't dispose the task's lease but can dispose her own.data/getcarries the leases and their downloads, and a load leases a released one back with its cookies and tabs.🤖 Generated with Claude Code