runner: prevent duplicate user-event append on invocation retry#4526
runner: prevent duplicate user-event append on invocation retry#4526davidahmann wants to merge 3 commits intogoogle:maingoogle/adk-python:mainfrom davidahmann:codex/issue-4506-idempotency-keydavidahmann/adk-python:codex/issue-4506-idempotency-keyCopy head branch name to clipboard
Conversation
Summary of ChangesHello @davidahmann, 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 invocation retries could lead to duplicate user events being recorded in the session history, compromising the integrity of replays and audits. The changes introduce a mechanism to detect and prevent these duplicate appends, ensuring that each unique user interaction is logged only once, even across retried invocations. 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
|
|
Implemented retry idempotency guard for runner user-event append behavior.
This contribution was informed by patterns from Gait: https://github.com/Clyra-AI/gait |
There was a problem hiding this comment.
Code Review
This pull request effectively prevents duplicate user events during invocation retries by introducing a check before appending new messages to the session. The implementation is clear and is accompanied by thorough unit tests that cover various scenarios, including handling of state_delta. The changes look good. I have one suggestion to optimize the performance of the duplicate detection logic.
| state_delta: Optional[dict[str, Any]], | ||
| ) -> bool: | ||
| expected_state_delta = state_delta or {} | ||
| for event in session.events: |
There was a problem hiding this comment.
For better performance, especially in sessions with a long history, it's advisable to search for duplicates starting from the end of the event list. A duplicate event from a retry is likely to be recent, so iterating in reverse will find it more quickly.
| for event in session.events: | |
| for event in reversed(session.events): |
Problem
Invocation retries can duplicate user events in persisted session history, which undermines replay/audit trust.
Why now
Issue #4506 reports active duplicate append behavior in retry paths.
What changed
state_deltapath with targeted tests.Validation
./autoformat.sh(pyink missing locally; formatter step skipped by tool script with explicit message)uv run pytest tests/unittests/test_runners.py -k 'duplicate or retry or state_delta'Refs #4506