fix: stabilize function call IDs across streaming events#4732
fix: stabilize function call IDs across streaming events#4732giulio-leone wants to merge 2 commits 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 resolves an issue where function call IDs would inconsistently change between streaming chunks, leading to mismatches between function calls and their corresponding results. The solution introduces a caching mechanism to ensure that function call IDs remain stable throughout a streaming session, thereby preventing data integrity problems and improving the reliability of streaming function call processing. 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
|
|
Response from ADK Triaging Agent Hello @giulio-leone, thank you for your contribution! To help reviewers understand the scope of your testing, could you please add a You can find more details in our contribution guidelines. Thanks! |
There was a problem hiding this comment.
Code Review
This pull request addresses an issue with unstable function call IDs during streaming by introducing a cache to preserve the first-seen ID. The implementation for the non-live streaming path is correct and is accompanied by a comprehensive set of new unit tests. However, the fix appears to be missing for the live streaming path (run_live), which could leave it vulnerable to the same bug. I've also suggested a small refactoring to improve the readability of the caching logic.
c2ed499 to
344a742
Compare
When models don't provide function call IDs, ADK generates client-side IDs via populate_client_function_call_id(). In streaming mode, partial and final events for the same logical function call each get a fresh uuid4, causing an ID mismatch that breaks HITL (human-in-the-loop) workflows and SSE consumers that correlate function calls across chunks. Root cause: _finalize_model_response_event creates a new Event object for each llm_response chunk, and populate_client_function_call_id generates a brand-new ID every time without knowledge of prior IDs. Fix: Add an optional function_call_id_cache dict that maps (name, index) keys to previously generated IDs. The streaming loop in _run_async creates the cache before iteration and threads it through _postprocess_async → _finalize_model_response_event → populate_client_function_call_id, ensuring the same logical function call gets a stable ID across all streaming events. The cache is keyed by (name:index) to correctly handle multiple calls to the same function within a single response. Fixes google#4609
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
344a742 to
c71d31b
Compare
When streaming function calls, the function call ID can change between chunks, causing the tool result to reference a stale ID. This leads to mismatched function call/result pairs.
This PR stabilizes the function call ID by preserving the first-seen ID throughout the streaming session.
Supersedes #4653 (closed due to CLA issue, now resolved).
Co-authored-by: Copilot 223556219+Copilot@users.noreply.github.com