Skip to content

Conversation

@samedson
Copy link
Contributor

Description

Ensures the terminal works after you Ctrl-C

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @samedson, 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 InteractiveCLI's ability to gracefully manage terminal state. By introducing signal handlers for process exit and interruption (Ctrl-C), and centralizing cleanup logic, it ensures that the terminal is consistently returned to a normal, usable state, even in unexpected termination scenarios.

Highlights

  • Robust Terminal Cleanup: Implemented signal handlers for exit and SIGINT (Ctrl-C) to ensure proper terminal state restoration, preventing a "wonky" terminal after process termination.
  • Centralized Cleanup Logic: Refactored terminal cleanup operations into a dedicated cleanup() method, improving code organization and reusability.
  • Enhanced Terminal Reset: The cleanup process now explicitly disables application mode (\x1b[?1l) in addition to restoring cursor visibility (\x1b[?25h), ensuring a more complete terminal reset.
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 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 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.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

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
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 aims to improve the cleanup of agent evaluations, especially when interrupting the process with Ctrl-C. The changes introduce a cleanup method and add exit and SIGINT event handlers to ensure the terminal state is restored. My review identifies a key issue with the implementation of the SIGINT handler, which currently prevents the process from exiting as expected. I've provided a suggestion to correct this behavior by centralizing cleanup logic in the exit handler and ensuring the child process is also terminated, which prevents orphaned processes.

Comment on lines +40 to +45
process.on("exit", () => {
this.cleanup();
});
process.on("SIGINT", () => {
this.cleanup();
});
Copy link
Contributor

Choose a reason for hiding this comment

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

high

The SIGINT handler should terminate the process, and the exit handler should be responsible for all cleanup, including killing the child ptyProcess.

Currently:

  1. The SIGINT handler calls cleanup() but doesn't terminate the process. Attaching a listener to SIGINT prevents the default behavior of terminating the process. This will cause the process to hang after pressing Ctrl-C, which is likely not the intended behavior.
  2. The exit handler is called when the process terminates, but it doesn't kill the child ptyProcess, which could lead to orphaned processes.

By having the SIGINT handler simply call process.exit(), we trigger the exit event, centralizing all cleanup logic in one place. The exit handler should then be responsible for both cleaning up the terminal state and killing the child process.

    process.on("exit", () => {
      this.cleanup();
      if (this.ptyProcess) {
        this.ptyProcess.kill();
      }
    });
    process.on("SIGINT", () => {
      // This will trigger the "exit" handler to perform cleanup.
      process.exit();
    });

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant