Gate (2c, efficiency): the 0.5 s check while browser_exec runs stopped only once this process
owned the daemon. On Windows, in a managed worker, or for a daemon another Hermes started it can
never be owned, so it ran every tick for the whole call (up to ~600 short threads in a 300 s call;
for another Hermes's daemon each tick also read its cmdline, uids, sid and environ).
_own_harness_daemon now answers True (owned), False (never ours) or None (nothing to own yet), and
the check stops on anything but None. The managed-worker comment now gives the real reason: a
killed worker must not take the next turn's browser along; its clean exit still runs main's atexit
browser cleanup.
Tests: for another Hermes's daemon and in a managed worker the check answers stop; both fail with
the old owned-only stop rule.
main deleted agent-browser and the browser_tool_* modules and replaced them with a Python Chromium
launcher (tools/browser_launcher.py) and a browser_session layer. On this base:
- The agent-browser family (daemon + Chromium ownership) and the old lightpanda / real-profile
ownership have nothing left to apply to; their tests are dropped.
- main's atexit handler (browser_session_lifecycle.emergency_cleanup_all_sessions) now always runs
cleanup_all_browsers, which stops every harness daemon this process drove. The owned-only exit
step (stop_owned_harness_daemons) had no caller left and is removed; a harness daemon this
process started is still owned and dies with it on an ungraceful exit.
- The launcher's Chromium and lightpanda serve start detached by design: a shared-profile Chromium
outlives its launcher for its other holders, and a crashed owner's throwaway Chromium or
lightpanda server is reaped from its launch record by the next Hermes. Both spawns are marked
with that reason; owning the throwaway ones is a follow-up.
- The long-first-call test drives main's browser_exec routing (_route_exec_current).
Review (W4): on main, the atexit handler reached harness daemons only through
cleanup_all_browsers when _active_sessions was non-empty, so a browser_exec-only process never
stopped them on Windows. This branch's exit step fell back to stop_harness_daemons() off POSIX,
so every Windows exit --reloaded every daemon it had driven: a shared "default" daemon another
live Hermes was using (the cross-owner stop this branch fixes on POSIX) plus up to 15 s of exit
latency per daemon. Windows records no ownership, so the owned-only exit step now does nothing
there, as main did.
Test: with os.name "nt" and a driven daemon, the exit step reloads nothing; fails with the fallback.
Review (W3): agent/managed_worker.py documents that a worker keeps its background processes,
sandbox and browser between turns, and _owns_job exempts managed-worker jobs for that reason.
The browser daemons had no such exemption: a Browser Use harness daemon or an agent-browser
daemon (and its Chromium) started by one turn's worker was owned by it, so the supervisor killed
it when that worker exited and the next turn got a fresh browser (a Browser Use cloud browser lost
its state). _own_harness_daemon and _own_local_daemon now return early in a worker process
(agent.runtime_session_store.is_worker_process), mirroring _owns_job.
Tests: in a worker process neither family registers its daemon; both fail without the check.
Review (2c efficiency, nit 8): the 0.5 s check that owns a long first command's daemon kept
running for the whole command, and for an already-owned agent-browser daemon each tick rescans the
process table for children (psutil children(): 7-15 ms on a busy host). Both periodic checks now
return False once their daemon is owned, which stops them (agent.periodic_scheduler); the call
after the command still rescans for a relaunched Chromium. A pid file naming a process that fails
the identity check logged WARNING "Refusing to reap browser daemon" on every tick; that path now
logs at DEBUG (the reap paths keep WARNING).
The agent-browser half lives in browser_tool_lifecycle (_owning_local_daemon_meanwhile, next to
_own_local_daemon), which also keeps browser_tool_session.py under the 1k-line shape gate.
Test: once owned, the in-command check runs once and stops; fails when the check never returns False.
Review of 7b22760a16: registering_meanwhile started a fresh "while not done.wait()" thread per
browser command, the exact loop agent.periodic_scheduler exists to replace (one process-wide timer
thread; a body runs on a short-lived worker only when due, raises are logged and rescheduled, a
handle never overlaps itself, cancel(wait=) lets an in-flight run finish, and the body keeps the
caller's context). browser_exec and the local agent-browser command now schedule their existing
ownership check on it and cancel it (wait=5) before their own post-command check; the helper and
its unit test are gone, and hermes_cli no longer gains a thread it had to mark exempt.
Tests: the two long-first-command tests still fail when the scheduled check is a no-op.
Greptile on d1d8bc2e19: browser_exec handed the harness daemon to the owner-death supervisor only
after the CLI call returned, and agent-browser did the same for its daemon and Chromium. The first
call starts them and can run for minutes (navigation, user code); a Hermes killed during it left
them running, as on main. Both waits now run inside registering_meanwhile(), which calls the same
ownership check (_own_harness_daemon / _own_local_daemon) every 0.5 s on a helper thread while the
command runs and stops (joined) before the caller's own post-call check. A command shorter than
0.5 s never triggers it; the check is the existing one, so a daemon another Hermes started is still
never registered. _owns_local_daemon names the local-session predicate both agent-browser call sites
now share.
Tests: a browser_exec and an agent-browser command that block until their daemon was owned (both
fail when the wrapper is removed); registering_meanwhile stops with its block and swallows a failing
registration.
Greptile on d1d8bc2e19: stop_owned_harness_daemons trusted the cached ownership entry and stopped the
daemon by name (--reload). If our daemon had exited and another live Hermes had since started its
replacement under the same name, _own_harness_daemon never saw it (no command ran here after), so
exiting this Hermes stopped the other Hermes's browser. The exit path now reads the name's published
pid (one resolver, _published_daemon_pid, shared with _own_harness_daemon) and reloads only names
that still publish the pid we own; for the rest it forgets the entry and releases our old group once
empty. The exit test now uses a real per-test runtime dir instead of resolving under $HOME.
Test: with the name republished by another pid, exit reloads nothing and releases ours; the control
half (still our pid) reloads it. Fails when the published-pid check is removed.
Round-2 review of the exit-path fold:
- Windows records no ownership (_own_harness_daemon is POSIX-only), so the owned-only exit stop
would have stopped nothing there. stop_owned_harness_daemons stops every driven daemon on
Windows, as the exit path did before.
- _own_local_daemon keeps its one-syscall group-leader check for an already-owned pid, so a stale
pid file whose pid was recycled is never treated as the owned daemon.
- The ddgs marker now says the worker runs until its search returns, which is unbounded if primp hangs.
- test_mcp_stdio_init_timeout still patched tools.mcp_tool._get_mcp_stderr_log (dropped in the
previous commit); the replaced-daemon test uses a reaped child's pid instead of a fixed 4242; the
two browser kill -9 tests treat macOS's EPERM for a zombie-only group as gone.
cleanup_all_browsers keeps stopping every driven daemon: /browser connect|disconnect call it so the
next call runs on the new endpoint, and a daemon latches its endpoint when it starts
(TestBackendSwapRetargetsDaemons). Its reload of a daemon another Hermes started on the same name
is main's behaviour, unchanged here.
_own_local_daemon (after every local agent-browser command) and _own_harness_daemon (after every
browser_exec) ran the full identity chain (getpgid, psutil cmdline/uids, the spawn-tag environ read)
before looking at what they already owned, so the docstring's "already-registered groups cost one
set lookup" was false. Both now check the owned pid first: a known daemon skips the identity and tag
checks; agent-browser still rescans the daemon's children so a relaunched Chromium is picked up.
Also:
- A session whose daemon exited (pid file gone, idle timeout) drops its entry, so a long-lived
gateway with per-task session names no longer keeps one entry per session forever.
- A harness daemon that replaced an owned one releases the old group (once empty) instead of
leaving the stale number registered until a later prune.
- The harness pid-file path moves to browser_harness_dirs.harness_pid_file, sharing _harness_home
with namespace_harness_dirs; the copy in browser_use_cli had drifted (Path.home() of this
process where the harness resolves the child env's HOME).
Tests: an owned daemon is not re-verified (both families), an exited agent-browser daemon is
forgotten, a replacement harness daemon releases the old group; both new tests fail on the prior head.
The atexit handler called stop_harness_daemons(), which sends --reload to every daemon this process
drove. browser_exec records a daemon it merely reused too, so a clean exit restarted the shared
daemon another live Hermes started on the same name, the case _own_harness_daemon already refuses
to own. The exit path now stops only the daemons in _owned_daemon_groups (stop_owned_harness_daemons).
cleanup_all_browsers keeps main's stop-everything-driven behaviour for a backend swap.
Test: the atexit handler with one owned and one foreign driven daemon reloads only the owned one; it
fails when the handler calls stop_harness_daemons() again.
Two same-user Hermes processes can reach one daemon. Both read bu-default.pid on the default
Browser Use name, and every Hermes shares the real-profile attach session. The identity checks (uid,
module, session leader, socket-dir binding) prove what the daemon is, not who started it, so both
Hermes registered its group. Killing either one then killed the browser the other was still using.
The real-profile attach's before/after pid-file diff had the same hole: two concurrent attaches
both see the file change.
Each agent-browser and browser-harness command now carries this process's spawn tag (spawn_env:
pid plus create time). The daemon it forks inherits the tag, and _own_local_daemon /
_own_harness_daemon register a daemon only when its tag names this process
(process_identity.spawned_by_this_process; an unreadable environment fails closed). The pid-file
diff is gone. Probed on macOS against agent-browser 0.26.0: the forked daemon carries the tag.
New tests start a verified daemon tagged with another live process. Each fails with its check
removed (the daemon gets registered) and passes with it.
Reported by Greptile on #137057 (two threads).
Same class as the router fix: nine stop paths released their group from the owner-death supervisor
as soon as the leader exited, but members that ignore TERM or outlive the leader keep the group
alive. Releasing it let those members survive a later kill -9 of this process.
Lightpanda, real-profile Chrome, embedded cua-driver, the TTS command provider, dashboard WhatsApp
pairing, the raft and WhatsApp bridges, verify's app server, agent-browser session groups, and
Browser Use harness daemons stopped by --reload now go through release_process_group_once_empty.
New test stops a raft bridge whose TERM-ignoring helper survives. It fails when raft releases
unconditionally, and the group stays covered with the fix. Test seams moved from the per-module
release_process_groups name to the shared helper.
Reported by Greptile on #137057 (thread on the router).
A child started in its own session or group (start_new_session, os.setsid /
setpgid / setpgrp, windows_detach_popen_kwargs) does not die with a SIGKILLed
Hermes: it reparents to init and runs forever. That is how every family this PR
migrates leaked. With the families on spawn_owned, this keeps the class closed.
scripts/check_detached_spawns.py (AST) flags those shapes in the production trees
unless the line, or the line above it, says `detached-spawn: ok — <why>`. It runs
in scripts/check ("detached-spawns") and as a blocking lint.yml step. The baseline
is empty: every remaining site is on spawn_owned / own_process_groups, or carries
its reason. The reasons this commit adds are the census verdicts:
- must outlive the starter on purpose: restart watchers, /update and the updater
hand-offs, dashboard/desktop/service launches, cron and kanban workers
(restart-safe), the update-custody watchdog itself;
- awaited with a group kill on timeout: cron scripts, rg search, the Browser Use
CLI, update completion (holds the checkout lock fd);
- covered by its own parent guard: the compute host (compute_host._parent_guard_loop
flushes sessions; a supervisor KILL could cut that short);
- not a spawn: the wake-word `start_new_session` config key and event field.
tests/scripts/test_check_detached_spawns.py: each shape flagged, non-detached and
commented/string shapes not, the marker opts out on its line or the line above
and nowhere else, tests and the helper are out of scope, main() fails on a new
unmarked spawn, and the repository scan is empty. Teeth: appending an unmarked
start_new_session Popen to tools/file_operations_search.py turns
`scripts/check --only detached-spawns` red (rc 1); restoring it turns it green.
Names the owned-child API in process_identity layer 4:
- spawn_owned(argv, purpose=..., **popen_kwargs): starts the child as a session/group leader,
hands the group to the owner-death supervisor and records it in the spawn ledger.
- own_process_groups(pgids) / release_process_groups(pgids): for groups something else spawned
(MCP SDK servers, agent-browser's Chromium, harness daemons) and for children the owner stopped
itself.
The stringly update_supervised_pgids("register"/"unregister", ...) becomes the private protocol
writer. llama-server's spawn_server(owned=True) now goes through spawn_owned instead of
re-spelling it. Adds a contract test for spawn_owned (group leader, supervisor registration,
ledger entry, release); it goes red when the registration is removed.
browser_harness detaches its daemon on purpose (start_new_session) so a session persists across
browser_exec calls, and the daemon has no idle exit. A SIGKILLed or OOM-killed Hermes therefore
left every daemon it drove running forever, each holding a CDP connection (#121095). A clean exit
leaked them too: stop_harness_daemons() only ran from cleanup_all_browsers(), which the atexit
handler calls only when an agent-browser session was tracked, and a browser_exec-only process
never tracks one (measured: 4 of 4 daemons leaked after the owners exited normally).
After each browser_exec, the daemon behind its BU_NAME is handed to the per-process owner-death
supervisor. The harness publishes the daemon pid in its runtime dir; it is accepted only while it
is this user's live `python -m browser_harness.daemon` leading its own session, so a stale or
planted pid file can never put a stranger's group in front of the supervisor. stop_harness_daemons()
releases the groups it stopped, and the atexit handler now calls it unconditionally.
Replaces the per-family reaper of #120739 (trevornk, owner-pid claim files + a janitor sweep of
dead-owner daemons, +1150 lines): the owner dying is detected by the shared supervisor at the
moment it happens, not by the next Hermes that happens to start the browser janitor, and the live
control daemon of another Hermes is never in this process's registry at all. The claim-file idea
(trevornk) and the per-owner-dir idea (#129655, mheals / Diaspar4u) are what this keys on: the
daemon's own pid file under the runtime dir the CLI ran with.
Outside a served profile, browser-harness binds
<home>/.config/browser-harness/runtime/bu-<BU_NAME>.sock. A deep HOME (a
container's profile home $HERMES_HOME/home, a long account home) or a long
session name pushed that past sun_path and every browser_exec died with
"browser-harness: fatal: AF_UNIX path too long". Only served profiles had a
short-dir fallback.
browser_exec now judges the default socket on the call's final BU_NAME and,
when it would overflow, points BH_RUNTIME_DIR at a private 0700 hbh-<hash>
dir (keyed by uid and harness home): the user's runtime dir
($XDG_RUNTIME_DIR, else /run/user/<uid>) first, the short socket temp root
only where none exists (containers, macOS). A socket that already binds keeps
its path and its live daemon; an exported BH_RUNTIME_DIR/BH_TMP_DIR is kept.
The direct-API Browser Use route stamped "cloud" from configuration before the harness chose its
browser. With BU_AUTOSPAWN the harness attaches to a local Chrome that is already listening, and
capture_screenshot()/new_tab() then switched the user's visible tab. That route now asks the live
harness daemon (daemon_browser_kind() == "cloud", set only by a BU_BROWSER_ID cloud browser) at each
call; a provider session whose CDP endpoint Hermes resolved keeps activating, every local, connected
or autospawn-fell-back-to-local browser never does.
capture_screenshot() activated a hidden agent tab on every backend, so on
/browser connect, the real-profile browser or a local headed Chrome each
screenshot switched the user's visible tab. Activation now follows the same
cloud flag new_tab uses; the 10 s png deadline and jpeg fallback stay on every
backend. new_tab's activation on cloud no longer raises after the tab exists
when a provider rejects Target.activateTarget.
Chrome draws no compositor frame for a hidden tab, and Browser Use cloud
never answers a png Page.captureScreenshot for one, while the harness
creates its tabs in the background. browser_exec now launches the harness
through a thin launcher that rebinds capture_screenshot() (bring a hidden
tab to the front, png with a 10s deadline, then one jpeg fallback saved
as png) and, on cloud-provider browsers, new_tab() (activate the tab).
The model code still arrives untouched on stdin.
Found on Hermes Cloud staging.
Greptile finding "Browser recommends a missing tool": the non-native
browser_exec header picked its vision_analyze pointer from
check_vision_requirements(), which reports whether a vision route exists,
not whether this session exposes the tool, so a session with `vision`
disabled was told to call a tool it does not have (tools/AGENTS.md:
cross-toolset references are added in get_tool_definitions()).
The header now states only the transport fact ("Screenshots are not
attached to this tool's results. Work text-first: ..."), still never
calling the model blind, and model_tools' browser_exec rewriter appends the
vision_analyze pointer when "vision_analyze" is in the session's available
set. The native header (screenshots ride back in the result) never gets it.
Prompt-surface fixtures re-rendered: the stock render has vision_analyze,
so browser_exec gains the pointer (+8 tokens per surface).
The non-native header told every model whose screenshots don't ride back in tool results
"Your model cannot view images ... skip the screenshot-driven workflow described below".
The gate (_should_use_native_vision_fast_path) is a routing fact: decide_image_input_mode is
"text" when auxiliary.vision is pinned explicitly (by design, #16506) or the catalog cannot
attest the model. A vision-capable main model read the line against itself, and no
screenshot section follows the header.
Three honest variants now: attached natively (unchanged), "not attached to this tool's
results; pass the capture_screenshot() path to vision_analyze" when the vision_analyze gate
(check_vision_requirements) has a route, and "no vision route is configured" otherwise.
Lightpanda keeps its own text-first line without the misleading prefix.
The browser_exec description picks its text-first header from
_should_use_native_vision_fast_path(), which measures whether screenshots can
ride back inside TOOL RESULTS for the active provider/model. The header then
asserted a model-level fact ("Your model cannot view images") that was never
tested, and a vision-capable model on such a provider (deepseek-flash in the
report; nous/claude on this host) quoted it against itself and skipped an
image the user had attached to the conversation.
Reword the header to state only what was determined: screenshots will not
reach the model through this tool's results, work text-first, and this says
nothing about user-attached images. Same guidance, no capability claim.
Reported and diagnosed by @dcdc4747 in #131568.
The deferred tool_search catalog shows each tool's first sentence clipped to
60 chars, so lines like 'image_generate: Generate high-quality images from
text prompts, or edit /…' hid that it edits with reference images on the
user's configured model. An agent skipped it and called FAL directly with a
hardcoded model.
- catalog line cap 60 -> 80 (CATALOG_SUMMARY_MAX_CHARS); every built-in
tool's first sentence now fits and leads with what it does
- image_generate/video_generate say they use the configured model;
image_generate says to use it rather than direct API calls/scripts
- web_search/web_extract/browser_exec name when to use each other
- drop a duplicated cronjob sentence and filler in skill_view/video_generate
- regenerate tests/fixtures/prompt_surface
A local browser_exec call (hybrid ::local sidecar, cloud fallback, real profile) was labelled by re-reading
browser.engine after the call. A session created before the engine changed (a routed profile re-reads config
every call), or the real-profile Chromium, could therefore be counted as Lightpanda, and a Lightpanda session
as Chromium.
The route now carries the engine of the session it actually ran on ("local" or "lightpanda"; the real profile
is always Chromium) into the metrics label instead of reconstructing it from configuration.
browser.user_data_dir, chromium_args, cloud_provider and every other browser.* knob were read with
read_raw_config, which skips the managed overlay and ${VAR} expansion: a managed profile pin or
flag set was ignored, and ${HOME}/chrome-profile became a literal dir under HERMES_HOME. The session
layer's one reader (browser_session_cloud.browser_section) now uses load_user_config_effective, and
the other raw browser.* reads go through it or the same loader: browser_exec's cloud routing
(browser_use_cli._read_browser_cfg), the real-profile pin (browser_connect._browser_setting) and
/browser status's cdp_url (methods_browser, now browser_session_cdp.get_cdp_override_raw). Tests
that stubbed read_raw_config for browser.* now stub the effective loader.
The handler named the configured cloud provider for every call, so hybrid ::local sidecar, cloud
fallback and real-profile calls counted against browserbase. The test now drives the real
_handle_browser_exec instead of rebuilding the wiring.
- locales: drop the /browser use, Browser Use mode and agent-browser status keys whose callers are gone;
reword status/usage/description lines and tips t180-t182 (contiguous tip keys kept) in every locale.
- browser_launcher: a bare command name in browser.executable_path resolves through hermes_platform's
locate_command (no shutil.which); the LANE fallback for chromium_missing_hint is gone.
- browser_cdp: drop the Camofox sentences from its description and error.
- shared metrics: record_browser_call loses the extension-controller wrapper (no browser_* tool routes
through it any more) and browser_exec's registry handler calls it, so the browser execution-backend
series keeps reporting for the only browser path.
- test_profiles: the clone/live-browser test uses browser_launcher.running_instance.
Live probe: browser-harness tracks native dialogs in its own daemon
(Page.javascriptDialogOpening on its own target session) and the task's CDP
supervisor never captured one on harness-driven pages, so the field had no
working source. browser_dialog's text now describes what it actually does:
answer a supervisor-held dialog, its error listing candidate ids.
browser_exec is the only core browser tool (plus browser_cdp, browser_dialog,
browser_vault, all CDP). Deleted: browser_navigate/snapshot/click/type/
scroll/back/press/get_images/vision/console and every module that served
them (browser_tool_session/_lifecycle/_cloud/_cdp/_real_profile/
_lightpanda_fallback/_eval_policy/_origin/_snapshot/_vision) plus
browser_camofox*.py (Camofox ships as the catalog plugin 'camofox').
tools/browser_tool.py and tools/browser_tool_install.py shrink to the
frozen old-updater stub warm_agent_browser_npx_cache.
toolsets: _HERMES_CORE_TOOLS / browser toolset list only the CDP tools.
model_tools: browser_tools legacy alias and the browser_navigate /
browser_type schema rewriters removed. Cloud providers no longer request an
install post_setup hook (nothing to install).
- browser_vault: supervisor-only (no agent-browser eval fallback); attaches
on demand to the task's session cdp_url; check_fn = browser_exec available
or a CDP override.
- browser_cdp: endpoint + SSRF guards from browser_session_cdp /
browser_url_policy; the private-page probe reads the target's URL over the
same CDP endpoint; gate = browser-harness importable + CDP override.
- browser_dialog: pending dialogs now arrive in browser_exec results
(pending_dialogs) instead of the deleted browser_snapshot.
- browser_extension_router serves browser_cdp only.
browser_exec no longer shells out to agent-browser: local browsers (real
profile, Lightpanda, packaged Chromium) come from
browser_session.get_session_info, whose sessions always carry cdp_url, and
the cloud fallback_from_cloud path reuses the same local session.
check_fn is browser_exec_available() (browser-harness importable).
Removed is_browser_use_cli_mode, default_downgrade_notice,
set_browser_use_mode, get_browser_backend and BACKEND_DISABLED; the
harness env gets only BROWSER_USE_API_KEY from the profile secret scope.
Three review points on the served-profile harness dirs:
- The length check measured BH_RUNTIME_DIR as supplied, but the harness
binds `Path(BH_RUNTIME_DIR).expanduser().resolve()`
(browser_harness/_ipc.py:23). A short relative (`BH_RUNTIME_DIR=rt`
from a deep cwd) or symlinked spelling skipped the short-dir fallback
while the real socket exceeded sun_path. The candidate is now expanded
and resolved before measuring, on Linux and macOS alike; a dir that
fits is still returned exactly as given.
- The dir selection, socket budget and private-dir claim move from
tools/browser_use_cli.py (which had grown past 1,000 lines) to a new
tools/browser_harness_dirs.py, together with the daemon identity
(HARNESS_DIR_KEYS, daemon_identity, daemon_env).
_base_subprocess_env applies namespace_harness_dirs; browser_use_cli.py
is back to 1,000 lines.
- The budget is a pure function of the platform
(`socket_dir_budget(platform)`, `fits_socket_budget(dir, budget)`), so
the macOS length rule is tested with macOS data and no longer patches
sys.platform. The real-platform bind tests stay marked
platforms("macos") / platforms("linux").
Red on the previous head: the relative and symlink cases of the new
Linux test (resolved socket 249/246 bytes > 107).
Refs #134889 (GW-23)
On Linux a served profile's harness runtime dir ~/.config/browser-harness/runtime/p-<12hex> left
room for only 38-character session names at /home/teknium (30 at /home/alexander.smith) under the
108-byte sun_path, while BU_NAME may be 64; the daemon could not bind for longer names.
_socket_fit_runtime_dir now applies the macOS short private dir claim on Linux too, with Linux's
budget (107 - len("/bu-.sock") - 64 = 34 bytes): hbh-<12hex> under socket_safe_tmpdir(), else under
the sticky system temp root, claimed only through _claim_private_dir (mkdir 0700, or an existing
real dir owned by this uid with no group/other bits). A dir that already fits is kept unchanged, and
an unclaimable one keeps the long path. Windows (loopback TCP) is unchanged.
Refs #134889 (GW-23)
browser_exec resolves the live endpoint into BU_CDP_URL in _route_exec, and records its harness
daemon only inside dispatch(). A /browser connect landing between the two reaped nothing, the CLI
spawned the daemon on the old endpoint, and the daemon (which latches BU_CDP_* at spawn) kept
driving the old browser for every later call in that profile.
browser_exec now snapshots the profile's live CDP generation before routing and re-routes (at most
3 attempts) when it moved during routing; after dispatch, a moved generation reloads this call's
daemon through the existing --reload path so the next call respawns on the current endpoint.
Refs #134889 (GW-23)
The harness writes shot.png, debug-click overlays and bu-<NAME>.log under
BH_TMP_DIR (browser_harness/paths.py tmp_dir, else <home>/tmp). A served
profile already had its own BH_RUNTIME_DIR but still shared that tmp dir, so
one profile's screenshots and daemon logs sat beside another's.
_namespace_harness_daemons now also sets BH_TMP_DIR to <tmp root>/p-<hash>
(nested inside an inherited BH_TMP_DIR when one is set) with
BH_TMP_DIR_SHARED=1 so log names keep the bu-<name> stem. The runtime dir
still derives from the inherited value, as before. The driven-daemon identity
now carries the tmp keys too, so an unscoped shutdown --reload reaches the
daemon with its own tmp dir. Single-profile processes are unchanged.
Refs #134889 (GW-23)
Refs #134889 only
A served profile's Browser Use daemons get their own BH_RUNTIME_DIR
(~/.config/browser-harness/runtime/p-<hash>), shared by several BU_NAMEs, so
the installed harness names each socket <dir>/bu-<BU_NAME>.sock
(browser_harness/_ipc.py _runtime_stem/_sock_path). On macOS sun_path is 104
bytes; with a default HOME that path is 63 bytes on a 9-letter account, which
left room for only ~31-character session names although BU_NAME may be 64.
When the per-profile dir is over the 30-byte budget on macOS, the profile now
gets a private dir under the short socket root (/private/tmp/hbh-<12 hex>,
keyed by uid, harness root and profile). An existing dir is accepted only when
it is a real directory owned by this uid with no group/other bits; otherwise
the long path stays. Linux and single-profile processes are unchanged.
Refs #134889 (GW-23)
Refs #134889 only
The harness names a daemon by BU_NAME alone (an unnamed browser_exec is
"default") inside one runtime dir and reuses any live daemon of that name.
On a multiplexed gateway profile B's unnamed exec therefore reused the
daemon A had spawned on A's /browser connect endpoint and drove A's
logged-in browser. The owner map was keyed by BU_NAME and last-writer-wins,
so A's reap stopped nothing after B touched the daemon, or killed the one B
was using.
Under a served-profile scope _base_subprocess_env now points
BH_RUNTIME_DIR at a per-home subdirectory (sha256 of the home key) of the
harness runtime dir, with BH_RUNTIME_DIR_SHARED=1 so names keep their
bu-<name> stems. _driven_daemons is keyed by (runtime dir, shared flag,
BU_NAME), and stop_harness_daemons reloads each daemon in the dir it was
started in. Outside a served-profile scope the env is unchanged.
Test: A and B unnamed execs get different daemons on their own endpoints;
A's reap stops only A's daemon, B keeps its browser and A respawns on its
new endpoint (red on the previous head: B got A's endpoint).
Refs #134889 (CLI-9)
/browser connect wrote the process-wide BROWSER_CDP_URL and reaped every
task's browser, so on a multiplexed gateway one profile's live browser
reached every other profile's sessions.
- tools/browser_tool_cdp: live overrides are a lock-protected map keyed by
hermes_home_key() (set_live_cdp_override / live_cdp_override).
Precedence: this profile's live connect, then the operator's
BROWSER_CDP_URL env, then browser.cdp_url. Camofox yields to it too.
- Browser sessions record the home_key that created them; CDP supervisors
and Browser Use harness daemons remember theirs.
- cleanup_profile_browsers(home_key) closes only that profile's sessions,
supervisors (SUPERVISOR_REGISTRY.stop_home) and harness daemons, and
drops its per-home config cache slots. cleanup_all_browsers is unchanged.
Refs #134889 (CLI-9)
Review findings on the fallback:
- browser_exec(local=true) under a cloud backend fell back to the CLOUD
browser when the profile could not load. It now runs on the local
sidecar browser (which never loads the profile) and the route keeps it.
- Without local, the session layer makes the one real-profile-or-fresh
decision for the browser it actually launches; browser_exec reports that
session's note instead of its own earlier attempt, so the note can never
describe a different browser.
- The note is delivered on the first result that reaches the model: a
failed first navigation or a timed-out exec no longer swallows it.
With browser.use_real_profile on, every browser call failed whenever the
profile could not be snapshotted: Windows with Chrome open (cookie DB
locked), a non-Chromium default, a bad pin, a launch failure. The browser
tool was unusable until the user quit their browser or found the toggle.
Now the session runs on a fresh browser without the user's logins and the
first result carries `real_profile_unavailable` with the reason, so the
model says it is signed out instead of failing or pretending. Built-in
tools keep the fallback for the session's life; browser_exec remembers it
per route so a task never swaps browsers mid-way.
Docs and config comments describe the new behaviour. The touched real-profile
test file also gets explicit encodings (Windows footgun checker).
/simplify-code follow-up. The autospawn check (is_legacy_browser_use_cloud_config)
and the direct-API shortcut read the same profile-scoped key; share one
_browser_use_api_key_set() helper so the two cannot drift. The
_resolve_backend_cdp docstring and comment no longer claim the shortcut covers
keyless "auth login" configs, and the tests drop delenv calls the autouse
_clean_env fixture already makes and pin the packaged-Chromium route.
Folds #136210 and #126260 into one gate. The direct-API shortcut in
_resolve_backend_cdp returns no CDP so the browser-use CLI can autospawn its
own cloud browser, but the CLI only autospawns with BROWSER_USE_API_KEY. Both
keyless shapes that reach the shortcut were broken:
- never-configured install, Nous-entitled: autodetect returns the managed
gateway provider (same "browser-use" name); #136210's new error branch told
these users they had "set via hermes tools" a key they never needed.
- explicit cloud_provider: browser-use with no key: the harness hunted for an
installed Chrome (DevToolsActivePort).
Gating the shortcut on the key sends both through the session path: the
managed provider returns the gateway CDP URL; the keyless direct selection
fails create_session with the provider's own selection error and the session
layer falls back to packaged Chromium, as the built-in browser tools already
do. This replaces #126260's _is_managed_browser_use probe (a private-method
call wrapped in a blind except) and #136210's error branch.
Tests: #136210's test now asserts the local-Chromium fallback instead of the
error; #126260's managed-autodetect test is kept with its provider stub
simplified; its two other tests duplicated the existing direct-key and
provider-failure guards and are dropped.
The direct-API path returns no CDP so the CLI can autospawn, and autospawn
only runs when BROWSER_USE_API_KEY is set. Without the key, return the
selection error instead of handing the harness nothing.
browser_exec's CDP resolver short-circuits for any provider named
"browser-use" that isn't a picker/legacy Nous-gateway config, on the
assumption it is a direct BROWSER_USE_API_KEY config the CLI drives
natively. Autodetect can also hand back a MANAGED browser-use provider
on installs that never configured a cloud browser (the gateway token
needs no API key) — and it reports the same name, so the shortcut fires
for a provider that does have a session path.
The result is BU_CDP_WS/BU_CDP_URL left unset, so the harness falls
back to discovering the user's own profile dirs (~/.config/chromium,
~/.config/google-chrome). On a headless host with neither, every
browser_exec call fails with:
fatal: chrome-not-running: no supported Chromium-family browser is
running -- start Chrome, then retry
Gate the shortcut on the provider actually being direct-API so managed
configs resolve their CDP endpoint like every other provider. Direct-API
behaviour is unchanged, and a provider that fails to yield a session now
names the real error instead of surfacing chrome-not-running.
Regression tests cover the never-configured managed shape, the
direct-API shortcut that must still hold, and the failure path.
The stock prompt surface regrew ~3.4k tokens after the August diet, almost
all from features added straight into the never-deferred core. This takes
back the biggest pieces:
- browser_vault: the five eager browser_vault_* tools (list, fill, unlock,
save_login, enter_code) become one browser_vault tool with an action enum,
deferred behind tool_search by default. It still rides with the browser
(an empty vault keeps save_login reachable), so discovery holds; only a
catalog line is paid per request. Results and errors name the new actions;
the input-tool password note points at it through tool_call.
- terminal: schema re-dieted (1,136 -> 651 Qwen tokens). Description and
param docs no longer repeat each other; heartbeat / persist_on_release keep
their rules in one line each; process(...) references name process_manage.
- tool_search / tool_call: the keyword-query rule lives once, in the queries
param; description and connector hint trimmed.
- system prompt: the "Async handoff" block is removed. Its rule ships in the
delegate_task description and in the background dispatch result the model
reads at the moment it matters, and the polling loop it targeted is guarded
structurally (#124724).
Stock CLI surface (prompt-surface render, chars/4): 18,612 -> 16,524.
Fresh install, Qwen3 tokenizer: 14,962 -> 13,120 (Sep 7 post-diet: 11,595).
Live A/B harness: evals/prefix_rediet/.
When the configured cloud browser provider fails to create a session (seen live:
Browser Use gateway HTTP 429 RATE_LIMIT_EXCEEDED), the session layer already falls
back to local Chromium and marks the session fallback_from_cloud, which keeps the
built-in browser_* tools working. browser_exec read only cdp_url from that session,
found none (local sessions launch lazily), and failed the whole call with "returned
no CDP endpoint, so Browser Use mode cannot drive it".
On a fallback session, resolve the packaged Chromium's CDP endpoint the same way the
no-provider path does, and log the provider failure once.
The salvaged route declined the provider in browser_use_cli, but the
managed-Chromium resolver still asked _get_session_info for the plain
cache key, and with a cloud provider configured that key builds a CLOUD
session — the private-URL call still created a Browser Use cloud browser.
- the sidecar call uses the `::local` cache key, so _get_session_info
builds local Chromium (the same key browser_navigate's sidecar uses);
- it runs under its own harness daemon (BU_NAME `_local_<name>`): the
daemon reads BU_CDP_* once at spawn, so reusing the cloud route's
daemon would relay the private URL to the cloud browser;
- a follow-up call with no URL literal stays on the route the previous
call took, like browser_navigate's _last_session_key.
Review caught that `_hybrid_routes_locally` resolves DNS (`_url_is_private` ->
`socket.getaddrinfo`) and is not memoised, so evaluating it separately for the
pre-flight and again for the backend choice lets a host whose answer changes
between the two lookups split them: the first lookup looks private, which
relaxes the private-address floor, and the second looks public, which clears
`force_local_sidecar` — so the call executes against the CLOUD provider with the
private URL in it. That is the leak this change exists to prevent.
`_code_url_verdict(code)` now makes ONE pass over the URL literals and returns
`_CodeUrlVerdict(blocked, local_sidecar)`; `browser_exec` consumes the returned
verdict instead of re-deriving it, so both decisions rest on the same captured
evidence. This is the discipline `browser_navigate` already applies — it derives
its safety relaxation from the session key (`_is_local_sidecar_key`) rather than
re-running the predicate. `_blocked_url_in_code` is gone rather than kept as a
wrapper: a caller that recomputed the route after it would reintroduce exactly
this bug.
Tests: `test_rebinding_host_cannot_split_verdict_from_route` stubs
`socket.getaddrinfo` to answer private then public, counts predicate evaluations
and asserts both that they are one per URL and that the call never reaches the
cloud provider — RED against the previous commit ("evaluated 2 times"), green
after. `test_public_then_private_answer_is_refused_not_leaked` pins the other
direction, where the safety check sees the private answer and refuses (the
over-block is the safe side). No live DNS in either. 10 existing cases moved to
the renamed helper. Full browser suite: 68 files, 830 passed, 0 failed.
With a cloud browser provider configured (the picker's `nous`, or any
browserbase/browser-use key), `browser.auto_local_for_private_urls` is on by
default and `browser_navigate` routes private/loopback/LAN URLs to a LOCAL
Chromium sidecar so the cloud provider never sees them. `browser_exec`'s
pre-flight URL scan did not consult that decision, so *every* LAN URL was
refused with "Blocked: URL targets a private or internal address" — and in
Browser Use mode (`browser.backend` unset, the default) `browser_exec` is the
only browser tool, so the documented hybrid workflow was unreachable.
Relaxing the pre-flight alone would have been wrong: the exec call resolves ONE
CDP endpoint for the whole code blob (`_resolve_backend_cdp`), so an allowed
private URL would then have been executed against the configured cloud browser
— exactly the leak the guard exists to prevent. Verdict and route now move
together:
* Extract `_hybrid_routes_locally(url)` in browser_tool as the single source of
truth for the predicate; `_navigation_session_key` reads it too, so the
navigate and exec paths cannot drift apart.
* `evaluate_url_safety(url, *, auto_local=False)` forwards the relaxation to
`_url_policy_error` (the cloud-metadata floor stays unconditional).
* `_blocked_url_in_code` passes `auto_local=_hybrid_routes_locally(url)`, the
same verdict the navigation path reaches for itself.
* `browser_exec` computes `local_sidecar` from the URLs in the code and threads
it through `_route_backend` → `_resolve_backend_cdp(force_local_sidecar=...)`,
which declines the cloud provider so the local engine serves the call. One
endpoint per call means a mixed call runs wholly local — the safe direction.
Scope is deliberately narrow: no cloud provider, a CDP override, or Camofox all
leave `_hybrid_routes_locally` False, so those paths are byte-for-byte unchanged.
The two operator overrides (BU_CDP_*/`browser.cdp_url`) still outrank it.
Tests: 9 new cases in tests/tools/test_browser_use_cli.py covering the URL
verdict (LAN, loopback, public, IMDS still blocked, hybrid off, no provider) and
the endpoint the verdict depends on (LAN-only and mixed calls must never reach
the provider; public-only still must). Full browser suite: 663 passed.