Skip to content

fix(cli): prevent env-derived flags from triggering implicit re-launch#1395

Open
xiaodankasi wants to merge 1 commit into
vercel-labs:mainfrom
xiaodankasi:fix/implicit-launch-env-relaunch
Open

fix(cli): prevent env-derived flags from triggering implicit re-launch#1395
xiaodankasi wants to merge 1 commit into
vercel-labs:mainfrom
xiaodankasi:fix/implicit-launch-env-relaunch

Conversation

@xiaodankasi
Copy link
Copy Markdown

Problem

When AGENT_BROWSER_EXECUTABLE_PATH (or other launch-related env vars / config values) is set, every CLI invocation that hits the daemon sends an implicit launch command — even when the user only runs a read-only action like get url.

Because this second launch omits flags the original launch included (e.g. --proxy), the computed launch_hash differs from the running browser's hash, causing the daemon to kill and re-launch the browser. The new browser instance starts at about:blank, breaking subsequent commands.

This was introduced in PR #996 (commit 05d86fa, shipped in v0.24.1) which added hash-based relaunch detection.

Root Cause

The launch condition in main.rs checks flags.executable_path.is_some() (among others), which is true whenever the env var AGENT_BROWSER_EXECUTABLE_PATH is set — regardless of whether the user explicitly passed --executable-path on the CLI. This means an env-only configuration silently triggers a launch command on every invocation.

Fix

Guard the implicit launch with has_explicit_launch_flags — a boolean that is true only when the user passes launch-relevant flags directly on the CLI (using the cli_* tracking fields introduced in PR #996 itself). When the daemon is already running and no explicit CLI launch flags are present, the launch command is skipped entirely.

This preserves PR #996's design intent: users can still explicitly change browser options mid-session with --headed, --proxy, etc., triggering a hash-aware relaunch. But env/config-derived values alone will no longer cause unintended relaunches.

Reproduction

# On a machine with AGENT_BROWSER_EXECUTABLE_PATH set:
agent-browser open --proxy http://proxy:port --session test
agent-browser --session test get url   # ← triggers relaunch, returns about:blank

Testing

Verified on Linux (Alibaba Linux, Chrome 140) where AGENT_BROWSER_EXECUTABLE_PATH=/usr/bin/google-chrome-140:

  • open --proxyget url (no explicit flags): browser stays alive, returns correct URL ✓
  • open --proxyget url --proxy (explicit flag): correctly triggers relaunch ✓
  • open --headedget url: no spurious relaunch ✓
  • Fresh start (no daemon): launch proceeds normally ✓

Closes #1299

@vercel
Copy link
Copy Markdown
Contributor

vercel Bot commented May 27, 2026

Someone is attempting to deploy a commit to the Vercel Labs Team on Vercel.

A member of the Team first needs to authorize it.

When the daemon is already running, launch-relevant flags read from
environment variables (e.g. AGENT_BROWSER_EXECUTABLE_PATH) or config
files would cause the CLI to send an implicit launch command on every
invocation. Because these env/config-derived options often differ from
the original launch (e.g. missing --proxy that was only on the first
command), the daemon's hash comparison detects a mismatch and kills the
running browser — resulting in a fresh instance at about:blank.

The fix gates the implicit launch on whether the user explicitly passed
launch-relevant CLI flags (--headed, --proxy, --profile, etc.) using the
existing cli_* tracking fields. This preserves the intentional re-launch
behavior from vercel-labs#996 (explicit option changes trigger a restart) while
preventing env/config values from causing spurious hash mismatches.

Fixes vercel-labs#1299
@xiaodankasi xiaodankasi force-pushed the fix/implicit-launch-env-relaunch branch from 8955b4a to fb63504 Compare May 28, 2026 03:40
@xiaodankasi
Copy link
Copy Markdown
Author

Hi @ctate, could you take a look when you have a moment? This fixes a bug where env-derived flags (e.g. AGENT_BROWSER_EXECUTABLE_PATH) trigger an implicit re-launch on every CLI invocation, causing hash mismatches that kill the running browser. It also closes #1299. Thanks!

Comment thread cli/src/main.rs
// explicitly passed launch-relevant CLI flags (indicating intent to change options).
// Environment-variable or config-file derived values alone must NOT trigger a
// re-launch — doing so causes hash mismatches that kill the running browser (#1299).
let has_explicit_launch_flags = flags.cli_headed
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing cli_color_scheme and cli_engine tracking fields cause --color-scheme and --engine CLI flags to be silently ignored when daemon is already running.

Fix on Vercel

Copy link
Copy Markdown
Author

@xiaodankasi xiaodankasi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re: Vercel bot comment about missing cli_color_scheme and cli_engine

These cli_* tracking fields do not exist in the codebase. flags.rs only defines: cli_headed, cli_executable_path, cli_profile, cli_state, cli_proxy, cli_args, cli_user_agent, cli_allow_file_access, cli_extensions, cli_download_path, and cli_hide_scrollbars.

Adding cli_color_scheme / cli_engine would be a separate enhancement. Also worth noting: color_scheme is not included in launch_hash(), so it does not affect relaunch behavior regardless.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

--headed window dies and Chrome is killed+relaunched on every CLI invocation (macOS 26 / Darwin 25.x)

1 participant