Race after `close`: immediate relaunch with a different launch config (`--headed`) fails ~50% with "Failed to connect: No such file or directory (os error 2)"
Summary
close returns while the session daemon is still alive (its <session>.sock / <session>.pid stay in ~/.agent-browser for ~1 s). If the very next command needs a different launch config — e.g. --headed after a headless run — it fails about half the time with:
✗ Could not configure browser: Failed to connect: No such file or directory (os error 2)An immediate relaunch with the same config (headless → headless) never fails, so this looks like a race between the old daemon's shutdown and the CLI's "restart daemon for incompatible launch" path connecting to a socket that has just been unlinked.
Reproduction
agent-browser 0.37.1, macOS 15 arm64 (Homebrew), Chrome for Testing 153.0.8010.36 installed via agent-browser install. No profile, no plugins.
for i in 1 2 3 4 5 6; do
agent-browser --session race open about:blank >/dev/null
agent-browser --session race close >/dev/null
agent-browser --session race --headed open about:blank 2>&1 | head -1
agent-browser --session race close >/dev/null
doneObserved (6 runs): 3 × ✗ Could not configure browser: Failed to connect: No such file or directory (os error 2), 3 × ✓. Same ratio with --profile <dir>.
Control — same loop without --headed on the third command: 6/6 ✓.
State right after close returns:
agent-browser --session race open about:blank; agent-browser --session race close
ls ~/.agent-browser | grep '^race\.' # race.pid race.sock still present
ps -p "$(cat ~/.agent-browser/race.pid)" # daemon still alive
sleep 1; ls ~/.agent-browser | grep '^race\.' # goneExpected
Either close blocks until the daemon has actually exited and removed its socket, or the relaunch path treats ENOENT on the stale socket as "daemon gone" and proceeds to spawn a fresh one.
Workaround
sleep 1 (or a single retry) between close and the mode-switching command.
Source: vercel-labs/agent-browser