Skip to content

fix(core): sanitize function_response.parts before compression - #19856

Closed
Aarchi-07 wants to merge 5 commits into
google-gemini:mainfrom
Aarchi-07:fixing-function-part-inline-data-compression-failure
Closed

fix(core): sanitize function_response.parts before compression#19856
Aarchi-07 wants to merge 5 commits into
google-gemini:mainfrom
Aarchi-07:fixing-function-part-inline-data-compression-failure

Conversation

@Aarchi-07

@Aarchi-07 Aarchi-07 commented Feb 21, 2026

Copy link
Copy Markdown
Contributor

Summary

Gemini 3 models support nesting multimodal data (inlineData) inside function_response.parts at runtime. When chat history compression triggers, it sends this raw history to a summarizer model that may not support this Gemini-3-specific feature, causing the API to reject the request with:

"function_response.parts is not supported for this model"

Once this happens, every subsequent turn also triggers auto-compression with the same corrupted history, permanently breaking the session.

Changes

  • Added [sanitizeHistoryForSummarizer()] in chatCompressionService.ts that strips the nested function_response.parts field before passing history to the summarizer
  • Applied to both generateContent calls (initial summary + verification)
  • Added regression test in chatCompressionService.test.ts

Pre-Merge Checklist

  • Updated relevant documentation and README (if needed)
  • Added/updated tests (if needed)
  • Noted breaking changes: No breaking changed made
  • Validated on required platforms/methods:
    • Windows
      • npm run
      • npx
      • Docker

Fixes #19853

@Aarchi-07
Aarchi-07 requested a review from a team as a code owner February 21, 2026 20:41
@gemini-code-assist

Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @Aarchi-07, 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 critical issue where Gemini 3 multimodal data, specifically inlineData nested within function_response.parts, could cause chat history compression to fail. By sanitizing the chat history to remove this Gemini-3-specific field before it reaches the summarizer model, the change prevents API rejections and ensures continuous chat sessions, improving the robustness of the chat compression service.

Highlights

  • Chat History Sanitization: Introduced a new utility function, sanitizeHistoryForSummarizer(), to strip Gemini-3-specific multimodal data (function_response.parts) from chat history entries before they are sent to the summarizer model.
  • Compression Logic Integration: Applied the sanitizeHistoryForSummarizer() function to both generateContent calls within the chat compression service, ensuring that the summarizer model receives a compatible history format during initial summary generation and verification.
  • Regression Test: Added a comprehensive regression test case to chatCompressionService.test.ts to validate that the nested function_response.parts field is correctly removed while preserving other functionResponse properties.
Changelog
  • packages/core/src/services/chatCompressionService.test.ts
    • Added a new test case to verify the stripping of Gemini 3 multimodal data from function_response.parts during summarization.
  • packages/core/src/services/chatCompressionService.ts
    • Added sanitizeHistoryForSummarizer function to remove Gemini-3-specific function_response.parts from chat history.
    • Applied sanitizeHistoryForSummarizer to generateContent calls for initial summary generation.
    • Applied sanitizeHistoryForSummarizer to generateContent calls for summary verification.
Activity
  • Updated relevant documentation and README (if needed).
  • Added/updated tests (if needed).
  • Confirmed no breaking changes were made.
  • Validated on Windows using npm run and npx.
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.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

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-cli gemini-cli Bot added the area/agent Issues related to Core Agent, Tools, Memory, Sub-Agents, Hooks, Agent Quality label Feb 21, 2026

@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 correctly addresses the issue where Gemini 3 specific multimodal data in tool responses causes the summarizer model to fail. By stripping the nested parts field from function_response before sending history to the summarizer, it prevents session-breaking errors. I've suggested a few improvements to the sanitization logic to ensure type safety, adhere to object construction best practices, and avoid redundant processing of large chat histories.

Comment thread packages/core/src/services/chatCompressionService.ts
Comment thread packages/core/src/services/chatCompressionService.ts Outdated
Comment thread packages/core/src/services/chatCompressionService.ts Outdated
@gemini-cli

gemini-cli Bot commented Mar 15, 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 size/m A medium sized PR

Projects

None yet

2 participants