fix(core, a2a-server): prevent hang during OAuth in non-interactive sessions#21045
fix(core, a2a-server): prevent hang during OAuth in non-interactive sessions#21045spencer426 merged 6 commits intomainfrom
Conversation
Summary of ChangesHello, 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 critical issue where the Gemini CLI and a2a-server could hang indefinitely during OAuth authentication in non-interactive environments. The changes introduce robust error handling for non-interactive sessions, prevent indefinite waits for user input, and provide an intelligent fallback to alternative authentication methods in cloud contexts, significantly improving the reliability and user experience in automated or headless deployments. Highlights
Changelog
Activity
Using Gemini Code AssistThe 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
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 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
|
There was a problem hiding this comment.
Code Review
This pull request effectively addresses an issue where the CLI could hang during OAuth in non-interactive sessions. The changes introduce an interactivity check before attempting manual authorization and add a timeout to user prompts. For a2a-server, it correctly detects headless mode and implements a fallback to Application Default Credentials in cloud environments, preventing hangs. The test coverage for these new behaviors is thorough. I have one suggestion to improve the error reporting during the authentication fallback to provide better diagnostic information, aligning with our guidelines for detailed error logging.
|
Size Change: +610 B (0%) Total Size: 26 MB ℹ️ View Unchanged
|
| return Promise.resolve(); | ||
| }); | ||
|
|
||
| // Update the mock implementation for this test |
- Introduced a pre-check for headless mode and GEMINI_CLI_USE_COMPUTE_ADC to avoid blocking OAuth prompts in non-interactive environments. - Updated refreshAuthentication to skip LOGIN_WITH_GOOGLE and prefer COMPUTE_ADC directly when headless or explicitly requested. - Improved error reporting by including both original failure and fallback failure details in FatalAuthenticationError. - Added comprehensive test cases in config.test.ts for headless success, ADC override, and detailed error reporting. - Verified fix with full monorepo preflight check. Fixes #21045
|
thank goodness, I've been trying to do gemini-cli development with gemini-cli on google-cloud using the OIDC login... Ive had to revert to 18.4! I sure hope this doesn't regress again, I saw some of the other attempts didn't include unit tests to capture this, so hopefully the coverage here helps keep this from happening again |

Summary
Prevent Gemini CLI and
a2a-serverfrom hanging during OAuth authentication in non-interactive environments by guarding the manual authorization flow and implementing an automated fallback toCOMPUTE_ADCin cloud environments.Details
packages/core):config.isInteractive()check inoauth2.tsbefore attempting the manual user code flow. If the session is non-interactive, it now throws aFatalAuthenticationErrorinstead of hanging on areadlineprompt.readlineprompt inauthWithUserCodeto prevent indefinite hangs even in interactive sessions.packages/a2a-server):loadConfigto dynamically set theinteractiveflag usingisHeadlessMode().refreshAuthenticationto automatically attempt fallback to Application Default Credentials (COMPUTE_ADC) ifLOGIN_WITH_GOOGLEfails in a cloud environment (e.g., Cloud Shell) or when forced viaGEMINI_CLI_USE_COMPUTE_ADC=true.Related Issues
Fixes #20854
How to Validate
a2a-serverin a headless environment (e.g.,echo | USE_CCPA=true a2a-server ...) and verify it fails fast with a descriptive error message instead of hanging.npm test -w @google/gemini-cli-core -- src/code_assist/oauth2.test.tsnpm test -w @google/gemini-cli-a2a-server -- src/config/config.test.tsPre-Merge Checklist