Repository navigation
fix(core): avoid duplicate tool response turns when resuming sessions - #29618
Conversation
When reconstructing client history during session resume, convertSessionToClientHistory replays recorded user response turns while also re-synthesizing response turns from toolCalls[].result on preceding model turns. This change: - Checks whether recorded user response turns are already present before synthesizing from toolCalls[].result, retaining fallback synthesis for legacy recordings. - Filters out duplicate functionResponse entries matching the same callId within a single turn. - Adds test coverage for single tool calls, parallel tool calls, legacy formats, and deduplication.
Summary of ChangesHello, 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 an issue where resuming recorded sessions caused duplicate tool response turns. By intelligently checking for existing user-provided responses before synthesizing them from model tool calls and implementing deduplication logic, the history reconstruction process is now more robust and prevents redundant entries. Highlights
Using Gemini Code AssistThe 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
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 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
|
|
📊 PR Size: size/L
|
There was a problem hiding this comment.
Code Review
This pull request updates the convertSessionToClientHistory function in sessionUtils.ts to prevent duplicate tool response turns and deduplicate functionResponse parts in the conversation history. It tracks processed function response IDs using a set and looks ahead at subsequent user messages to avoid synthesizing duplicate tool responses. Unit tests have been updated and added to verify these deduplication behaviors. I have no feedback to provide.
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request enhances convertSessionToClientHistory in packages/core/src/utils/sessionUtils.ts to deduplicate function response IDs and avoid synthesizing duplicate tool response turns when they are already recorded in subsequent user messages. It also adds unit tests to verify these deduplication scenarios. The review feedback suggests utilizing a pendingPartsToAppend map to merge synthesized tool responses into the correct subsequent user turns, preventing consecutive user turns and keeping parallel tool responses grouped together.
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request refactors convertSessionToClientHistory in sessionUtils.ts to deduplicate tool response turns and prevent duplicate tool responses when a recorded user functionResponse turn follows. It also adds comprehensive test cases to verify these behaviors. However, a potential runtime error was identified where msg.content can be undefined or null, which would cause a crash when processing user messages. A fix is recommended to safely handle optional properties.
…sionToClientHistory
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request updates the convertSessionToClientHistory function in packages/core/src/utils/sessionUtils.ts to improve the handling of tool responses and prevent duplication. The changes introduce logic to track and deduplicate function responses, ensuring that tool calls are correctly merged into subsequent user turns instead of creating redundant response turns. Additionally, the test suite in packages/core/src/utils/sessionUtils.test.ts has been expanded with several new test cases to verify these deduplication and merging behaviors, as well as to ensure robust handling of user messages with undefined content. I have no feedback to provide as there were no review comments.
Findings🔴 Critical / High PriorityNone identified. The fix directly solves the duplicate response problem, gracefully repairs already-corrupted historical session files, and preserves full backwards compatibility for legacy recordings. 🟡 Improvements
🟢 Nitpicks
|
… clean up pending map
Summary
Prevent duplicate tool response turn deserialization in
convertSessionToClientHistorywhen resuming recorded sessions.Details
When reconstructing client history during session resume,
convertSessionToClientHistorypreviously replayed recorded userfunctionResponseturns while also synthesizing${msg.id}_responseturns fromtoolCalls[].resulton the preceding model message. This resulted in redundant history synthesis and mismatched pairing alignment betweenfunctionCallandfunctionResponseentries.This change:
functionResponseentries for the model turn'stoolCalls, skipping redundant synthesis while retaining fallback synthesis fromtoolCalls[].resultfor legacy session recordings.functionResponseentries with the sameidwithin a single tool exchange round so existing recordings with duplicated entries deserialize cleanly.packages/core/src/utils/sessionUtils.test.tsfor modern session recordings, legacy session recordings, parallel tool calls, and duplicate entry filtering.Related Issues
Fixes #29365
How to Validate
Run the unit test suite for
sessionUtils:npm test -w @google/gemini-cli-core -- src/utils/sessionUtils.test.tsPre-Merge Checklist