Skip to content

Fix multiple bugs with auth flow including using the implemented but unused restart support.#13565

Merged
jacob314 merged 1 commit intomainfrom
auth2
Nov 21, 2025
Merged

Fix multiple bugs with auth flow including using the implemented but unused restart support.#13565
jacob314 merged 1 commit intomainfrom
auth2

Conversation

@jacob314
Copy link
Copy Markdown
Contributor

@jacob314 jacob314 commented Nov 21, 2025

Summary

The auth flow was hard to read with important information sent to the debug console rather than displayed on the screen so users would have little indication of what was going on.

We were also neglecting to use the functionality @shrutip90 added to support restarting the IDE and so we were forcing users to restart manually in multiple places. Audited all places we were exiting adding the proper cleanup logic and calling the appropriate command to restart for cases where it was intended the user would restart.

Details

  • Centralized Terminal Control: Terminal interaction functions (mouse events, Kitty protocol, alternate screen, line wrapping) have been moved from packages/cli to a new shared packages/core/src/utils/terminal.ts module for improved reusability and consistency across the application.
  • Improved Authentication Flow: The user code authentication process (when NO_BROWSER=true) has been enhanced by utilizing the alternate screen buffer for a cleaner user experience and providing clearer feedback messages directly to the terminal.
  • Structured CLI Restart Mechanism: Direct process.exit(0) calls for scenarios requiring a CLI restart (e.g., after Google login when browser launch is suppressed) have been replaced with a specific RELAUNCH_EXIT_CODE and runExitCleanup(), enabling better external process management and a more graceful restart.
  • Enhanced Error Handling & User Feedback: Core error handling now consistently uses writeToStderr for critical errors, and informational/error messages during authentication are communicated via CoreEvent.UserFeedback, improving user communication.

Related Issues

Fixes: #12893

How to Validate

Demo of auth flow with browser:
https://screencast.googleplex.com/cast/NjQyNzU5Mjg4MTA3ODI3Mnw3NzQ1OGIxZC05Nw

Demo of auth flow with browser disabled:
https://screencast.googleplex.com/cast/NjIxNzg5Nzg2NDA2OTEyMHxkNWFiMGQxZC1mOA

Disable authentication with the browser via config and verify you can still authenticate seeing the whole auth string with correct line wrap in the console.

Validate cancelling the auth flow.

Validate that editing.a setting requiring restart now restarts automatically when you press r rather than making you do it.

The one known issue I wasn't able to fix is that ctrl-C does not work to exit with the readline based security code entry logic in core.

@jacob314 jacob314 requested a review from a team as a code owner November 21, 2025 08:45
@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @jacob314, 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 refactors and enhances the CLI's authentication process and terminal interaction logic. It centralizes terminal control functions into a shared core module, leading to more consistent behavior across the application. The authentication flow, especially for non-browser environments, is improved with a dedicated restart mechanism and better user feedback, addressing several underlying bugs and improving the overall user experience.

Highlights

  • Centralized Terminal Control: Terminal interaction functions (mouse events, Kitty protocol, alternate screen, line wrapping) have been moved from packages/cli to a new shared packages/core/src/utils/terminal.ts module for improved reusability and consistency across the application.
  • Improved Authentication Flow: The user code authentication process (when NO_BROWSER=true) has been enhanced by utilizing the alternate screen buffer for a cleaner user experience and providing clearer feedback messages directly to the terminal.
  • Structured CLI Restart Mechanism: Direct process.exit(0) calls for scenarios requiring a CLI restart (e.g., after Google login when browser launch is suppressed) have been replaced with a specific RELAUNCH_EXIT_CODE and runExitCleanup(), enabling better external process management and a more graceful restart.
  • Enhanced Error Handling & User Feedback: Core error handling now consistently uses writeToStderr for critical errors, and informational/error messages during authentication are communicated via CoreEvent.UserFeedback, improving user communication.
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
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 introduces several valuable improvements, primarily fixing bugs in the authentication flow and implementing restart support. The refactoring to centralize terminal control logic into @google/gemini-cli-core is a great step towards better code organization and maintainability. The user experience for the non-interactive authentication flow is also significantly enhanced. However, I've identified a critical issue where the application can hang if the user cancels the authentication code prompt.

Comment thread packages/core/src/code_assist/oauth2.ts
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Nov 21, 2025

Size Change: +3.34 kB (+0.02%)

Total Size: 21.1 MB

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

compressed-size-action

'\nFailed to authenticate with user code.',
i === maxRetries - 1 ? '' : 'Retrying...\n',
);
// Enter alternate buffer
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Rendering this in the alternate buffer is perhaps overkill but depending on if Gemini CLI was already rendering it is better if we ensure this is rendered in the alternate buffer than clear the main buffer as would be needed to ensure this UI doesn't conflict with Gemini CLI

writeToStdout('\u001B[2J\u001B[H');
disableMouseEvents();
disableKittyKeyboardProtocol();
enableLineWrapping();
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

enabling line wrapping is key so the URL is copyable/clickable

debugLogger.log(
'Please visit the following URL to authorize the application:',
);
debugLogger.log('');
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

the fact that these were debugLogger was very strange this was always UI written to stdout.

}

export function disableKittyKeyboardProtocol() {
writeToStdout('\x1b[<u');
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I've switched these back to the standard writeToStdout method as the sync version wasn't fixing issues anyway.

@jacob314 jacob314 added this pull request to the merge queue Nov 21, 2025
Merged via the queue into main with commit 030a5ac Nov 21, 2025
22 checks passed
@jacob314 jacob314 deleted the auth2 branch November 21, 2025 16:42
thacio added a commit to thacio/auditaria that referenced this pull request Nov 23, 2025
werdnum pushed a commit to werdnum/gemini-cli that referenced this pull request Nov 24, 2025
mboshernitsan pushed a commit that referenced this pull request Nov 25, 2025
@SandyTao520
Copy link
Copy Markdown
Contributor

/patch stable

@github-actions
Copy link
Copy Markdown

Patch workflow(s) dispatched successfully!

📋 Details:

  • Channels: stable
  • Commit: 030a5ace971816547a0df58966bf0e4c8c2dd495
  • Workflows Created: 1

🔗 Track Progress:

github-actions Bot pushed a commit that referenced this pull request Nov 26, 2025
…unused restart support. (#13565)

# Conflicts:
#	packages/cli/src/gemini.tsx
#	packages/cli/src/ui/AppContainer.test.tsx
#	packages/cli/src/ui/AppContainer.tsx
#	packages/cli/src/ui/utils/mouse.ts
#	packages/core/src/index.ts
@github-actions
Copy link
Copy Markdown

🚀 Patch PR Created!

📋 Patch Details:

📝 Next Steps:

  1. ⚠️ Resolve conflicts in the hotfix PR first: #13869
  2. Test your changes after resolving conflicts
  3. Once merged, the patch release will automatically trigger
  4. You'll receive updates here when the release completes

🔗 Track Progress:

SandyTao520 pushed a commit that referenced this pull request Nov 26, 2025
@github-actions
Copy link
Copy Markdown

🚀 Patch Release Started!

📋 Release Details:

  • Environment: prod
  • Channel: stable → publishing to npm tag latest
  • Version: v0.18.3
  • Hotfix PR: Merged ✅
  • Release Branch: release/v0.18.3-pr-13565

⏳ Status: The patch release is now running. You'll receive another update when it completes.

🔗 Track Progress:

@github-actions
Copy link
Copy Markdown

Patch Release Complete!

📦 Release Details:

  • Version: 0.18.4
  • NPM Tag: latest
  • Channel: stable
  • Dry Run: false

🎉 Status: Your patch has been successfully released and published to npm!

📝 What's Available:

🔗 Links:

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.

Authentication URL is cut off in iTerm2

3 participants