Fix: Aborted Task and Closed Agent#25433
Fix: Aborted Task and Closed Agent#25433shahyashish wants to merge 1 commit intogoogle-gemini:mainfrom
Conversation
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
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 stability issues in the Gemini CLI where internal AbortErrors, often triggered during loop recovery, were causing the agent to crash or display intrusive stack traces. By centralizing error handling and improving the robustness of error identification, the changes ensure that these transient events are handled silently without interrupting the user session. 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 refactors the error handling in gemini.tsx by introducing a shared handleError function for unhandledRejection and uncaughtException events. The main change involves adding a handler for uncaughtException to prevent process crashes. However, a critical issue was identified: the current uncaughtException handling does not terminate the process for non-AbortError exceptions, which can lead to an unstable application state. A suggestion was provided to ensure proper cleanup and process termination for all non-AbortError uncaught exceptions, aligning with Node.js best practices. There is also a minor formatting change in the main function.
| process.on('uncaughtException', (error) => { | ||
| handleError(error); | ||
| }); |
There was a problem hiding this comment.
While handling uncaughtException prevents the process from crashing for AbortError, it's very risky to resume normal operation for other types of uncaught exceptions. According to the Node.js documentation, an uncaught exception leaves the application in an undefined state, and continuing to run can lead to unpredictable behavior, memory leaks, or data corruption.
The recommended practice is to perform cleanup and then terminate the process. For AbortError, the current logic of suppressing it is correct, but for all other errors, the process should exit gracefully to ensure stability.
process.on('uncaughtException', async (error) => {
// Suppress expected AbortErrors, which are not fatal.
if (error?.name === 'AbortError') {
handleError(error);
return;
}
// For any other uncaught exception, the application is in an undefined state.
// It is not safe to continue. Log the error, attempt cleanup, and exit.
handleError(error);
// The Node.js documentation strongly advises against resuming normal
// operation after an 'uncaughtException'. The process must terminate.
await runExitCleanup();
process.exit(1);
});
The issue was caused by an internal
AbortError(likely triggered by loop recovery inGeminiClient) surfacing as an unhandled rejection or uncaught exception, which then caused the agent to crash or show a scary stack trace.The fix involved updating
setupUnhandledRejectionHandlerinpackages/cli/src/gemini.tsxto:AbortErrorby checkingreason?.name === 'AbortError'. This is safer thaninstanceof Errorbecause in bundled environments or different Node versions (whereAbortErrormight be aDOMException), theinstanceofcheck can fail.uncaughtExceptionto handle cases where the error isn't caught by promise rejection logic, which prevents the Node.js process from exiting unexpectedly (the 'Closed Agent' part of the issue).debugLogger.log) to prevent transient internal recovery state changes from being displayed to the user as fatal errors.Test: To verify the fix:
abort()), ensure that noAbortErrorstack trace appears on the screen and the CLI session remains active (instead of closing the agent).AbortErrorrejection in a development build and verify it is caught silently by checking the debug logs, while a non-AbortError still triggers the 'CRITICAL' error message and opens the debug console.