fix: isolate concurrent browser agent instances#24794
fix: isolate concurrent browser agent instances#24794gsquared94 merged 1 commit intogoogle-gemini:mainfrom
Conversation
Summary of ChangesHello, 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
Using Gemini Code AssistThe 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
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 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
|
There was a problem hiding this comment.
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.
893b2bf to
49d52ab
Compare
|
✅ 62 tests passed successfully on gemini-3-flash-preview. 🧠 Model Steering GuidanceThis PR modifies files that affect the model's behavior (prompts, tools, or instructions).
This is an automated guidance message triggered by steering logic signatures. |
49d52ab to
54f5747
Compare
54f5747 to
8f71c77
Compare
8f71c77 to
bfcf3cb
Compare
|
/gemini review |
There was a problem hiding this comment.
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.
Summary
When two
browser_agentcalls run concurrently (e.g., the model emits two parallelbrowser_agentfunction calls), they share a singleBrowserManagersingleton, causing one agent to navigate away from the other's page.This was introduced by
73dd7328d(persistent browser sessions) which changednew BrowserManager(config)→BrowserManager.getInstance(config)(singleton keyed bysessionMode:profilePath).Changes
browserManager.ts: Addacquire()/release()/isAcquired()tracking. ModifygetInstance()to create parallel instances with suffixed keys (e.g.,persistent:default:1) when the primary is already in-use.browserAgentFactory.ts: Callacquire()aftergetInstance()to mark the instance as in-use.browserAgentInvocation.ts: Callrelease()in thefinallyblock to make the instance available for reuse.How It Works
getInstance()→ gets primary instance → callsacquire()getInstance()→ primary isinUse→ gets new parallel instance (key:1) → callsacquire()release()makes the instance available for sequential reuseTesting