Skip to content

fix(cli): harden uncaughtException handler for PTY resize errors#27526

Open
amitesh0303 wants to merge 1 commit into
google-gemini:mainfrom
amitesh0303:fix/uncaught-exception-handler-v2
Open

fix(cli): harden uncaughtException handler for PTY resize errors#27526
amitesh0303 wants to merge 1 commit into
google-gemini:mainfrom
amitesh0303:fix/uncaught-exception-handler-v2

Conversation

@amitesh0303
Copy link
Copy Markdown

Summary

Details

Related Issues

How to Validate

Pre-Merge Checklist

  • Updated relevant documentation and README (if needed)
  • Added/updated tests (if needed)
  • Noted breaking changes (if any)
  • Validated on required platforms/methods:
    • MacOS
      • npm run
      • npx
      • Docker
      • Podman
      • Seatbelt
    • Windows
      • npm run
      • npx
      • Docker
    • Linux
      • npm run
      • npx
      • Docker

@amitesh0303 amitesh0303 requested a review from a team as a code owner May 28, 2026 12:22
@google-cla
Copy link
Copy Markdown

google-cla Bot commented May 28, 2026

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.

@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 enhances the stability of the CLI by hardening the uncaughtException handler. It specifically targets race conditions occurring during PTY resizing by silencing additional known error patterns that arise when a PTY process exits unexpectedly.

Highlights

  • Expanded Error Handling: Added detection for 'ioctl(2) failed' and 'ESRCH' error types to the uncaughtException handler.
  • Improved Stack Trace Filtering: Updated the isFromNodePty check to include additional stack trace signatures like 'UnixTerminal.resize', 'WindowsTerminal.resize', and 'resizePty' to ensure more robust filtering.
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 the 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 counterproductive. 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.

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 expands the uncaught exception handler in the CLI package to silence additional expected errors from node-pty during PTY resizing, specifically handling ioctl(2) failed and ESRCH errors, and broadening the stack trace detection. The reviewer suggested explicitly handling the optional error.stack property by providing a default boolean value (?? false) to comply with TypeScript type safety guidelines instead of relying on implicit falsy coercion.

Comment thread packages/cli/index.ts
Comment on lines 32 to +37
const isFromNodePty =
error.stack?.includes('node-pty') || error.stack?.includes('PtyResize');

if ((isPtyResizeError || isEbadfError) && isFromNodePty) {
error.stack?.includes('node-pty') ||
error.stack?.includes('PtyResize') ||
error.stack?.includes('UnixTerminal.resize') ||
error.stack?.includes('WindowsTerminal.resize') ||
error.stack?.includes('resizePty');
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

high

The error.stack property is optional on the Error interface (its type is string | undefined). To comply with the repository guidelines, we must explicitly handle the undefined case by providing a default value (e.g., using ?? false) rather than relying on implicit falsy coercion in conditional checks.

Suggested change
const isFromNodePty =
error.stack?.includes('node-pty') || error.stack?.includes('PtyResize');
if ((isPtyResizeError || isEbadfError) && isFromNodePty) {
error.stack?.includes('node-pty') ||
error.stack?.includes('PtyResize') ||
error.stack?.includes('UnixTerminal.resize') ||
error.stack?.includes('WindowsTerminal.resize') ||
error.stack?.includes('resizePty');
const isFromNodePty =
(error.stack?.includes('node-pty') ||
error.stack?.includes('PtyResize') ||
error.stack?.includes('UnixTerminal.resize') ||
error.stack?.includes('WindowsTerminal.resize') ||
error.stack?.includes('resizePty')) ??
false;
References
  1. When consuming an object, if a property is optional in its type definition (interface), callers must handle the undefined case (e.g., by providing a default with ??). Do not rely on the implementation details of the function that creates the object to always provide a value, as this can change. Code against the interface contract.

@gemini-cli gemini-cli Bot added the priority/p1 Important and should be addressed in the near term. label May 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

priority/p1 Important and should be addressed in the near term.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants