Skip to content

Vertex ai model mapping fix#27749

Merged
DavidAPierce merged 10 commits into
mainfrom
vertex_ai_model_mapping_fix
Jun 9, 2026
Merged

Vertex ai model mapping fix#27749
DavidAPierce merged 10 commits into
mainfrom
vertex_ai_model_mapping_fix

Conversation

@DavidAPierce

@DavidAPierce DavidAPierce commented Jun 8, 2026

Copy link
Copy Markdown
Contributor

Summary

Refactor non-api key and non-Vertex AI model mapping for gemini-3.5-flash

Details

LOGIN_WITH_GOOGLE and COMPUTE_ADC auth types hit CCPA which routes gemini-3-flash to gemini-3.5-flash on their end, but they do not accept gemini-3.5-flash as the model ID. This updates calls to them as the exception rather than the rule, and sets the default 3.5 flash model to be gemini-3.5-flash and only changes it to gemini-3-flash when it should be hitting CCPA.

Related Issues

None.

How to Validate

  1. Build the project: npm run build
  2. Run the core config tests: npm test -w @google/gemini-cli-core -- src/config/models.test.ts
  3. Run the following exports for vertex ai login:
export GOOGLE_CLOUD_PROJECT="YOUR_PROJECT_NAME"
export GOOGLE_CLOUD_LOCATION="YOUR_LOCATION"
npm run start -- --model=gemini-3-flash
  1. Verify that the model mappings still function as expected when using /auth to login via vertex ai.
  2. Do the same for /auth for gemini-api-key authentication.

Pre-Merge Checklist

  • Added/updated tests (if needed - verified existing tests cover the change)
  • Validated on required platforms/methods:
    • Linux
      • npm run
      • npx
      • Docker

I have also validated locally using LOGIN_WITH_GOOGLE on an enterprise account, a gemin-api-key, and using vertex ai as login methods.

@DavidAPierce DavidAPierce requested a review from a team as a code owner June 8, 2026 21:51
@github-actions github-actions Bot added the size/m A medium sized PR label Jun 8, 2026
@github-actions

github-actions Bot commented Jun 8, 2026

Copy link
Copy Markdown

📊 PR Size: size/L

  • Lines changed: 503
  • Additions: +489
  • Deletions: -14
  • Files changed: 9

@gemini-code-assist

Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, 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 the Vertex AI and Gemini API model mapping logic to improve maintainability and consistency. By introducing a decorator pattern via ModelMappingContentGenerator, the system can now transparently redirect model requests based on predefined mappings, reducing hardcoded dependencies and potential configuration errors.

Highlights

  • Model Mapping Refactor: Introduced ModelMappingContentGenerator to dynamically map model names, ensuring consistent behavior across different authentication types.
  • Configuration Updates: Added VERTEX_AI_MODEL_MAPPINGS and GEMINI_API_MODEL_MAPPINGS to models.ts to centralize model redirection logic.
  • Core Integration: Updated createContentGenerator to wrap the generator with the new mapping logic based on the active authentication method.
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 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 .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 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

  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.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

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 a new ModelMappingContentGenerator class to dynamically map model names based on the authentication type (Vertex AI or Gemini API) and integrates it into the content generator setup. A critical issue was identified in packages/core/src/config/models.ts where the model mapping objects use the literal string "SECONDARY_GEMINI_3_5_FLASH_MODEL" as a key instead of its evaluated constant value. Using computed property names [SECONDARY_GEMINI_3_5_FLASH_MODEL] is recommended to resolve this issue.

Comment thread packages/core/src/config/models.ts Outdated
@github-actions

github-actions Bot commented Jun 8, 2026

Copy link
Copy Markdown

Size Change: +1.73 kB (+0.01%)

Total Size: 33.9 MB

Filename Size Change
./bundle/chunk-2XQHIRSU.js 0 B -13 kB (removed) 🏆
./bundle/chunk-5T5EOQZP.js 0 B -16.4 MB (removed) 🏆
./bundle/chunk-IOQYTDQN.js 0 B -3.43 kB (removed) 🏆
./bundle/chunk-KFDKRVXS.js 0 B -19.5 kB (removed) 🏆
./bundle/chunk-KQ7KU2D7.js 0 B -2.79 MB (removed) 🏆
./bundle/chunk-KXU4SYKZ.js 0 B -3.77 kB (removed) 🏆
./bundle/chunk-T22H5ZDM.js 0 B -49.2 kB (removed) 🏆
./bundle/chunk-Y7ZRWXVT.js 0 B -661 kB (removed) 🏆
./bundle/core-EZPWU45A.js 0 B -49.7 kB (removed) 🏆
./bundle/devtoolsService-5CNW7SEO.js 0 B -28 kB (removed) 🏆
./bundle/gemini-OBQS3373.js 0 B -589 kB (removed) 🏆
./bundle/interactiveCli-GTTN7IZI.js 0 B -1.3 MB (removed) 🏆
./bundle/liteRtServerManager-URCYOJFT.js 0 B -2.08 kB (removed) 🏆
./bundle/oauth2-provider-35K7QSBY.js 0 B -9.12 kB (removed) 🏆
./bundle/chunk-2YJHWBM6.js 16.4 MB +16.4 MB (new file) 🆕
./bundle/chunk-5RR6MRTO.js 661 kB +661 kB (new file) 🆕
./bundle/chunk-6I5KKVT3.js 2.79 MB +2.79 MB (new file) 🆕
./bundle/chunk-AQZ7W5C2.js 49.2 kB +49.2 kB (new file) 🆕
./bundle/chunk-NBLXMBAK.js 3.77 kB +3.77 kB (new file) 🆕
./bundle/chunk-RI2EJLRY.js 13 kB +13 kB (new file) 🆕
./bundle/chunk-TZCUW2Q5.js 19.5 kB +19.5 kB (new file) 🆕
./bundle/chunk-WOXI6HHQ.js 3.43 kB +3.43 kB (new file) 🆕
./bundle/core-4N6F37VM.js 49.7 kB +49.7 kB (new file) 🆕
./bundle/devtoolsService-UM7FEPU7.js 28 kB +28 kB (new file) 🆕
./bundle/gemini-PUMK2S2B.js 589 kB +589 kB (new file) 🆕
./bundle/interactiveCli-WJY6O5FK.js 1.3 MB +1.3 MB (new file) 🆕
./bundle/liteRtServerManager-JWUTNQNY.js 2.08 kB +2.08 kB (new file) 🆕
./bundle/oauth2-provider-6GYCYFBF.js 9.12 kB +9.12 kB (new file) 🆕
ℹ️ View Unchanged
Filename Size Change
./bundle/bundled/third_party/index.js 8 MB 0 B
./bundle/chunk-34MYV7JD.js 2.45 kB 0 B
./bundle/chunk-5AUYMPVF.js 858 B 0 B
./bundle/chunk-5PS3AYFU.js 1.18 kB 0 B
./bundle/chunk-6HI7VNOG.js 124 kB 0 B
./bundle/chunk-DAHVX5MI.js 206 kB 0 B
./bundle/chunk-IUUIT4SU.js 56.5 kB 0 B
./bundle/chunk-TUDYL3X4.js 40.3 kB 0 B
./bundle/cleanup-XA26XBSS.js 0 B -902 B (removed) 🏆
./bundle/devtools-V7NE4CQA.js 696 kB 0 B
./bundle/events-XB7DADIJ.js 418 B 0 B
./bundle/examples/hooks/scripts/on-start.js 188 B 0 B
./bundle/examples/mcp-server/example.js 1.43 kB 0 B
./bundle/gemini.js 5.38 kB 0 B
./bundle/getMachineId-bsd-TXG52NKR.js 1.55 kB 0 B
./bundle/getMachineId-darwin-7OE4DDZ6.js 1.55 kB 0 B
./bundle/getMachineId-linux-SHIFKOOX.js 1.34 kB 0 B
./bundle/getMachineId-unsupported-5U5DOEYY.js 1.06 kB 0 B
./bundle/getMachineId-win-6KLLGOI4.js 1.72 kB 0 B
./bundle/https-proxy-agent-AVGR4LHR.js 490 B 0 B
./bundle/multipart-parser-KPBZEGQU.js 11.7 kB 0 B
./bundle/sandbox-macos-permissive-open.sb 890 B 0 B
./bundle/sandbox-macos-permissive-proxied.sb 1.31 kB 0 B
./bundle/sandbox-macos-restrictive-open.sb 3.36 kB 0 B
./bundle/sandbox-macos-restrictive-proxied.sb 3.56 kB 0 B
./bundle/sandbox-macos-strict-open.sb 4.82 kB 0 B
./bundle/sandbox-macos-strict-proxied.sb 5.02 kB 0 B
./bundle/src-LG4OHBW7.js 233 kB 0 B
./bundle/src-QVCVGIUX.js 47 kB 0 B
./bundle/start-G33ISN7K.js 0 B -622 B (removed) 🏆
./bundle/tree-sitter-7U6MW5PS.js 274 kB 0 B
./bundle/tree-sitter-bash-34ZGLXVX.js 1.84 MB 0 B
./bundle/worker/worker-entry.js 361 kB 0 B
./bundle/cleanup-437MHKKB.js 902 B +902 B (new file) 🆕
./bundle/start-6DNXLJIM.js 622 B +622 B (new file) 🆕

compressed-size-action

@gemini-cli gemini-cli Bot added the status/need-issue Pull requests that need to have an associated issue. label Jun 8, 2026

@galdawave galdawave left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Intent Summary: This PR introduces a ModelMappingContentGenerator to intercept and rename model identifiers (specifically mapping gemini-3-flash to gemini-3.5-flash) right before the request is dispatched to @google/genai for Vertex AI and Gemini API backends. It also updates internal configuration assignment to default to gemini-3-flash while relying on the new mapping layer to translate it for the backend.

🚨 Critical Concerns (P0/P1)

Action required before merging.

  • packages/core/src/core/modelMappingContentGenerator.ts:38: The model mapping relies on strict string equality (this.mappings[req.model]). This will silently fail to map the model if it is passed with the models/ prefix (e.g., models/gemini-3-flash), which is commonly used throughout the application. It will bypass the interceptor and potentially cause a NOT_FOUND error from the API. Use the existing normalizeModelId utility.
    import { normalizeModelId } from '../utils/modelUtils.js';
    
    private mapModel<T extends { model?: string }>(req: T): T {
      if (req.model) {
        const normalizedModel = normalizeModelId(req.model);
        if (this.mappings[normalizedModel]) {
          return {
            ...req,
            model: req.model.startsWith('models/') 
              ? `models/${this.mappings[normalizedModel]}` 
              : this.mappings[normalizedModel],
          };
        }
      }
      return req;
    }

🧹 Refactoring & Nits (P2/P3)

Recommended improvements.

  • packages/core/src/config/config.ts:3567: The PR description states it replaces hardcoded values with constants, but this line hardcodes 'gemini-3-flash' instead of using the existing SECONDARY_GEMINI_3_5_FLASH_MODEL constant.
  • packages/core/src/config/config.test.ts:4360: Same as above. The test asserts against the hardcoded literal 'gemini-3-flash' instead of the constant.

📝 Metadata Review

Feedback on PR description or commit message clarity.

  • The PR description claims it "Replaced hardcoded values in packages/core/src/config/models.ts", but the diff actually adds entirely new constants (VERTEX_AI_MODEL_MAPPINGS and GEMINI_API_MODEL_MAPPINGS) and introduces an interceptor. It would be helpful to clarify that this PR introduces a new ModelMappingContentGenerator to remap aliases right before the API call.

…r loggingContnentGenerator so that it doesn't ignore experiment flag checks when wrapped.
@github-actions github-actions Bot added the size/l A large sized PR label Jun 9, 2026
@DavidAPierce

Copy link
Copy Markdown
Contributor Author

Addressed Critical Concerns (P0/P1) from the previous comment:
The wrapper now accounts for potential prefixes and has tests associated with it to verify.

Refactoring & Nits (P2/P3):
These must remain "magic strings" as the default models can be overwritten at runtime depending on flag access or auth type, and needs to be checked against and re-updated. Since the values of those defaults can be changed, they cannot be relied on as a source of truth in this instance.

Note that when the flag can be cleaned up this will no longer be the case, and these values will become consts again.

Updated pr description according to refactors.

…tor now that their model names are assumed correct by default.
@DavidAPierce DavidAPierce enabled auto-merge June 9, 2026 19:48
@DavidAPierce DavidAPierce added this pull request to the merge queue Jun 9, 2026
Merged via the queue into main with commit f08b4af Jun 9, 2026
32 checks passed
@DavidAPierce DavidAPierce deleted the vertex_ai_model_mapping_fix branch June 9, 2026 20:16
@DavidAPierce

Copy link
Copy Markdown
Contributor Author

/patch

@github-actions

github-actions Bot commented Jun 9, 2026

Copy link
Copy Markdown

🚀 [Step 1/4] Patch workflow(s) waiting for approval!

📋 Details:

  • Channels: stable,preview
  • Commit: f08b4af65459ee8626187fb0cd823395649b9b1e
  • Workflows Created: 2

⏳ Status: The patch creation workflow has been triggered and is waiting for deployment approval. Please visit the specific workflow links below and approve the runs.

🔗 Track Progress:

@github-actions

github-actions Bot commented Jun 9, 2026

Copy link
Copy Markdown

🚀 [Step 2/4] Patch PR Created!

📋 Patch Details:

📝 Next Steps:

  1. Review and approve the hotfix PR: #27768
  2. Once merged, the patch release will automatically trigger
  3. You'll receive updates here when the release completes

🔗 Track Progress:

@github-actions

github-actions Bot commented Jun 9, 2026

Copy link
Copy Markdown

🚀 [Step 2/4] Patch PR Created!

📋 Patch Details:

📝 Next Steps:

  1. Review and approve the hotfix PR: #27769
  2. Once merged, the patch release will automatically trigger
  3. You'll receive updates here when the release completes

🔗 Track Progress:

@github-actions

github-actions Bot commented Jun 9, 2026

Copy link
Copy Markdown

🚀 [Step 3/4] Patch Release Waiting for Approval!

📋 Release Details:

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

⏳ Status: The patch release has been triggered and is waiting for deployment approval. Please visit the specific workflow run link below and approve the deployment. You'll receive another update when it completes.

🔗 Track Progress:

@github-actions

github-actions Bot commented Jun 9, 2026

Copy link
Copy Markdown

🚀 [Step 3/4] Patch Release Waiting for Approval!

📋 Release Details:

  • Environment: prod
  • Channel: preview → publishing to npm tag preview
  • Version: v0.46.0-preview.2
  • Hotfix PR: Merged ✅
  • Release Branch: release/v0.46.0-preview.2-pr-27749

⏳ Status: The patch release has been triggered and is waiting for deployment approval. Please visit the specific workflow run link below and approve the deployment. You'll receive another update when it completes.

🔗 Track Progress:

@github-actions

github-actions Bot commented Jun 9, 2026

Copy link
Copy Markdown

[Step 4/4] Patch Release Complete!

📦 Release Details:

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

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

📝 What's Available:

🔗 Links:

@github-actions

github-actions Bot commented Jun 9, 2026

Copy link
Copy Markdown

[Step 4/4] Patch Release Complete!

📦 Release Details:

🎉 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

size/l A large sized PR size/m A medium sized PR status/need-issue Pull requests that need to have an associated issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants