fix(availability): apply modelIdResolutions to tool sub-agent model configs#28406
fix(availability): apply modelIdResolutions to tool sub-agent model configs#28406vedhakoushik wants to merge 1 commit into
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 an issue where utility tool configurations were failing for API-key users who lacked preview access. By applying model ID resolution logic to non-chat model requests, the system now correctly maps restricted models to their available GA counterparts, preventing service disruptions for web-based tools. 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
|
|
📊 PR Size: size/M
|
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
There was a problem hiding this comment.
Code Review
This pull request addresses an issue where API-key users without preview access encountered INVALID_MODEL errors when using tool sub-agents (such as web-search or web-fetch). It resolves this by applying modelIdResolutions to non-chat-model calls within applyModelSelection, allowing preview-gated sub-agent models to fall back to appropriate GA models. The reviewer suggested using optional chaining and nullish coalescing when calling configuration methods on the config object to prevent potential runtime crashes when the configuration is partially mocked in tests or other contexts.
| hasAccessToPreview: config.getHasAccessToPreviewModel(), | ||
| useGemini3_1: config.getGemini31LaunchedSync(), | ||
| useGemini3_5Flash: config.hasGemini35FlashGAAccess(), |
There was a problem hiding this comment.
To prevent potential runtime crashes and maintain consistency with the rest of this file (such as in resolvePolicyChain), please use optional chaining and nullish coalescing when calling these configuration methods. This is especially important because config is frequently mocked or partially implemented in tests and other contexts, and calling these methods directly without guards can lead to TypeError exceptions.
| hasAccessToPreview: config.getHasAccessToPreviewModel(), | |
| useGemini3_1: config.getGemini31LaunchedSync(), | |
| useGemini3_5Flash: config.hasGemini35FlashGAAccess(), | |
| hasAccessToPreview: config.getHasAccessToPreviewModel?.() ?? false, | |
| useGemini3_1: config.getGemini31LaunchedSync?.() ?? false, | |
| useGemini3_5Flash: config.hasGemini35FlashGAAccess?.() ?? false, |
References
- When consuming an object, if a property is optional in its type definition (interface), callers must handle the
undefinedcase (e.g., by providing a default with??). Do not rely on the implementation details of the function that creates the object to always provide a value, as this can change. Code against the interface contract.
There was a problem hiding this comment.
Done — applied optional chaining and nullish coalescing on all three config method calls, consistent with the existing pattern at lines 54-57 of the same file. Force-pushed in the latest commit.
…onfigs web-search, web-fetch, loop-detection and other utility tools extend gemini-3-flash-base which hardcodes gemini-3-flash-preview. This model ID was never run through modelIdResolutions, so API-key users without preview access hit INVALID_MODEL on every web tool call. applyModelSelection now calls resolveModelId on the alias-resolved model for non-chat-model requests, mirroring the fallback logic that already exists for the main chat model router. Users without preview access are transparently downgraded to gemini-2.5-flash (or gemini-3.5-flash if Gemini 3.5 GA access is available). Fixes: google-gemini#28390
33990e3 to
25e7d72
Compare
Problem
Fixes #28390
web-search,web-fetch, and other utility tool configs extendgemini-3-flash-basewhich hardcodesgemini-3-flash-preview. This model ID was never run throughmodelIdResolutions, so API-key users without preview access (hasAccessToPreview: false) hitINVALID_MODELon every web tool call — completely breaking web search and URL fetching for these users.Affected aliases (all inherit from
gemini-3-flash-base):web-searchweb-fetchweb-fetch-fallbackloop-detectionllm-edit-fixernext-speaker-checkercontext-snapshotterRoot Cause
applyModelSelectioncallsgetResolvedConfigto walk the alias chain:The resolved model string (
gemini-3-flash-preview) is returned directly and used as-is. It is never passed throughresolveModelId, which already has the correct fallback contexts defined indefaultModelConfigs.ts:The fix logic exists — it just was not applied to non-chat-model calls.
For comparison, the main chat model goes through
ModelRouterServicewhich does callresolveModelId. Tool/utility model calls go directly throughapplyModelSelectionand skip that step entirely.Fix
In
applyModelSelection(packages/core/src/availability/policyHelpers.ts), for non-chat-model requests, run the alias-resolved model throughresolveModelIdwith the current session context before proceeding with availability selection:Chat model calls are explicitly excluded — the router already handles resolution for those.
Result
gemini-3-flash-preview✓gemini-3-flash-preview✓ (unchanged)INVALID_MODEL✗gemini-2.5-flash✓INVALID_MODEL✗gemini-3.5-flash✓Testing
applies modelIdResolutions for non-chat tool configs (web-search/web-fetch preview fallback)— assertsgemini-3-flash-preview→gemini-2.5-flashwhenhasAccessToPreview: falsedoes not apply modelIdResolutions for chat model calls (already routed)— assertsresolveModelIdis NOT called for chat model pathpolicyHelpers.test.ts,fallbackIntegration.test.ts, andbaseLlmClient.test.tsthat were missing the new config methodsChecklist
npx vitest run packages/core/src/availability/ packages/core/src/core/baseLlmClient.test.ts packages/core/src/tools/web-search.test.ts packages/core/src/tools/web-fetch.test.ts)