Skip to content

fix(core): guard message inspectors against empty parts arrays#28068

Open
AriaZhao-coder wants to merge 2 commits into
google-gemini:mainfrom
AriaZhao-coder:fix/message-inspectors-empty-parts
Open

fix(core): guard message inspectors against empty parts arrays#28068
AriaZhao-coder wants to merge 2 commits into
google-gemini:mainfrom
AriaZhao-coder:fix/message-inspectors-empty-parts

Conversation

@AriaZhao-coder

Copy link
Copy Markdown

Summary

isFunctionCall() and isFunctionResponse() in packages/core/src/utils/messageInspectors.ts returned true for messages with an empty parts array, because [].every(...) is vacuously true in JavaScript.

As a result:

  • any role: "model" message with parts: [] was misclassified as a function call, and
  • any role: "user" message with parts: [] was misclassified as a function response.

These helpers are consumed by the routing, loop-detection, and chat subsystems, so the false positives can propagate incorrect behavior across the agent.

Fix

Add a parts.length > 0 guard to both functions so empty-parts messages are correctly treated as neither a function call nor a function response.

content.role === 'user' &&
!!content.parts &&
content.parts.length > 0 &&            // added
content.parts.every((part) => !!part.functionResponse)

Tests

The file previously had no test coverage. Added messageInspectors.test.ts with 12 tests covering both functions: valid calls/responses, wrong role, non-matching parts, mixed parts, undefined parts, and the empty-array regression case.

Verified locally (Node 20):

  • vitest run — new tests pass (12/12); affected callers (routing strategies, loop detection, nextSpeaker) still pass (131/131)
  • prettier --check, eslint --max-warnings 0, tsc --noEmit — all clean

Fixes #23195
Fixes #22912

`isFunctionCall()` and `isFunctionResponse()` in `messageInspectors.ts`
returned `true` for messages with an empty `parts` array, because
`[].every(...)` is vacuously `true` in JavaScript. This misclassified
any `role: "model"` message with `parts: []` as a function call, and any
`role: "user"` message with `parts: []` as a function response, affecting
the routing, loop-detection, and chat subsystems that rely on these
checks.

Add a `parts.length > 0` guard to both functions so empty-parts messages
are correctly treated as neither a function call nor a function response.
Also add the previously missing test coverage for `messageInspectors.ts`.

Fixes google-gemini#23195
Fixes google-gemini#22912
@AriaZhao-coder AriaZhao-coder requested a review from a team as a code owner June 21, 2026 03:46
@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 addresses a logic error in the message inspection utilities where empty parts arrays were causing false positives for function call and response classification. By enforcing a non-empty parts array requirement, the fix ensures more accurate message handling across the agent's subsystems.

Highlights

  • Bug Fix: Added a length check to ensure messages with empty parts arrays are not incorrectly identified as function calls or responses.
  • Test Coverage: Introduced comprehensive unit tests in a new test file to validate function inspector logic and prevent future regressions.
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.

@github-actions github-actions Bot added the size/m A medium sized PR label Jun 21, 2026
@github-actions

github-actions Bot commented Jun 21, 2026

Copy link
Copy Markdown

📊 PR Size: size/M

  • Lines changed: 113
  • Additions: +113
  • Deletions: -0
  • Files changed: 2

@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 updates the isFunctionResponse and isFunctionCall utility functions in packages/core/src/utils/messageInspectors.ts to ensure they return false when the parts array is empty. Additionally, a new test file packages/core/src/utils/messageInspectors.test.ts has been added to thoroughly test these utilities. There are no review comments, and I have no feedback to provide.

@gemini-cli gemini-cli Bot added priority/p2 Important but can be addressed in a future release. area/agent Issues related to Core Agent, Tools, Memory, Sub-Agents, Hooks, Agent Quality labels Jun 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/agent Issues related to Core Agent, Tools, Memory, Sub-Agents, Hooks, Agent Quality priority/p2 Important but can be addressed in a future release. size/m A medium sized PR

Projects

None yet

1 participant