google-gemini / google-gemini/gemini-cli
MaxListenersExceededWarning and Infinite Loop with gemma-4-31b-it (Gemini API)
- Dominant language
- TypeScript
- Stars
- 107k
- Forks
- 14.6k
- Avg merge
- 2d 3h
- Merged PRs (30d)
- 45
Description
### What happened?
[ACTION REQUIRED] 📎 PLEASE ATTACH THE EXPORTED CHAT HISTORY JSON FILE TO THIS ISSUE IF YOU FEEL COMFORTABLE SHARING IT.
### What did you expect to happen?
The CLI should handle larger context payloads reliably without triggering a cascade of abort signal listeners or falling into an infinite retry loop when processing model responses.
### Client information
* **CLI Version:** 0.49.0
* **Git Commit:** 5d402f89f
* **Session ID:** 8a648203-aa42-4de0-aaef-f8963cc226fa
* **Operating System:** linux v20.20.2
* **Sandbox Environment:** no sandbox
* **Model Version:** gemma-4-31b-it
* **Auth Type:** gemini-api-key
* **Memory Usage:** 322.6 MB
* **Terminal Name:** VTE(7600)
* **Terminal Background:** #300a24
* **Kitty Keyboard Protocol:** Unsupported
### Login information
api-key
### Anything else we need to know?
Description:
When using gemma-4-31b-it (via Gemini API key authentication) in the Gemini CLI, the application enters an infinite "thinking-loop" when processing sessions with large context. The
process rapidly throws a MaxListenersExceededWarning: Possible EventTarget memory leak detected. 11 abort listeners added to [AbortSignal].
Steps to Reproduce:
1. Authenticate using gemini-api-key.
2. Configure settings.json to use gemma-4-31b-it via the Gemini API.
3. Engage in a session that utilizes a larger context payload.
4. Observe the rapid onset of the "thinking-loop" followed by the MaxListenersExceededWarning.
Diagnostic Findings & Attempts:
* Listener Leak: The MaxListenersExceededWarning indicates a rapid accumulation of AbortSignal listeners, likely due to an unhandled retry mechanism when requests hang or fail
during large context processing.
* Behavior: The loop and warning appear very quickly, suggesting that the CLI enters a rapid retry-cycle as soon as the API response handling for this specific model configuration
encounters an issue.
* Attempted Workarounds (Failed):
* general.maxAttempts restricted to 2.
* connection.timeoutMs increased to 300,000.
* Global EventEmitter.defaultMaxListeners increased to 50 via Node.js preload script (NODE_OPTIONS="-r increase-listeners.js").
* Result: The issue persists regardless of these configuration adjustments, suggesting a deeper architectural issue in how the CLI manages streams and listeners for gemma-4-31b-it
requests.
Contributor guide
Research direction
Start by reproducing the issue with settings.json configured for gemma-4-31b-it through the Gemini API, using a large-context session and the reported retry and timeout settings. Trace the Gemini API request, stream, retry, and abort-listener handling from the resulting warning. Done means the CLI processes the model response without an infinite thinking-loop or repeated MaxListenersExceededWarning.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- ai, cli
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100