fix: prevent state_delta overwrite on function_response-only events#4642
fix: prevent state_delta overwrite on function_response-only events#4642yuvrajangadsingh wants to merge 1 commit intogoogle:mainfrom
Conversation
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 a bug where the Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Changelog
Activity
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 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 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
|
There was a problem hiding this comment.
Code Review
This pull request effectively addresses a bug where state_delta was being overwritten by an empty string in __maybe_save_output_to_state for function-response-only events with skip_summarization=True. The added elif not result: condition correctly prevents this unintended behavior. The new test case test_maybe_save_output_to_state_skips_function_response_only_event thoroughly validates the fix, ensuring the callback-set values are preserved. The changes are well-implemented and improve the robustness of the agent's state management.
|
Hi @yuvrajangadsingh , Thank you for your contribution! We appreciate you taking the time to submit this pull request. Your PR has been received by the team and is currently under review. We will provide feedback as soon as we have an update to share. |
|
Hi @xuanyang15 , can you please review this. |
When skip_summarization is True and an event only contains function_response parts (no text), __maybe_save_output_to_state would join zero text parts into an empty string and overwrite the state_delta value already set by after_tool_callback. Skip writing to state_delta when result is empty and no output_schema is configured. Fixes google#3178
fe595fd to
6db186d
Compare
Fixes #3178
When
skip_summarization=Trueand an event only hasfunction_responseparts (no text),__maybe_save_output_to_statejoins zero text parts into""and overwrites whatever theafter_tool_callbackalready set instate_delta.Root cause:
is_final_response()returnsTrueforskip_summarizationevents, so the method enters the save block. But there are no text parts to extract, soresult = "". Withoutoutput_schema, the empty string gets written directly tostate_delta[output_key], clobbering the callback's value.Fix: skip writing to
state_deltawhenresultis empty and nooutput_schemais configured. This preserves callback-set values on function_response-only events while keeping existing behavior for text-based responses unchanged.Testing: added a test that sets
state_deltavia callback on a function_response-only event withskip_summarization=True, then verifies the value isn't overwritten. All 406 agent tests pass.