gemini-cli - 💡(How to fix) Fix Browser agent actionCounter not reset between sequential invocations, causing second agent to immediately hit maxActionsPerTask limit [1 pull requests]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…

Error Message

Error: Browser agent reached maximum action limit (100). Task terminated to prevent runaway execution. To config the limit, use maxActionsPerTask in the settings.

Root Cause

BrowserManager is a singleton (getInstance() returns the same instance for the same session mode). The actionCounter is only reset in two places:

  1. During connect() (line 762-763 in browserManager.ts)
  2. Never during release() or acquire()

When the first browser_agent finishes and the second one starts:

  • release() marks inUse = false but does not reset actionCounter
  • acquire() marks inUse = true but does not reset actionCounter
  • ensureConnection() sees the connection is still alive (isConnected() === true) and returns early — no reconnect, no counter reset

So the second agent inherits the exhausted counter (100) from the first agent.

Fix Action

Fixed

Code Example

Error: Browser agent reached maximum action limit (100). Task terminated to prevent runaway execution. To config the limit, use maxActionsPerTask in the settings.

---

acquire(): void {
  this.inUse = true;
  this.actionCounter = 0;
}
RAW_BUFFERClick to expand / collapse

Bug Description

When two browser_agent subagents are invoked sequentially in the same session, the second agent immediately hits the maxActionsPerTask limit (default 100) on its very first tool call, even though it's a completely new task.

Error message:

Error: Browser agent reached maximum action limit (100). Task terminated to prevent runaway execution. To config the limit, use maxActionsPerTask in the settings.

Root Cause

BrowserManager is a singleton (getInstance() returns the same instance for the same session mode). The actionCounter is only reset in two places:

  1. During connect() (line 762-763 in browserManager.ts)
  2. Never during release() or acquire()

When the first browser_agent finishes and the second one starts:

  • release() marks inUse = false but does not reset actionCounter
  • acquire() marks inUse = true but does not reset actionCounter
  • ensureConnection() sees the connection is still alive (isConnected() === true) and returns early — no reconnect, no counter reset

So the second agent inherits the exhausted counter (100) from the first agent.

Steps to Reproduce

  1. Start a session with a task that triggers two sequential browser_agent invocations
  2. The first browser_agent runs normally and exhausts its 100 actions
  3. The second browser_agent is spawned as a new subagent with a fresh task
  4. The second agent's very first tool call (list_pages, new_page, etc.) immediately returns the "maximum action limit" error

Expected Behavior

Each browser_agent invocation should have its own independent action budget of maxActionsPerTask actions, since they represent separate tasks.

Suggested Fix

Reset actionCounter in acquire(), which is called at the start of every new browser agent invocation:

acquire(): void {
  this.inUse = true;
  this.actionCounter = 0;
}

This ensures each new task starts with a fresh counter, regardless of whether the underlying connection is reused.

Environment

  • gemini-cli version: 0.40.1
  • Session mode: persistent (default)

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING