Repository navigation
fix(auth): prevent infinite verification and OAuth retry loops - #29655
Conversation
|
📊 PR Size: size/L
|
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 several critical issues related to authentication and verification loops in the CLI. By introducing retry bounds, synchronizing concurrent OAuth flows, and stabilizing UI state transitions, the changes ensure that users are not trapped in infinite verification cycles and that authentication processes are more resilient to transient errors and race conditions. Highlights
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 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 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
|
There was a problem hiding this comment.
Code Review
This pull request introduces several improvements to the authentication and validation flows, including deduplicating concurrent OAuth2 requests, bounding verification retries to prevent infinite loops, and ensuring parent re-renders do not reset the validation dialog timer. The review feedback suggests resetting the authentication retry counter when a new token is successfully acquired in oauth2-provider.ts, and wrapping the asynchronous onSelect call in a try/catch block in AuthDialog.tsx to handle potential errors gracefully.
Note: Security Review did not run due to the size of the PR.
…Select error handling
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request introduces several improvements to the authentication and validation flows, including deduplicating concurrent OAuth2 authentication requests, bounding verification retries to prevent infinite loops, and preventing parent re-renders from resetting timers in the validation dialog. The feedback highlights a potential race condition in shouldRetryWithHeaders where concurrent 401/403 failures could independently increment the retry counter and exhaust the limit prematurely, suggesting a check to see if the token has already been updated or cleared by another request.
Note: Security Review did not run due to the size of the PR.
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request introduces several robustness improvements to the authentication and validation flows. Key changes include deduplicating concurrent interactive OAuth requests and gracefully handling concurrent token failures in OAuth2AuthProvider, adding a cancellation mechanism to the OAuth callback server, and bounding verification retries to a maximum of three attempts in both setupUser and retryWithBackoff to prevent infinite loops. Additionally, ValidationDialog now uses refs to prevent parent re-renders from resetting its transition timer, and error handling in AuthDialog has been improved to catch and forward errors thrown during selection. I have no further feedback to provide.
Note: Security Review did not run due to the size of the PR.
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request introduces several robustness improvements to the authentication and validation flows in the Gemini CLI. Key changes include coalescing concurrent token refresh and interactive auth requests in OAuth2AuthProvider to prevent duplicate flows, bounding verification retries to a maximum of three attempts in both setupUser and retryWithBackoff to prevent infinite loops, and using refs in ValidationDialog to prevent parent re-renders from resetting the success timer. Additionally, error handling has been enhanced in AuthDialog and useAuthCommand, a cancel mechanism has been added to startCallbackServer, and fallback metadata keys are now supported when classifying validation errors. Comprehensive unit tests have been added to verify these behaviors. I have no feedback to provide as there are no review comments to assess.
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request improves the robustness of the authentication and validation flows by deduplicating concurrent interactive OAuth2 requests, bounding verification retries to prevent infinite loops, and using refs in the validation dialog to prevent parent re-renders from resetting timers. It also adds a cancel mechanism to the OAuth callback server. Feedback identifies a potential crash in the callback server's abort handler if server.close() is called on an already closed server, suggesting a check on server.listening before closing.
Head branch was pushed to by a user without write access
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request improves the robustness of the authentication and validation flows. Key updates include deduplicating concurrent interactive OAuth2 requests, bounding verification retries to a maximum of three attempts to prevent infinite loops, and adding cancellation support to the OAuth callback server. Additionally, it optimizes React rendering in ValidationDialog and AppContainer by using refs and callbacks to prevent unnecessary timer resets, and refines error handling for validation and auth transitions. I have no feedback to provide.
Note: Security Review did not run due to the size of the PR.
Summary
Fixes an issue where users could get stuck in an infinite cycle of browser verification and OAuth prompts even after completing browser authentication and pressing Enter in the CLI.
Details
Bounded Verification Retries (
packages/core/src/utils/retry.ts,packages/core/src/code_assist/setup.ts):- Previously,
retryWithBackoffresetattempt = 0unconditionally wheneveronValidationRequiredreturned'verify', and_doSetupUserlooped inwhile (true)without a cap. Bounded verification retries toMAX_VALIDATION_ATTEMPTS = 3so persistent403 VALIDATION_REQUIREDresponses terminate cleanly instead of trapping the user in an infinite verification loop.- Added fallback extraction for
validation_urlandvalidation_learn_more_urlinclassifyValidationRequiredError(
packages/core/src/utils/googleQuotaErrors.ts).Terminal Redraw & Timer Stabilization (
packages/cli/src/ui/components/ValidationDialog.tsx,packages/cli/src/ui/AppContainer.tsx):- Stored
onChoicein a ref (onChoiceRef) with a completion guard (hasCompletedRef) insideValidationDialogand memoizedhandleShowAuthSelectioninAppContainer. Previously, parent re-renders recreatedonShowAuthSelectionandhandleValidationChoice, resetting the 500ms'complete'transition timer inValidationDialog.OAuth Callback & Token Acquisition Synchronization (
packages/core/src/agents/auth-provider/oauth2-provider.ts,packages/core/src/utils/oauth-flow.ts):- Deduplicated concurrent token acquisition / interactive OAuth flows in
OAuth2AuthProvider.headers()viapendingAuthPromise.- Reset
authRetryCount = 0when returning a valid cached token on subsequentheaders()calls.- Cleared the 5-minute callback timeout on server close/error in
startCallbackServer()and exposed acancelcallback to close the server cleanly when user consent is declined.Auth State Transitions (
packages/cli/src/ui/auth/useAuth.ts,packages/cli/src/ui/auth/AuthDialog.tsx):- Handled
ChangeAuthRequestedErrorandValidationCancelledErrorinuseAuthCommandby transitioning cleanly toAuthState.Updatingwithout setting a blockingauthError.- Cleared stale
authErrorand awaitedonSelectwhen a valid auth method is chosen inAuthDialog.Related Issues
Fixes #19936
How to Validate
Run the core unit test suites for OAuth flow, OAuth2 provider, retry logic, and Code Assist user setup:
npm test -w @google/gemini-cli-core -- src/agents/auth-provider/oauth2-provider.test.ts src/utils/oauth-flow.test.ts src/utils/retry.test.ts src/code_assist/setup.test.tsRun the CLI UI unit test suites for ValidationDialog, AuthDialog, useAuth, and useQuotaAndFallback:
npm test -w @google/gemini-cli -- src/ui/components/ValidationDialog.test.tsx src/ui/auth/AuthDialog.test.tsx src/ui/auth/useAuth.test.tsx src/ui/hooks/useQuotaAndFallback.test.ts
Run workspace typecheck and lint:
npm run typecheck && npm run lint
Pre-Merge Checklist