Skip to content

Conversation

@abhipatel12
Copy link
Collaborator

Summary

This PR implements history synchronization for observation masking, ensuring that masked tool outputs are tracked, persisted to session files, and correctly resumed.

Details

  • Tracking & Persistence: Implemented GeminiChat.setHistory to persist the message history to disk whenever it is updated. This ensures that any masked content (stored in memory) is mirrored in the session history file.
  • Manual Masking Updates: Enhanced ChatRecordingService to correctly synchronize in-memory history when manual masking updates occur.
  • Trajectory Fix: Fixed a bug where masked tool outputs were resumed as plain text parts. They are now correctly resumed as functionResponse parts, which preserves the model's tool-use trajectory and multi-modal content (like images).
  • Multi-modal Support: Verified that existing multi-modal data (inlineData) within tool results is preserved when a response is updated/masked.

Related Issues

Phase 2 of Observation Masking (History Synchronization).

How to Validate

  1. Run npm run test -w @google/gemini-cli-core -- src/services/chatRecordingService.test.ts to verify persistence and multi-modal preservation.
  2. Run npm run preflight to ensure no regressions.
  3. Manually verify by masking a tool output and checking that the .json session history file reflects the masked state and can be resumed correctly.

Pre-Merge Checklist

  • Updated relevant documentation and README (if needed)
  • Added/updated tests (if needed)
  • Noted breaking changes (if any)
  • Validated on required platforms/methods:
    • MacOS
      • npm run
      • npx
      • Docker
      • Podman
      • Seatbelt

This PR enables the synchronization of masked tool outputs to the session
history, ensuring that automatic and manual masking updates are persisted
to disk and correctly resumed in future sessions. It also fixes a bug
where masked outputs were resumed as plain text parts, breaking the
tool-use trajectory and stripping multi-modal data.
@abhipatel12 abhipatel12 requested a review from a team as a code owner February 6, 2026 18:07
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @abhipatel12, 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 significantly improves the robustness of the chat recording service by implementing comprehensive persistence and resumption for masked tool outputs. It addresses critical synchronization issues, ensuring that the full history, including sensitive masked data and multi-modal content, is accurately saved to and loaded from session files, thereby maintaining the integrity of the conversation trajectory.

Highlights

  • History Synchronization for Masked Tool Outputs: Ensures that changes to tool outputs, especially masking, are consistently tracked and synchronized with the session history.
  • Persistence to Session Files: Masked tool outputs are now correctly persisted to disk within session files, allowing for accurate state restoration.
  • Correct Resumption of Tool Outputs: Fixes a bug where masked tool outputs were resumed as plain text; they are now correctly restored as 'functionResponse' parts, preserving the model's tool-use trajectory.
  • Multi-modal Content Preservation: Guarantees that existing multi-modal data (like images) within tool results remains intact when responses are updated or masked.
Changelog
  • packages/core/src/core/geminiChat.ts
    • Integrated 'chatRecordingService.updateMessagesFromHistory(history)' call within the 'setHistory' method to ensure the chat recording service is notified of history updates, facilitating persistence of masked content.
  • packages/core/src/services/chatRecordingService.test.ts
    • Added a new test suite for 'updateMessagesFromHistory' to validate correct synchronization of masked tool results from API history to disk.
    • Included a test case to specifically verify the preservation of multi-modal sibling parts during history synchronization.
  • packages/core/src/services/chatRecordingService.ts
    • Imported 'Content' and 'Part' types from '@google/genai'.
    • Introduced a new public method 'updateMessagesFromHistory(history: Content[])' responsible for updating the conversation record on disk. This method parses the provided API history to identify and correctly store masked 'functionResponse' parts and their associated multi-modal data, ensuring proper trajectory reconstruction upon resumption.
Activity
  • Implemented history synchronization for observation masking.
  • Ensured masked tool outputs are tracked, persisted to session files, and correctly resumed.
  • Fixed a bug where masked tool outputs were resumed as plain text parts, now correctly resuming them as 'functionResponse' parts.
  • Verified that existing multi-modal data within tool results is preserved when a response is updated/masked.
  • Added/updated tests to cover the new functionality and ensure no regressions.
  • Updated relevant documentation and README.
  • Validated changes on MacOS.
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.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

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 effectively implements history synchronization for masked tool outputs, ensuring they are persisted and resumed correctly. The changes are well-structured and include relevant tests. I've identified one critical issue in the history processing logic that could lead to data loss if API response parts are not ordered as expected. My feedback includes a code suggestion to make this logic more robust.

@github-actions
Copy link

github-actions bot commented Feb 6, 2026

Size Change: +1.82 kB (+0.01%)

Total Size: 23.8 MB

Filename Size Change
./bundle/gemini.js 23.8 MB +1.82 kB (+0.01%)
ℹ️ View Unchanged
Filename Size
./bundle/sandbox-macos-permissive-closed.sb 1.03 kB
./bundle/sandbox-macos-permissive-open.sb 890 B
./bundle/sandbox-macos-permissive-proxied.sb 1.31 kB
./bundle/sandbox-macos-restrictive-closed.sb 3.29 kB
./bundle/sandbox-macos-restrictive-open.sb 3.36 kB
./bundle/sandbox-macos-restrictive-proxied.sb 3.56 kB

compressed-size-action

@gemini-cli gemini-cli bot added the status/need-issue Pull requests that need to have an associated issue. label Feb 6, 2026
@abhipatel12 abhipatel12 enabled auto-merge February 6, 2026 21:10
@abhipatel12 abhipatel12 added this pull request to the merge queue Feb 6, 2026
Merged via the queue into main with commit 63f7e30 Feb 6, 2026
26 checks passed
@abhipatel12 abhipatel12 deleted the abhi/masking-phase-2 branch February 6, 2026 21:30
aswinashok44 pushed a commit to aswinashok44/gemini-cli that referenced this pull request Feb 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

status/need-issue Pull requests that need to have an associated issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants