Preventing Browser Conflicts Between Parallel AI Agents

Fazm Team··3 min read

Preventing Browser Conflicts Between Parallel AI Agents

Run two AI agents that both use browser automation and you will immediately hit conflicts. Agent A navigates to a settings page while Agent B is filling out a form. Both try to control the same browser instance. One of them loses, and the resulting state is corrupted for both.

This is not a theoretical problem. It is the first thing that breaks when you scale from one agent to two.

Separate Browser Profiles

The simplest fix is giving each agent its own browser profile. In Playwright, this means separate user-data-dir paths. Each profile has its own cookies, sessions, and state. Agent A's login does not interfere with Agent B's.

Create profiles at predictable paths like /tmp/agent-1-profile/, /tmp/agent-2-profile/. Clean them up on agent restart if you do not need persistent sessions.

Port Management

Each browser automation instance needs its own debugging port. If two agents try to launch Chrome on the same remote debugging port, the second one either fails or connects to the first agent's browser - both bad outcomes.

Assign port ranges per agent. Agent 1 gets ports 9222-9229, Agent 2 gets 9230-9239. Track allocated ports in a shared registry file with file-level locking.

File Locks for Shared Resources

When agents need to access the same resource - a shared config file, a download directory, a credential store - use file locks. A simple .lock file with the PID of the owning process prevents concurrent access.

The pattern is straightforward:

  1. Check if lock file exists
  2. If it does, wait and retry (with a timeout)
  3. If it does not, create it with your PID
  4. Do your work
  5. Remove the lock file

Always set a timeout on lock acquisition. A crashed agent that never releases its lock should not block everyone else forever.

Session Isolation

The hardest conflicts come from shared authentication state. If Agent A logs out of a service to switch accounts, Agent B's session breaks. Keep each agent's auth sessions completely separate - different browser profiles, different cookie stores, different credential files.

Parallel agents need walls between them. Build those walls before you hit the bugs.

Fazm is an open source macOS AI agent. Open source on GitHub.

More on This Topic

Related Posts