Skip to content

fix: isolate concurrent browser agent instances#24794

Merged
gsquared94 merged 1 commit intogoogle-gemini:mainfrom
gsquared94:fix/browser-regression2
Apr 8, 2026
Merged

fix: isolate concurrent browser agent instances#24794
gsquared94 merged 1 commit intogoogle-gemini:mainfrom
gsquared94:fix/browser-regression2

Conversation

@gsquared94
Copy link
Copy Markdown
Contributor

@gsquared94 gsquared94 commented Apr 6, 2026

Summary

When two browser_agent calls run concurrently (e.g., the model emits two parallel browser_agent function calls), they share a single BrowserManager singleton, causing one agent to navigate away from the other's page.

This was introduced by 73dd7328d (persistent browser sessions) which changed new BrowserManager(config)BrowserManager.getInstance(config) (singleton keyed by sessionMode:profilePath).

Changes

  • browserManager.ts: Add acquire()/release()/isAcquired() tracking. Modify getInstance() to create parallel instances with suffixed keys (e.g., persistent:default:1) when the primary is already in-use.
  • browserAgentFactory.ts: Call acquire() after getInstance() to mark the instance as in-use.
  • browserAgentInvocation.ts: Call release() in the finally block to make the instance available for reuse.
  • Tests: 4 new unit tests for concurrent isolation behavior, plus an integration test for concurrent browser agents with persistent session mode.

How It Works

  1. Agent A calls getInstance() → gets primary instance → calls acquire()
  2. Agent B calls getInstance() → primary is inUse → gets new parallel instance (key:1) → calls acquire()
  3. Both agents operate on separate browsers
  4. When each finishes, release() makes the instance available for sequential reuse

Testing

  • All 111 unit tests pass (browserManager + factory + invocation)
  • Integration test passes with persistent session mode
  • Manually validated with interactive CLI: two concurrent browser agents successfully navigated to separate GitHub repos and returned correct results
image

@gsquared94 gsquared94 requested a review from a team as a code owner April 6, 2026 22:43
@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request addresses a race condition where concurrent browser agent calls would inadvertently share a single BrowserManager singleton, causing navigation conflicts. By introducing an acquisition tracking system, the system now ensures that each concurrent agent receives its own isolated browser instance, which is then released back for reuse upon task completion.

Highlights

  • Concurrent Browser Isolation: Implemented an acquire/release mechanism in BrowserManager to prevent multiple concurrent browser agents from sharing the same browser instance.
  • Dynamic Instance Management: Modified BrowserManager.getInstance() to dynamically create parallel instances with suffixed keys when the primary instance is already in use.
  • Lifecycle Integration: Updated browserAgentFactory and browserAgentInvocation to properly acquire and release browser instances, ensuring they are returned to the pool after task completion.
  • Testing: Added comprehensive unit tests for concurrency logic and an integration test to verify that multiple browser agents can operate simultaneously without interference.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@gemini-cli gemini-cli bot added the status/need-issue Pull requests that need to have an associated issue. label Apr 6, 2026
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a mechanism to handle concurrent browser agent calls by allowing the BrowserManager to create and manage parallel instances when the primary instance is in use. It includes new acquire and release methods to track instance availability and adds comprehensive integration and unit tests to verify the concurrent behavior. Feedback focuses on potential resource exhaustion due to unbounded instance creation, isolation issues when multiple instances share the same persistent profile directory, and a potential resource leak if browser initialization fails after an instance is acquired.

@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 7, 2026

62 tests passed successfully on gemini-3-flash-preview.

🧠 Model Steering Guidance

This PR modifies files that affect the model's behavior (prompts, tools, or instructions).

  • ⚠️ Consider adding Evals: No behavioral evaluations (evals/*.eval.ts) were added or updated in this PR. Consider adding a test case to verify the new behavior and prevent regressions.
  • 🚀 Maintainer Reminder: Please ensure that these changes do not regress results on benchmark evals before merging.

This is an automated guidance message triggered by steering logic signatures.

@gsquared94
Copy link
Copy Markdown
Contributor Author

/gemini review

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces support for concurrent browser agents by implementing an acquisition and release mechanism within the BrowserManager. In 'isolated' session mode, the system now allows up to five parallel browser instances, each using a separate temporary profile. For 'persistent' and 'existing' modes, the code now explicitly prevents concurrent access to avoid Chrome profile lock conflicts. The changes include lifecycle management updates in the agent factory and invocation logic to ensure instances are released, along with comprehensive tests for these concurrency rules. Review feedback suggests refining an error message to be more concise for better terminal UI display.

@gsquared94 gsquared94 enabled auto-merge April 7, 2026 21:09
@gsquared94 gsquared94 added this pull request to the merge queue Apr 8, 2026
Merged via the queue into google-gemini:main with commit e77b22e Apr 8, 2026
29 checks passed
@gsquared94 gsquared94 deleted the fix/browser-regression2 branch April 8, 2026 15:07
warrenzhu25 pushed a commit to warrenzhu25/gemini-cli that referenced this pull request Apr 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

status/need-issue Pull requests that need to have an associated issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants