Skip to content

fix(cli): prevent crash during authentication in git repositories - #29163

Closed
ehsan-fj wants to merge 4 commits into
google-gemini:mainfrom
ehsan-fj:fix-waiting-for-auth
Closed

ehsan-fj wants to merge 4 commits into
google-gemini:mainfrom
ehsan-fj:fix-waiting-for-auth

Conversation

@ehsan-fj

@ehsan-fj ehsan-fj commented Sep 1, 2026

Copy link
Copy Markdown

Summary

Prevent Gemini CLI from crashing on startup when run inside a Git repository under macOS Seatbelt or other restricted permissions environments.

Details

When Gemini CLI starts up, the useGitBranchName hook is mounted to retrieve and display the active Git branch. If a .git folder is present, it initializes a Node.js fs.watch file watcher on the .git directory to monitor changes.

In environments with restricted sandbox permissions (like macOS Seatbelt), the file watcher can fail/emit an asynchronous 'error' event. Because Node's FSWatcher lacked an 'error' event listener, this unhandled 'error' event terminated the Node process immediately.

This PR adds a graceful listener to 'error' events on the watcher to suppress/log them without crashing the entire CLI. It also safely guards the registration with typeof w.on === 'function' to avoid breaking existing testing mocks.

Related Issues

Fixes #29153

How to Validate

  1. Run the unit tests for useGitBranchName and verify all 8 tests pass (including our newly added error suppression test):
    npx vitest run packages/cli/src/ui/hooks/useGitBranchName.test.tsx
  2. Run the CLI locally inside a Git directory under restricted sandboxed permissions and verify it no longer crashes during the authentication/loading state.

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
      • Seatbelt

@ehsan-fj
ehsan-fj requested review from a team as code owners September 1, 2026 22:35
@github-actions github-actions Bot added the size/l A large sized PR label Sep 1, 2026
@github-actions

github-actions Bot commented Sep 1, 2026

Copy link
Copy Markdown

📊 PR Size: size/L

  • Lines changed: 677
  • Additions: +32
  • Deletions: -645
  • Files changed: 3

@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 a stability issue where the Gemini CLI would crash upon startup when running inside a Git repository within restricted environments, such as macOS Seatbelt. By adding an error listener to the file watcher responsible for monitoring Git branch changes, the application now gracefully logs these errors instead of encountering an unhandled exception that terminates the process.

Highlights

  • Error Handling: Added an 'error' event listener to the Git directory file watcher to prevent the CLI from crashing in restricted environments.
  • Safety Guard: Implemented a check to ensure the watcher object supports the 'on' method before attaching the listener, maintaining compatibility with existing test mocks.
  • Testing: Added a new unit test case to verify that watcher errors are handled gracefully without terminating the process.
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. ↩

@gemini-code-assist gemini-code-assist Bot left a comment

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.

Code Review

This pull request cleans up unused test dependencies from packages/a2a-server and packages/sdk in package-lock.json. It also improves the useGitBranchName hook in packages/cli by adding error handling to the file watcher and introduces a unit test to verify this behavior. Feedback is provided to ensure the watcher instance is checked for existence before accessing its properties to prevent potential runtime crashes in environments where it might be undefined.

Comment thread packages/cli/src/ui/hooks/useGitBranchName.ts Outdated
@gemini-cli gemini-cli Bot added priority/p1 Important and should be addressed in the near term. area/security Issues related to security labels Sep 1, 2026
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>

@jhdz69833-create jhdz69833-create left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Excelente

@gemini-cli

gemini-cli Bot commented Sep 9, 2026

Copy link
Copy Markdown
Contributor

Hi there! Thank you for your interest in contributing to Gemini CLI.

To ensure we maintain high code quality and focus on our prioritized roadmap, we only guarantee review and consideration of pull requests for issues that are explicitly labeled as 'help wanted'.

This PR will be closed in 7 days if it remains without that designation. We encourage you to find and contribute to existing 'help wanted' issues in our backlog! Thank you for your understanding.

@gemini-cli

gemini-cli Bot commented Sep 16, 2026

Copy link
Copy Markdown
Contributor

This pull request is being closed as it has been open for 14 days without a 'help wanted' designation. We encourage you to find and contribute to existing 'help wanted' issues in our backlog! Thank you for your understanding.

@gemini-cli gemini-cli Bot closed this Sep 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/security Issues related to security priority/p1 Important and should be addressed in the near term. size/l A large sized PR status/pr-nudge-sent

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Gemini CLI v0.57.0 hangs on "Waiting for authentication..." in subdirectories on macOS

3 participants