Skip to content

fix(core): guard isFunctionCall/isFunctionResponse against empty parts#27527

Open
amitesh0303 wants to merge 1 commit into
google-gemini:mainfrom
amitesh0303:fix/empty-parts-vacuous-truth-v2
Open

fix(core): guard isFunctionCall/isFunctionResponse against empty parts#27527
amitesh0303 wants to merge 1 commit into
google-gemini:mainfrom
amitesh0303:fix/empty-parts-vacuous-truth-v2

Conversation

@amitesh0303
Copy link
Copy Markdown

Summary

Details

Related Issues

How to Validate

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

@amitesh0303 amitesh0303 requested a review from a team as a code owner May 28, 2026 12:23
@google-cla
Copy link
Copy Markdown

google-cla Bot commented May 28, 2026

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.

@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 improves the reliability of message inspection utilities by adding explicit length checks to function call and response validation. By ensuring that message parts are not empty, the code avoids potential logical errors where an empty array would otherwise return true, while also introducing safer property access patterns.

Highlights

  • Added length validation: Updated isFunctionResponse and isFunctionCall to ensure content.parts has at least one element, preventing vacuous truth issues with Array.every.
  • Improved safety: Added optional chaining to part access within the every callback to ensure robust handling of message parts.
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.

Copy link
Copy Markdown
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 updates the isFunctionResponse and isFunctionCall helper functions in messageInspectors.ts to avoid vacuous truth on empty arrays by ensuring parts.length > 0, and adds optional chaining for safety. Feedback suggests using Array.prototype.some instead of every for identifying function calls, as Gemini 2.0 models often return other parts (such as thoughts) alongside function calls in the same turn.

Comment on lines +30 to +31
content.parts.length > 0 &&
content.parts.every((part) => !!part?.functionCall)
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.

high

Gemini 2.0 models (such as Gemini 2.0 Flash/Pro) frequently return thought parts (part.thought) alongside functionCall parts in the same model turn. Using Array.prototype.every will cause isFunctionCall to return false if any thought parts (or text parts) are present, which can prevent tool execution. Changing this to Array.prototype.some ensures that any model response containing at least one function call is correctly identified, and it also naturally avoids vacuous truth for empty arrays without needing an explicit length check.

    content.parts.some((part) => !!part?.functionCall)

@gemini-cli gemini-cli Bot added the priority/p1 Important and should be addressed in the near term. label May 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

priority/p1 Important and should be addressed in the near term.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants