fix(gemini-cli): use backend project ID from onboarding response#2416
fix(gemini-cli): use backend project ID from onboarding response#2416kslamph wants to merge 2 commits intorouter-for-me:mainfrom
Conversation
- Simplify project ID selection to always use the backend project ID returned by Gemini onboarding - Update Gemini CLI version from 0.31.0 to 0.34.0 - Add 'terminal' to User-Agent string for better client identification Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
There was a problem hiding this comment.
Code Review
This pull request updates the .gitignore file, increments the GeminiCLIVersion to 0.34.0, and modifies the User-Agent string. It also simplifies the project ID mapping logic in performGeminiCLISetup by removing user-tier checks and interactive prompts. Feedback suggests refactoring the duplicated performGeminiCLISetup function into a shared package and simplifying the project ID assignment logic to eliminate redundant conditional branches.
| if explicitProject && !strings.EqualFold(responseProjectID, projectID) { | ||
| // Check if this is a free user (gen-lang-client projects or free/legacy tier) | ||
| isFreeUser := strings.HasPrefix(projectID, "gen-lang-client-") || | ||
| strings.EqualFold(tierID, "FREE") || | ||
| strings.EqualFold(tierID, "LEGACY") | ||
|
|
||
| if isFreeUser { | ||
| // Interactive prompt for free users | ||
| fmt.Printf("\nGoogle returned a different project ID:\n") | ||
| fmt.Printf(" Requested (frontend): %s\n", projectID) | ||
| fmt.Printf(" Returned (backend): %s\n\n", responseProjectID) | ||
| fmt.Printf(" Backend project IDs have access to preview models (gemini-3-*).\n") | ||
| fmt.Printf(" This is normal for free tier users.\n\n") | ||
| fmt.Printf("Which project ID would you like to use?\n") | ||
| fmt.Printf(" [1] Backend (recommended): %s\n", responseProjectID) | ||
| fmt.Printf(" [2] Frontend: %s\n\n", projectID) | ||
| fmt.Printf("Enter choice [1]: ") | ||
|
|
||
| reader := bufio.NewReader(os.Stdin) | ||
| choice, _ := reader.ReadString('\n') | ||
| choice = strings.TrimSpace(choice) | ||
|
|
||
| if choice == "2" { | ||
| log.Infof("Using frontend project ID: %s", projectID) | ||
| fmt.Println(". Warning: Frontend project IDs may not have access to preview models.") | ||
| finalProjectID = projectID | ||
| } else { | ||
| log.Infof("Using backend project ID: %s (recommended)", responseProjectID) | ||
| finalProjectID = responseProjectID | ||
| } | ||
| } else { | ||
| // Pro users: keep requested project ID (original behavior) | ||
| log.Warnf("Gemini onboarding returned project %s instead of requested %s; keeping requested project ID.", responseProjectID, projectID) | ||
| } | ||
| log.Infof("Gemini onboarding: requested project %s maps to backend project %s", projectID, responseProjectID) | ||
| log.Infof("Using backend project ID: %s", responseProjectID) | ||
| finalProjectID = responseProjectID | ||
| } else { | ||
| finalProjectID = responseProjectID | ||
| } |
There was a problem hiding this comment.
This logic is also present in internal/api/handlers/management/auth_files.go. In fact, the entire performGeminiCLISetup function is duplicated across both files.
With the changes in this PR, the logic has become identical. To improve maintainability and avoid having to apply the same changes in multiple places, this function should be extracted to a shared package (e.g., within internal/auth/gemini) and reused. This would prevent future inconsistencies and simplify maintenance.
| if explicitProject && !strings.EqualFold(responseProjectID, projectID) { | ||
| // Check if this is a free user (gen-lang-client projects or free/legacy tier) | ||
| isFreeUser := strings.HasPrefix(projectID, "gen-lang-client-") || | ||
| strings.EqualFold(tierID, "FREE") || | ||
| strings.EqualFold(tierID, "LEGACY") | ||
|
|
||
| if isFreeUser { | ||
| // For free users, use backend project ID for preview model access | ||
| log.Infof("Gemini onboarding: frontend project %s maps to backend project %s", projectID, responseProjectID) | ||
| log.Infof("Using backend project ID: %s (recommended for preview model access)", responseProjectID) | ||
| finalProjectID = responseProjectID | ||
| } else { | ||
| // Pro users: keep requested project ID (original behavior) | ||
| log.Warnf("Gemini onboarding returned project %s instead of requested %s; keeping requested project ID.", responseProjectID, projectID) | ||
| } | ||
| log.Infof("Gemini onboarding: requested project %s maps to backend project %s", projectID, responseProjectID) | ||
| log.Infof("Using backend project ID: %s", responseProjectID) | ||
| finalProjectID = responseProjectID | ||
| } else { | ||
| finalProjectID = responseProjectID | ||
| } |
There was a problem hiding this comment.
This if/else block can be simplified. Both branches assign responseProjectID to finalProjectID. You can move the assignment out of the conditional block to make the code more concise, while keeping the logging inside the if.
if explicitProject && !strings.EqualFold(responseProjectID, projectID) {
log.Infof("Gemini onboarding: requested project %s maps to backend project %s", projectID, responseProjectID)
log.Infof("Using backend project ID: %s", responseProjectID)
}
finalProjectID = responseProjectID
xkonjin
left a comment
There was a problem hiding this comment.
Code Review: Gemini CLI Project ID Simplification
Good cleanup removing the tier-based branching logic. However, there are concerns:
Critical Issue - Code Duplication:
The performGeminiCLISetup function is duplicated in two files:
internal/api/handlers/management/auth_files.go(lines 2569-2577)internal/cmd/login.go(lines 333-342)
The PR modifies both but they have diverged in comments and structure. The login.go version previously had interactive prompts that were removed, while auth_files.go had logging-only behavior. This should be refactored into a shared package as suggested by the Gemini Code Assist review.
Bug Risk:
-
Version Bump (line 15 in header_utils.go): Version bumped to 0.34.0 but no corresponding git tag or release notes. Ensure this matches the actual release version.
-
User-Agent Change (line 48): Added "; terminal" suffix. This could break API consumers that parse the User-Agent string. Verify this change is intentional and documented.
Missing Test Coverage:
- No tests for the project ID mapping logic
- No tests for the
responseProjectID != projectIDbranch - No tests verifying free vs pro tier behavior (now unified)
Security Note:
The simplification removes the free/pro tier distinction. Verify this is intentional from a product perspective - previously free users got backend project IDs for preview model access, now everyone does. This could have quota/billing implications.
Recommendation:
Refactor into a shared pkg/gemini package to eliminate duplication before merging.
…ment Both branches assign finalProjectID = responseProjectID, so move the assignment outside the conditional and keep only the logging inside.
luispater
left a comment
There was a problem hiding this comment.
Summary
This PR simplifies Gemini CLI project ID handling by always using the backend project ID returned by the onboarding response (when present), which should avoid the “frontend vs backend project” mismatch that can lead to auth failures. It also bumps the reported Gemini CLI version and adds terminal to the User-Agent for clearer client identification.
Findings
- ✅ The project ID assignment logic is now deterministic: when
responseProjectIDis present, it becomes the storedProjectIDregardless of tier. - ✅ The previous interactive prompt / free-vs-pro branching is removed, reducing complexity and failure modes.
⚠️ Behavior change: if a user explicitly requests a project ID and onboarding returns a different backend ID, the explicit choice is no longer honored. If this is intentional (per issue), it’s fine, but it’s worth documenting.
Checks / Tests
- CI
buildpassed. - No additional tests run locally.
Overall looks correct and low-risk given the small, targeted diff and successful CI.
This is an automated Codex review result and still requires manual verification by a human reviewer.
|
Thanks for the fix — the project ID simplification looks correct and aligns with upstream direction. One request before merging: Please bump Everything else LGTM. |
|
This PR is approved but currently has merge conflicts. Please change the base branch to |
Summary
Closes #2391
Test plan
🤖 Generated with Claude Code