Skip to content

fix(core): preserve functionResponse parts and functionCall metadata when stripping prefixes (#29589) - #29668

Open
goyaladitay11 wants to merge 1 commit into
google-gemini:mainfrom
goyaladitay11:fix/preserve-multimodal-parts-29589
Open

goyaladitay11 wants to merge 1 commit into
google-gemini:mainfrom
goyaladitay11:fix/preserve-multimodal-parts-29589

Conversation

@goyaladitay11

Copy link
Copy Markdown

Summary

Preserves all fields of functionResponse (such as multimodal parts) and functionCall (such as partialArgs and streaming metadata) when stripToolCallIdPrefixes() removes tool name prefixes from IDs.

Details

In packages/core/src/core/geminiChat.ts, stripToolCallIdPrefixes() stripped <toolName>__ prefixes from functionResponse and functionCall IDs by manually reconstructing objects with hardcoded { name, response, id } and { name, args, id } subsets.

When read_file or other tools return multimodal payloads (images, screenshots, inline data), convertToFunctionResponse attaches them to functionResponse.parts if multimodal tool use is supported. Because stripToolCallIdPrefixes() reconstructed newPart.functionResponse without parts, all binary/image content was discarded prior to sending the request to Gemini / Vertex AI, causing models to hallucinate descriptions of unseen images. Similarly, extra fields on functionCall were dropped.

This PR uses object spread (...fr and ...fc) to preserve all existing properties while updating the stripped id.

Related Issues

Closes #29589

How to Validate

Run unit tests:

npx vitest run packages/core/src/core/geminiChat.test.ts -t "stripToolCallIdPrefixes"

Pre-Merge Checklist

  • Added/updated tests (if needed)
  • Validated on required platforms/methods:
    • MacOS
      • npm run

@goyaladitay11
goyaladitay11 requested a review from a team as a code owner October 7, 2026 05:53
@google-cla

google-cla Bot commented Oct 7, 2026

Copy link
Copy Markdown

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 addresses a data loss issue in the Gemini chat integration where stripping tool name prefixes from IDs inadvertently dropped critical fields like multimodal parts and metadata. By switching from manual object reconstruction to object spread, the implementation now safely preserves all original properties, ensuring correct handling of binary data and tool call metadata.

Highlights

  • Data Preservation: Updated the stripToolCallIdPrefixes function to use object spread syntax, ensuring that all existing properties—including multimodal parts and metadata—are preserved when stripping tool name prefixes from IDs.
  • Bug Fix: Resolved an issue where binary content and additional metadata were being discarded during ID processing, which previously caused models to hallucinate descriptions of missing images.
  • Test Coverage: Added a new unit test case to verify that functionResponse parts and functionCall metadata are correctly maintained after the prefix stripping process.
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 Oct 7, 2026
@github-actions

github-actions Bot commented Oct 7, 2026

Copy link
Copy Markdown

📊 PR Size: size/M

  • Lines changed: 64
  • Additions: +60
  • Deletions: -4
  • 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 stripToolCallIdPrefixes function in packages/core/src/core/geminiChat.ts to use the spread operator when copying functionCall and functionResponse objects, ensuring that all additional fields (such as partialArgs and nested parts) are preserved when stripping prefixes. A corresponding unit test has been added to packages/core/src/core/geminiChat.test.ts to verify this behavior. There are no review comments, and I have no feedback to provide.

@gemini-cli gemini-cli Bot added the area/core Issues related to User Interface, OS Support, Core Functionality label Oct 7, 2026
@goyaladitay11

Copy link
Copy Markdown
Author

@googlebot I signed it!

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/core Issues related to User Interface, OS Support, Core Functionality size/m A medium sized PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug(core): stripToolCallIdPrefixes drops functionResponse.parts, so images read with read_file never reach the model

1 participant