Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

runner: prevent duplicate user-event append on invocation retry#4526

Open
davidahmann 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
Open

runner: prevent duplicate user-event append on invocation retry#4526
davidahmann 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

@davidahmann
Copy link

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

  • Added duplicate-append guard for resumed/retried invocations in runner message handling.
  • Covered duplicate behavior including state_delta path 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

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @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

  • Duplicate User Events Prevention: Implemented a guard to prevent duplicate user events from being appended to session history during invocation retries, addressing an issue where replay/audit trust was undermined.
  • New Duplicate Check Logic: Introduced a new private method, _has_duplicate_user_event_for_invocation, to identify and skip previously recorded user events based on invocation ID, content, and state delta.
  • Comprehensive Test Coverage: Added targeted unit tests to validate the duplicate-append guard's behavior, including scenarios for retry messages, non-duplicate messages, and state delta deduping.

🧠 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
  • src/google/adk/runners.py
    • Added a new private method _has_duplicate_user_event_for_invocation to check for existing user events with the same invocation ID, content, and state delta.
    • Integrated the duplicate check into _append_new_message_to_session to prevent re-appending identical user events during retries.
  • tests/unittests/test_runners.py
    • Added test_append_new_message_to_session_skips_duplicate_retry_message to confirm that identical user messages from the same invocation are not duplicated.
    • Added test_append_new_message_to_session_keeps_non_duplicate_messages to verify that distinct user messages are correctly appended.
    • Added test_append_new_message_to_session_state_delta_deduping to test the duplicate prevention logic when state_delta is involved.
Activity
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.

@davidahmann
Copy link
Author

Implemented retry idempotency guard for runner user-event append behavior.

  • Added duplicate detection to avoid appending the same user event on retry/resume for the same invocation.
  • Added focused tests including the state_delta path.
  • Validation: targeted runner tests passed; ./autoformat.sh reported missing pyink in this local environment.

This contribution was informed by patterns from Gait: https://github.com/Clyra-AI/gait

@adk-bot adk-bot added the core [Component] This issue is related to the core interface and implementation label Feb 18, 2026
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 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:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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.

Suggested change
for event in session.events:
for event in reversed(session.events):

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core [Component] This issue is related to the core interface and implementation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

Comments

Close sidebar
Morty Proxy This is a proxified and sanitized view of the page, visit original site.