fix(core): guard isFunctionCall/isFunctionResponse against empty parts#27527
fix(core): guard isFunctionCall/isFunctionResponse against empty parts#27527amitesh0303 wants to merge 1 commit into
Conversation
|
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. |
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 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
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
|
There was a problem hiding this comment.
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.
| content.parts.length > 0 && | ||
| content.parts.every((part) => !!part?.functionCall) |
There was a problem hiding this comment.
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)
Summary
Details
Related Issues
How to Validate
Pre-Merge Checklist