fix(google-gemini-cli-auth): fix Gemini CLI OAuth failures on Windows#40729
fix(google-gemini-cli-auth): fix Gemini CLI OAuth failures on Windows#40729vincentkoc merged 4 commits intoopenclaw:mainfrom
Conversation
Greptile SummaryThis PR fixes two independent Windows-only bugs in the Gemini CLI OAuth flow:
Both changes are narrow, focused fixes with no impact on Linux or macOS behavior. Confidence Score: 5/5
Last reviewed commit: 19531f6 |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 19531f686c
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
59ac27b to
d9b89fe
Compare
This comment was marked as spam.
This comment was marked as spam.
612db0b to
88d1d76
Compare
|
Friendly ping 🙂 — all CI checks are green and the PR is mergeable. Filed #41800 to track the underlying Windows bug. cc @steipete @mbelinky @obviyus — would appreciate a review when you get a chance. This fixes two independent bugs that completely break Gemini CLI OAuth on Windows (nvm installs). Happy to address any feedback! |
|
Please don’t spam-ping multiple maintainers at once. Be patient, or join our community Discord for help: https://discord.gg/clawd |
Two issues prevented Gemini CLI OAuth from working on Windows: 1. resolveGeminiCliDirs: the first candidate `dirname(dirname(resolvedPath))` can resolve to an unrelated ancestor directory (e.g. the nvm root `C:\Users\<user>\AppData\Local\nvm`) when gemini is installed via nvm. The subsequent `findFile` recursive search (depth 10) then picks up an `oauth2.js` from a completely different package (e.g. `discord-api-types/payloads/v10/oauth2.js`), which naturally does not contain Google OAuth credentials, causing silent extraction failure. Fix: validate candidate directories before including them — only keep candidates that contain a `package.json` or a `node_modules/@google/ gemini-cli-core` subdirectory. 2. resolvePlatform: returns "WINDOWS" on win32, but Google's loadCodeAssist API rejects it as an invalid Platform enum value (400 INVALID_ARGUMENT), just like it rejects "LINUX". Fix: use "PLATFORM_UNSPECIFIED" for all non-macOS platforms.
88d1d76 to
a865230
Compare
45905a5 to
ed11613
Compare
Summary
Gemini CLI OAuth is broken on Windows when gemini-cli is installed via nvm. Two independent bugs prevent setup from completing.
Bug 1:
extractGeminiCliCredentialsaccepts wrongoauth2.jsand gives upRoot cause: On Windows with nvm,
gemini.cmdresolves (viarealpathSync) to e.g.C:\Users\<user>\AppData\Local\nvm\v24.1.0\gemini.cmd. The first candidate pathdirname(dirname(resolvedPath))becomesC:\Users\<user>\AppData\Local\nvm— the nvm root directory.Since the direct path checks fail for this directory,
findFilekicks in with depth 10 and findsdiscord-api-types/payloads/v10/oauth2.js— a completely unrelated file. The code then immediately breaks out of the candidate loop and tries to extract credentials from this Discord types file. The regex naturally fails, and the function returnsnull, surfacing as:Fix: Move the credential regex validation (
googleusercontent.com+GOCSPX-) inside the candidate loop. When a foundoauth2.jsdoes not contain valid Google OAuth credentials, the search now continues to the next candidate instead of giving up. This is a minimal, defensive change that:resolveGeminiCliDirsor the candidate generation logicBug 2:
resolvePlatformreturns"WINDOWS"which Google API rejectsRoot cause:
resolvePlatform()returns"WINDOWS"onwin32, but Google'sloadCodeAssistAPI does not accept it as a validPlatformenum value (same as"LINUX"). All three endpoints respond with400 INVALID_ARGUMENT.Fix: Use
"PLATFORM_UNSPECIFIED"for all non-macOS platforms, consistent with how"LINUX"was already handled.Test plan
getExpectedPlatform()test helper to match newresolvePlatform()behavior