Skip to content

fix(core): strip functionResponse.id before sending to API - #22957

Closed
mianmian7 wants to merge 4 commits into
google-gemini:mainfrom
mianmian7:fix/remove-id-from-function-response
Closed

mianmian7 wants to merge 4 commits into
google-gemini:mainfrom
mianmian7:fix/remove-id-from-function-response

Conversation

@mianmian7

Copy link
Copy Markdown

Summary

  • strip functionResponse.id from request contents before sending them to the Gemini API
  • keep internal functionResponse.id call tracking intact by sanitizing only at the API boundary
  • add regression tests covering stripping, no-op cases, multiple function responses, and empty input

Test Plan

  • npm run build
  • npm run lint
  • npm run test --workspace @google/gemini-cli-core -- src/core/geminiChat.test.ts

Fixes #13972
Fixes #22183

@mianmian7
mianmian7 requested a review from a team as a code owner March 18, 2026 17:17
@google-cla

google-cla Bot commented Mar 18, 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 resolves an issue where the functionResponse.id field, used internally for tracking function calls, was erroneously included in requests sent to the Gemini API, leading to INVALID_ARGUMENT errors. The core change introduces a sanitization step at the API boundary to remove this internal id field from the request payload, ensuring compatibility with the API while preserving the integrity of internal call tracking mechanisms. This enhancement improves the robustness and reliability of API interactions.

Highlights

  • API Request Sanitization: Implemented a new utility function, sanitizeContentsForApi, to strip the id field from functionResponse parts before sending requests to the Gemini API, resolving INVALID_ARGUMENT errors.
  • Internal Tracking Preservation: Ensured that the internal functionResponse.id call tracking remains intact by applying the sanitization only at the API boundary.
  • Regression Testing: Added comprehensive regression tests for the sanitizeContentsForApi function, covering cases like stripping IDs, no-op scenarios, multiple function responses, and empty input.
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.

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. ↩

@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

The pull request introduces a sanitizeContentsForApi utility function to remove the internal id field from functionResponse parts within Content objects before sending them to the Gemini API, resolving INVALID_ARGUMENT errors caused by the v1 API not accepting this field. The generateContentStream method now uses this function for content sanitization. Unit tests for sanitizeContentsForApi have been added, covering various scenarios including stripping the id and ensuring non-mutation of other content parts. The reviewer suggests adding a comment to the sanitizeContentsForApi function explaining its expected behavior and performance implications.

Note: Security Review did not run due to the size of the PR.

Comment thread packages/core/src/core/geminiChat.ts Resolved
@gemini-cli gemini-cli Bot added priority/p1 Important and should be addressed in the near term. area/agent Issues related to Core Agent, Tools, Memory, Sub-Agents, Hooks, Agent Quality labels Mar 18, 2026
@gemini-cli

gemini-cli Bot commented Apr 2, 2026

Copy link
Copy Markdown
Contributor

Hi there! Thank you for your interest in contributing to Gemini CLI.

To ensure we maintain high code quality and focus on our prioritized roadmap, we have updated our contribution policy (see Discussion #17383).

We only guarantee review and consideration of pull requests for issues that are explicitly labeled as 'help wanted'. All other community pull requests are subject to closure after 14 days if they do not align with our current focus areas. For this reason, we strongly recommend that contributors only submit pull requests against issues explicitly labeled as 'help-wanted'.

This pull request is being closed as it has been open for 14 days without a 'help wanted' designation. We encourage you to find and contribute to existing 'help wanted' issues in our backlog! Thank you for your understanding and for being part of our community!

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/p1 Important and should be addressed in the near term. size/m A medium sized PR

Projects

None yet

2 participants