Skip to content

fix(cli): forward termination signals to relaunched child process#25642

Open
ixchio wants to merge 1 commit intogoogle-gemini:mainfrom
ixchio:fix/signal-forwarding-relaunch
Open

fix(cli): forward termination signals to relaunched child process#25642
ixchio wants to merge 1 commit intogoogle-gemini:mainfrom
ixchio:fix/signal-forwarding-relaunch

Conversation

@ixchio
Copy link
Copy Markdown

@ixchio ixchio commented Apr 18, 2026

This one's been bugging me — when you kill the parent process, the child just... keeps running.

The problem

relaunchAppInChildProcess spawns a child but never forwards SIGTERM, SIGHUP, or SIGINT. So if a process manager (or just kill <pid>) sends a signal to the parent, the child becomes an orphan. Pretty annoying in containers and ACP setups.

What I did

  • Added signal forwarder handlers right after spawn() for SIGTERM, SIGHUP, and SIGINT
  • Each handler checks child.killed before forwarding (no point sending signals to a dead process)
  • Forwarders get cleaned up on both close and error events
  • Wrapped child.send() in try/catch — if the IPC channel is already dead when we try to send admin settings, we don't want that to leak the signal handlers

Why not PR #25605?

That PR had a couple issues the reviewers flagged:

  • Conditional !process.stdin.isTTY check that re-introduces the leak for programmatic kill -INT
  • Inaccurate comments about Ctrl+C behavior
  • Potential listener leak if child.send() throws before promise setup

This PR forwards unconditionally and handles the cleanup properly.

Tests

Added 4 tests:

  • SIGTERM gets forwarded to child
  • Signal forwarders get registered on spawn
  • Forwarders get removed after child closes
  • Signals are skipped when child is already killed
Test Files  1 passed (1)
     Tests  12 passed (12)

Fixes #25590

cc @scidomino @jacob314 would love your eyes on this

@ixchio ixchio requested a review from a team as a code owner April 18, 2026 22:45
@google-cla
Copy link
Copy Markdown

google-cla bot commented Apr 18, 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 addresses an issue where child processes spawned by the CLI become orphaned when the parent process is terminated. By explicitly forwarding termination signals and ensuring proper cleanup of event listeners, the changes ensure that the child process lifecycle is correctly tied to the parent, improving stability in containerized and automated environments.

Highlights

  • Signal Forwarding: Implemented signal forwarding for SIGTERM, SIGHUP, and SIGINT from the parent process to the child process to prevent orphaned processes.
  • Resource Cleanup: Added automatic cleanup of signal listeners upon child process termination or error to prevent memory leaks.
  • IPC Robustness: Wrapped IPC communication in try/catch blocks to ensure signal handlers are correctly managed even if the IPC channel is closed.
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.

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 implements signal forwarding from the parent process to the child process in relaunchAppInChildProcess to prevent orphaned processes, including listener cleanup and improved IPC error handling. Feedback suggests removing the !child.killed guard to allow for signal escalation (e.g., sending SIGTERM after SIGINT) and reordering the message listener registration to ensure it is active before the initial child.send() call. The test suite should also be updated to reflect these logic improvements.

Comment thread packages/cli/src/utils/relaunch.ts
Comment thread packages/cli/src/utils/relaunch.ts
Comment thread packages/cli/src/utils/relaunch.test.ts Outdated
@gemini-cli gemini-cli bot added area/core Issues related to User Interface, OS Support, Core Functionality help wanted We will accept PRs from all issues marked as "help wanted". Thanks for your support! labels Apr 18, 2026
When relaunchAppInChildProcess spawns a child, it doesn't forward
SIGTERM, SIGHUP, or SIGINT. If the parent gets killed by a process
manager or via kill(pid), the child becomes an orphan — particularly
problematic in containers and ACP deployments.

This installs signal forwarders right after spawn() and cleans them
up on close/error. The child.send() call is wrapped in try/catch so
a dead IPC channel doesn't leak handlers.

Fixes google-gemini#25590
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/core Issues related to User Interface, OS Support, Core Functionality help wanted We will accept PRs from all issues marked as "help wanted". Thanks for your support!

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: relaunchAppInChildProcess does not forward signals to child, orphaning it when parent is killed

2 participants