Skip to content

fix(core): handle optional response fields from code assist API#20345

Merged
sehoon38 merged 2 commits intomainfrom
fix-code-assist-optional-fields
Feb 27, 2026
Merged

fix(core): handle optional response fields from code assist API#20345
sehoon38 merged 2 commits intomainfrom
fix-code-assist-optional-fields

Conversation

@sehoon38
Copy link
Contributor

Summary

This PR makes several fields within the Code Assist API responses optional and ensures the system handles these cases gracefully. Specifically, it updates the type definitions in packages/core/src/code_assist/types.ts and converter.ts to reflect the possibility of missing data (e.g., id, name, candidates, totalTokens) and provides robust fallbacks in setup.ts when tier IDs are missing.

Details

  • Updated CaGenerateContentResponse, VertexGenerateContentResponse, and CaCountTokenResponse in converter.ts to make properties optional and provide safe fallbacks.
  • Updated GeminiUserTier, IneligibleTier, PrivacyNotice, LongRunningOperationResponse, OnboardUserResponse, and CodeAssistGlobalUserSettingResponse in types.ts to make their respective properties optional.
  • Updated setup.ts to log warnings when the user tier ID is not returned from the Code Assist API (loadCodeAssist or onboardUser) and defaults to the STANDARD tier securely.

Related Issues

Fixes #20187

How to Validate

  1. Run the local test suite using npm run test
  2. Ensure no typing errors by running npm run typecheck
  3. Verify the Code Assist connection sets up as expected and defaults to STANDARD if a mocked API response is provided without tier IDs.

Pre-Merge Checklist

  • Updated relevant documentation and README (if needed)
  • Added/updated tests (if needed)
  • Noted breaking changes (if any)
  • Validated on required platforms/methods:
    • MacOS
      • npm run
      • npx
      • Docker
      • Podman
      • Seatbelt
    • Windows
      • npm run
      • npx
      • Docker
    • Linux
      • npm run
      • npx
      • Docker

@sehoon38 sehoon38 requested a review from a team as a code owner February 25, 2026 20:58
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @sehoon38, 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 enhances the resilience of the system by making various fields in the Code Assist API responses optional. This change prevents potential runtime errors when expected data is absent, ensuring that the application can gracefully handle incomplete responses. It also introduces default values and logging for critical user tier information, improving the overall stability and diagnostic capabilities of the Code Assist integration.

Highlights

  • API Response Robustness: Made several fields within Code Assist API responses optional to handle cases where data might be missing, preventing potential runtime errors.
  • Type Definition Updates: Modified type definitions in types.ts and converter.ts to accurately reflect the optionality of fields such as id, name, candidates, and totalTokens.
  • Fallback Mechanisms: Implemented robust fallbacks in setup.ts to default to the STANDARD tier when user tier IDs are not provided by the Code Assist API, ensuring consistent behavior.
  • Improved Logging: Added warning logs in setup.ts when user or onboarding tier IDs are missing, aiding in debugging and operational awareness.
Changelog
  • packages/cli/src/ui/hooks/usePrivacySettings.ts
    • Updated getRemoteDataCollectionOptIn and setRemoteDataCollectionOptIn to use nullish coalescing (??) for freeTierDataCollectionOptin, defaulting to true or the provided optIn value respectively.
  • packages/core/src/code_assist/converter.test.ts
    • Modified test assertions to use the non-null assertion operator (!) on codeAssistRes.response when accessing its properties, aligning with the updated type definitions.
  • packages/core/src/code_assist/converter.ts
    • Made response property optional in CaGenerateContentResponse.
    • Made candidates property optional in VertexGenerateContentResponse.
    • Made totalTokens property optional in CaCountTokenResponse.
    • Added a nullish coalescing fallback to 0 for totalTokens in fromCountTokenResponse.
  • packages/core/src/code_assist/setup.ts
    • Imported debugLogger for enhanced logging.
    • Added warning logs when paidTier?.id or currentTier.id are missing during user setup.
    • Added UserTierId.STANDARD as a fallback for userTier in multiple return paths within setupUser.
    • Added a warning log when the onboarding tier.id is missing.
  • packages/core/src/code_assist/types.ts
    • Made id optional in GeminiUserTier.
    • Made reasonCode, reasonMessage, tierId, and tierName optional in IneligibleTier.
    • Made showNotice optional in PrivacyNotice.
    • Made name optional in LongRunningOperationResponse.
    • Made id and name optional within cloudaicompanionProject in OnboardUserResponse.
    • Made freeTierDataCollectionOptin optional in CodeAssistGlobalUserSettingResponse.
Activity
  • Updated existing tests in converter.test.ts to reflect changes in type definitions.
  • Added warning logs for missing tier IDs in setup.ts to improve debugging.
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 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 counter productive. 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.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

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.

Copy link
Contributor

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

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 effectively addresses the potential for missing fields in the Code Assist API responses by making several type definitions optional and implementing robust fallbacks. The changes in types.ts, converter.ts, and setup.ts work together to handle optional tier IDs and other response data gracefully, defaulting to the STANDARD tier and logging warnings where appropriate. The updates in usePrivacySettings.ts also correctly handle optional boolean values. The overall implementation is solid and significantly improves the client's resilience to API variations. I have not found any issues of high or critical severity.

@github-actions
Copy link

github-actions bot commented Feb 25, 2026

Size Change: +1.03 kB (0%)

Total Size: 25.7 MB

Filename Size Change
./bundle/gemini.js 25.2 MB +1.03 kB (0%)
ℹ️ View Unchanged
Filename Size
./bundle/node_modules/@google/gemini-cli-devtools/dist/client/main.js 221 kB
./bundle/node_modules/@google/gemini-cli-devtools/dist/src/_client-assets.js 227 kB
./bundle/node_modules/@google/gemini-cli-devtools/dist/src/index.js 11.5 kB
./bundle/node_modules/@google/gemini-cli-devtools/dist/src/types.js 132 B
./bundle/sandbox-macos-permissive-open.sb 890 B
./bundle/sandbox-macos-permissive-proxied.sb 1.31 kB
./bundle/sandbox-macos-restrictive-open.sb 3.36 kB
./bundle/sandbox-macos-restrictive-proxied.sb 3.56 kB
./bundle/sandbox-macos-strict-open.sb 4.82 kB
./bundle/sandbox-macos-strict-proxied.sb 5.02 kB

compressed-size-action

@gemini-cli gemini-cli bot added the 🔒 maintainer only ⛔ Do not contribute. Internal roadmap item. label Feb 25, 2026
Copy link
Collaborator

@abhipatel12 abhipatel12 left a comment

Choose a reason for hiding this comment

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

LGTM

@sehoon38 sehoon38 added this pull request to the merge queue Feb 27, 2026
Merged via the queue into main with commit e709789 Feb 27, 2026
27 checks passed
@sehoon38 sehoon38 deleted the fix-code-assist-optional-fields branch February 27, 2026 17:05
BryanBradfo pushed a commit to BryanBradfo/gemini-cli that referenced this pull request Mar 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🔒 maintainer only ⛔ Do not contribute. Internal roadmap item.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Audit and update all endpoint response types to be optional-safe

2 participants