Skip to content

Conversation

@gundermanc
Copy link
Member

@gundermanc gundermanc commented Dec 31, 2025

Summary

Fixes an annoying issue where not selecting a Google account in the browser when prompted causes the terminal to hang for 5 minutes. Even Ctrl+C doesn't work when in this state.

The problem appears to be that the specialized buffering logic we do redirects all input, including that which handles Ctrl+C -> SIGINT translation.

I tried disabling raw mode while waiting for the user to auth and that seems to work ok though it causes an error stack to be printed to the console because the SIGINT bubbles up somewhere else instead of canceling the existing task.

Details

Related Issues

Fixes #15742

How to Validate

  • rm ~/.gemini/oauth_creds.json to delete cached creds.
  • Start Gemini CLI, running /auth if needed.
  • Select Google account.
  • When the browser opens, close it without clicking an account.
  • Previously terminal hangs. Now it prompts you to press any key to cancel. Pressing it returns you to the auth method choice list.

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

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @gundermanc, 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 significantly enhances the robustness and user experience of the CLI's OAuth authentication process. It introduces mechanisms to tolerate and differentiate between various authentication failure scenarios, such as when user interaction is required or when the process is explicitly cancelled. By implementing silent authentication attempts and refining the interactive login flow, the changes aim to make the CLI more resilient and user-friendly, especially in diverse operational environments. The refactoring also streamlines the initial application setup related to terminal interaction and authentication state management.

Highlights

  • Improved OAuth Failure Handling: The CLI now gracefully handles various OAuth authentication failures, distinguishing between cases where user interaction is required and fatal cancellations, preventing immediate errors and providing clearer feedback.
  • Silent Authentication Attempts: A new silentAuthOnly flag has been introduced to performInitialAuth, allowing the application to attempt authentication using only cached credentials without triggering interactive login flows. If interaction is required in this mode, it's handled without immediately opening an auth dialog.
  • User Cancellation for Interactive OAuth: Interactive OAuth flows now properly respond to user cancellations (e.g., Ctrl+C or escape key), leading to a FatalCancellationError which is then handled by resetting the authentication state without displaying a login failure message.
  • Refactored Authentication Logic: The core authentication logic has been refactored, moving the browser relaunch mechanism for Google login from AppContainer.tsx to useAuth.ts and simplifying the initial setup of raw mode and alternate screen handling in gemini.tsx.
  • Dependency Metadata Updates: Numerous peer: true entries have been removed from various dependencies within package-lock.json, indicating a potential update or refinement in how peer dependencies are managed.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

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.

@github-actions
Copy link

github-actions bot commented Dec 31, 2025

Size Change: +766 B (0%)

Total Size: 22.2 MB

ℹ️ View Unchanged
Filename Size Change
./bundle/gemini.js 22.2 MB +766 B (0%)
./bundle/sandbox-macos-permissive-closed.sb 1.03 kB 0 B
./bundle/sandbox-macos-permissive-open.sb 890 B 0 B
./bundle/sandbox-macos-permissive-proxied.sb 1.31 kB 0 B
./bundle/sandbox-macos-restrictive-closed.sb 3.29 kB 0 B
./bundle/sandbox-macos-restrictive-open.sb 3.36 kB 0 B
./bundle/sandbox-macos-restrictive-proxied.sb 3.56 kB 0 B

compressed-size-action

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 introduces significant improvements to the authentication flow, making it more robust by tolerating OAuth failures and allowing for user cancellation. The introduction of a silentAuthOnly mode is a great addition for non-interactive environments. The refactoring of authentication logic into the useAuth hook centralizes the responsibility and improves code organization. I've identified a couple of areas for improvement regarding type safety and code duplication that would further enhance the maintainability of these changes.


try {
if (silentAuthOnly) {
(config as any).silentAuthOnly = true;
Copy link
Contributor

Choose a reason for hiding this comment

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

high

Using as any to dynamically add a property to the config object circumvents TypeScript's type safety and can lead to maintainability issues. This creates an implicit contract between this function and the refreshAuth implementation that is not enforced by the type system.

A safer approach would be to introduce a mechanism for passing this option that is type-safe. For example, you could use a WeakMap to associate the silentAuthOnly flag with the config object without mutating it. Alternatively, if Config is a class you control, you could add a method to set temporary options, like config.setAuthOptions({ silent: true }), which would make the intent clearer and maintain type safety.

Comment on lines 135 to 147
const { runExitCleanup } = await import('../../utils/cleanup.js');
const { RELAUNCH_EXIT_CODE } = await import(
'../../utils/processUtils.js'
);
const { writeToStdout } = await import('@google/gemini-cli-core');

await runExitCleanup();
writeToStdout(`
----------------------------------------------------------------
Logging in with Google... Restarting Gemini CLI to continue.
----------------------------------------------------------------
`);
process.exit(RELAUNCH_EXIT_CODE);
Copy link
Contributor

Choose a reason for hiding this comment

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

high

This block of code for relaunching the application duplicates the logic found in relaunchApp from ../../utils/processUtils.js. Calling process.exit() directly from within a React hook is generally discouraged as it can lead to an abrupt termination of the application, bypassing React's cleanup lifecycle. It's better to use the existing relaunchApp utility, which is designed to handle this gracefully by including the necessary cleanup steps.

          const { relaunchApp } = await import('../../utils/processUtils.js');
          const { writeToStdout } = await import('@google/gemini-cli-core');

          writeToStdout(`
----------------------------------------------------------------
Logging in with Google... Restarting Gemini CLI to continue.
----------------------------------------------------------------
          `);
          await relaunchApp();

@gundermanc gundermanc force-pushed the gundermanc/tolerate-oauth-failures branch from f2d75cc to 3e9b687 Compare January 3, 2026 01:06
@gundermanc gundermanc changed the title Gundermanc/tolerate oauth failures Fix terminal hang when user exits browser without logging in Jan 3, 2026
@gundermanc gundermanc force-pushed the gundermanc/tolerate-oauth-failures branch from 3e9b687 to 65544f6 Compare January 3, 2026 01:52
@gundermanc gundermanc force-pushed the gundermanc/tolerate-oauth-failures branch from 65544f6 to 507ffd4 Compare January 3, 2026 02:07
@gundermanc gundermanc marked this pull request as ready for review January 3, 2026 02:11
@gundermanc gundermanc requested a review from a team as a code owner January 3, 2026 02:11
Copy link
Collaborator

@NTaylorMullen NTaylorMullen left a comment

Choose a reason for hiding this comment

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

Awesome catch! Few questions:

  • I noticed the use of writeToStdout to display the cancellation instructions. Since we’re using Ink for the TUI, do you think there’s a risk of UI flickering or text overlap when writing directly to stdout? Would it be safer to use coreEvents.emitFeedback('info', ...) instead to ensure the message is correctly handled by the UI engine?

  • Regarding the error handling: In the PR description, you mentioned that cancellation currently causes an error stack to be printed to the console. I noticed that useAuthCommand has a try-catch block that handles errors from refreshAuth—is that stack trace still appearing with this latest version of the PR, or was it specifically tied to the experiment with disabling raw mode? I just want to make sure we don't accidentally show a crash report to the user when they cancel.

@gundermanc
Copy link
Member Author

was it specifically tied to the experiment with disabling raw mode?

I think it was specifically related to disabling raw mode.

@gundermanc gundermanc enabled auto-merge January 5, 2026 18:07
@gundermanc gundermanc added this pull request to the merge queue Jan 5, 2026
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Jan 5, 2026
@gundermanc gundermanc enabled auto-merge January 5, 2026 18:41
@gundermanc gundermanc added this pull request to the merge queue Jan 5, 2026
Merged via the queue into main with commit 3997c7f Jan 5, 2026
29 of 33 checks passed
@gundermanc gundermanc deleted the gundermanc/tolerate-oauth-failures branch January 5, 2026 19:10
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.

Gemini CLI does not respond to ctrl+c and/or hangs if you close browser during auth

2 participants