google-gemini / google-gemini/gemini-cli
Enhance browser_agent resilience: Automatic session takeover and lock recovery
- Dominant language
- TypeScript
- Stars
- 107k
- Forks
- 14.6k
- Avg merge
- 2d 3h
- Merged PRs (30d)
- 45
Description
### What would you like to be added?
The `browser_agent` (specifically `BrowserManager.ts`) currently employs a restrictive "fail-fast" strategy when encountering a locked browser profile (e.g., when `sessionMode: 'persistent'` is used and an existing instance or orphaned process is active):
```json
{
"success": false,
"summary": "The task could not be completed because the browser is already running for /home/user/.gemini/cli-browser-profile.",
"fullErrorMessage": "The browser is already running for /home/user/.gemini/cli-browser-profile. Use --isolated to run multiple browser instances.\nCause: The browser is already running for /home/user/.gemini/cli-browser-profile. Use a different userDataDir or stop the running browser first."
}
```
I propose to make it more resilient with the following capabilities:
1. **Automatic Session Takeover:** If `persistent` mode fails due to a profile lock, the agent should automatically attempt to connect to the existing instance (as if `sessionMode: 'existing'` were specified). This requires a graceful "fallback-and-probe" mechanism in `BrowserManager.connectMcp()`.
2. **Orphaned Process Recovery:** If an `existing` connection is not feasible but the profile remains locked, the `BrowserManager` should proactively detect orphaned `chrome` or `chrome-devtools-mcp` processes associated with the Gemini CLI profile and offer (or automatically execute) a "Self-Healing" routine (process termination + lock file removal).
3. **Intelligent Error Remediation:** Replace the current static error messages with an interactive recovery flow. Utilizing the `ask_user` tool, the agent should present the user with a "Choice" menu featuring numbered options to resolve the lock (e.g., **1. Attempt Session Takeover**, **2. Force Termination & Reset**, or **3. Launch Isolated Session**).
### Why is this needed?
Forcing the user to manually `pkill` processes or close browser windows is a friction point that degrades the autonomous agent experience. The agent has sufficient context (profile path, PIDs) to resolve this internally without user intervention.
### Additional context
Contributor guide
Assessment
This issue has not been assessed yet.