Problem
agent-browser open (bare, no URL) with --profile/AGENT_BROWSER_PROFILE configured launches the profile browser and then immediately relaunches without the profile into a throwaway --user-data-dir=/tmp/agent-browser-chrome-<uuid> — losing all login state. Tracked in #1977.
Repro (AGENT_BROWSER_PROFILE=~/x --headed):
$ agent-browser open
[agent-browser] relaunched browser
✓ Doneps during the run shows two Chrome spawns ~0.5 s apart: first with --user-data-dir=<profile>, then with --user-data-dir=/tmp/agent-browser-chrome-<uuid>. Every bare open relaunches, even against a healthy browser.
Root cause
open with no URL parses to {"action":"launch","headless":...} (commands.rs) — a bare launch envelope carrying none of the launch options. With launch config flags set (profile, executable path, etc.), the CLI sends two envelopes in one invocation:
- The config launch envelope (has
profile,executablePath, …) → daemon launches the browser on the profile. - The bare
openenvelope (no options) → daemon'shandle_launch_innerbuilds launch options from only the command fields, computes a differentlaunch_hash, seeshash_changedagainst the healthy browser, closes it, and relaunches profile-less.
Fix
Two small changes:
- CLI (
main.rs): when this invocation already sent a config launch envelope, skip the redundant bare launch envelope — the config envelope already launched the browser on about:blank, which is exactly what bareopenwants. Encapsulated inbare_launch_follows_config_launch()with a unit test. - Daemon (
actions.rs): fall back toAGENT_BROWSER_PROFILEwhen the launch envelope has noprofilefield, mirroring the existingexecutablePathenv fallback. This covers other stripped-envelope senders (plugins, MCP) the same way.
Testing
- New unit test
bare_open_after_config_launch_is_suppressed(envelope suppression for: bare open with config,open <url>navigate path, bare open without config). - Manual verification with
--headed+ profile (instrumented launcher argv capture):- bare
open→ single launch,--user-data-dir=<profile>✓ (was: profile launch + temp-dir relaunch) - repeat bare
open→ no relaunch, browser reused ✓ open <url>→ unaffected, navigates on the profile browser ✓- no env/flags at all → headless temp-dir fallback still works ✓
--jsonmode output preserved ✓
- bare
Fixes #1977
@fahimscirex is attempting to deploy a commit to the Vercel Labs Team on Vercel.
A member of the Team first needs to authorize it.