google-gemini/gemini-cli · error · Error
Maximum number of parallel browser instances (${BrowserManag
Error message
Maximum number of parallel browser instances (${BrowserManager.MAX_PARALLEL_INSTANCES}) reached. Please wait for an existing browser task to complete before starting a new one. What it means
Thrown by BrowserManager.getInstance in 'isolated' mode after scanning all parallel instance slots (key:suffix) and finding MAX_PARALLEL_INSTANCES (5) already in use. This caps concurrent isolated browser processes.
Source
Thrown at packages/core/src/agents/browser/browserManager.ts:174
// Chrome prevents multiple instances from using the same profile, so
// concurrent usage would cause "profile locked" errors.
if (sessionMode === 'persistent' || sessionMode === 'existing') {
throw new Error(
`Cannot launch a concurrent browser agent in "${sessionMode}" session mode. ` +
`The browser instance is already in use by another task. ` +
`Please run browser tasks sequentially, or switch to "isolated" session mode for concurrent browser usage.`,
);
}
// Isolated mode: allow parallel instances up to the limit.
let inUseCount = 1; // primary is already in-use
let suffix = 1;
let parallelKey = `${key}:${suffix}`;
let parallel = BrowserManager.instances.get(parallelKey);
while (parallel?.inUse) {
inUseCount++;
if (inUseCount >= BrowserManager.MAX_PARALLEL_INSTANCES) {
throw new Error(
`Maximum number of parallel browser instances (${BrowserManager.MAX_PARALLEL_INSTANCES}) reached. ` +
`Please wait for an existing browser task to complete before starting a new one.`,
);
}
suffix++;
parallelKey = `${key}:${suffix}`;
parallel = BrowserManager.instances.get(parallelKey);
}
if (!parallel) {
parallel = new BrowserManager(config);
BrowserManager.instances.set(parallelKey, parallel);
debugLogger.log(
`Created parallel BrowserManager (key: ${parallelKey})`,
);
} else {
debugLogger.log(
`Reusing released parallel BrowserManager (key: ${parallelKey})`,
);View on GitHub (pinned to 5024443c72)
Solutions
- Wait for at least one in-flight browser task to complete before launching another.
- Lower the fan-out / parallelism of browser tasks to stay under 5 concurrent.
- Audit that every browser invocation releases its instance in a finally block; leaked inUse flags exhaust the pool.
- Call BrowserManager.resetAll() if the count is stale due to a prior crash, or restart the process.
Example fix
// problematic: fanning out 8 parallel browser subagents
await Promise.all(tasks.map(t => browserAgent.run(t))); // >5 concurrent
// fix: limit concurrency to <= MAX_PARALLEL_INSTANCES
await pMap(tasks, t => browserAgent.run(t), { concurrency: 4 }); Defensive patterns
Strategy: validation
Validate before calling
import { BrowserManager } from './browserManager.js';
function countInUse() {
let n = 0;
for (const inst of BrowserManager.instances.values()) if (inst.isAcquired()) n++;
return n;
}
// Before launching: assert countInUse() < BrowserManager.MAX_PARALLEL_INSTANCES. Try / catch
try {
const bm = BrowserManager.getInstance(config);
} catch (e) {
if (e instanceof Error && /Maximum number of parallel/.test(e.message)) {
// wait / queue / reduce concurrency
}
throw e;
} Prevention
- Cap concurrent browser tasks below MAX_PARALLEL_INSTANCES (5).
- Ensure every isolated instance is released after use.
- Reset stale instances via BrowserManager.resetAll() if counts look wrong.
When it happens
Trigger: sessionMode === 'isolated' and the primary plus slots :1..:4 all have inUse===true, so inUseCount reaches MAX_PARALLEL_INSTANCES during the while loop.
Common situations: Five or more concurrent browser subagents/tasks fanned out at once; isolated instances not released because of missing finally release(); long-running browser tasks stacking up.
Related errors
- Cannot launch a concurrent browser agent in "${sessionMode}"
- LegacyAgentSession.send() cannot be called while a stream is
- Failed to initialize chrome-devtools MCP client
- Domain not allowed: The requested domain is not in the allow
- Browser agent requires user consent to proceed. Please re-ru
AI-assisted analysis of google-gemini/gemini-cli@5024443c72 (2026-08-12).
Data as JSON: /api/errors/12a2f1eabe78f626.
Report an issue: GitHub.