Skip to content

tests: assert post-run session state from refetched snapshot#4550

Open
davidahmann wants to merge 5 commits intogoogle:mainfrom
davidahmann:codex/issue-4547-session-refetch
Open

tests: assert post-run session state from refetched snapshot#4550
davidahmann wants to merge 5 commits intogoogle:mainfrom
davidahmann:codex/issue-4547-session-refetch

Conversation

@davidahmann
Copy link

Problem

Post-run_async assertions can read stale state if tests inspect a previously held in-memory session object.

Why now

This stale-snapshot pattern causes flaky or misleading assertions around event persistence.

What changed

  • Added regression test test_run_async_assertions_use_refetched_session_snapshot in tests/unittests/test_runners.py.
  • Test documents stale original handle and verifies fresh get_session(...) for authoritative assertions.

Validation

  • uv run pytest tests/unittests/test_runners.py -k refetched_session_snapshot -q (pass)

Refs #4547

@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 addresses a potential source of flakiness in tests where assertions made after an asynchronous run_async operation might inspect a stale in-memory session object. By introducing a new regression test, it highlights the necessity of explicitly refetching the session state to ensure that subsequent assertions reflect the actual, updated state of the system, thereby improving the reliability of event persistence tests.

Highlights

  • Regression Test Added: A new regression test, test_run_async_assertions_use_refetched_session_snapshot, was added to tests/unittests/test_runners.py to address issues with stale session states.
  • Stale Session Handling: The new test demonstrates the importance of refetching the session snapshot after run_async operations to ensure assertions are made against the most current state, preventing flaky or misleading test results.

🧠 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
  • tests/unittests/test_runners.py
    • Added a new asynchronous test case to validate session state after run_async calls.
Activity
  • A new regression test was added to address a potential issue with stale session states.
  • The new test was validated locally using 'uv run pytest tests/unittests/test_runners.py -k refetched_session_snapshot -q', confirming it passes.
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 the issue-scoped change with targeted regression coverage and validation:

  • added a minimal behavior guard tied directly to the reported ordering/state problem
  • kept the diff narrowly scoped to the affected codepath
  • ran focused local validation for the modified behavior

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 19, 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 adds a valuable regression test to ensure that assertions made after running an agent use a refetched session snapshot, correctly addressing potential issues with stale in-memory state. The test is well-structured and clearly demonstrates the intended behavior. My feedback includes a suggestion to improve the way the asynchronous generator is consumed for better memory efficiency.

Comment on lines 692 to 699
_ = [
event
async for event in runner.run_async(
user_id=TEST_USER_ID,
session_id=TEST_SESSION_ID,
new_message=types.Content(role="user", parts=[types.Part(text="hi")]),
)
]
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

Using a list comprehension to exhaust the run_async generator creates a list in memory that is immediately discarded. This is slightly inefficient as it allocates memory for all events from the generator. A more idiomatic and memory-efficient approach for consuming an async generator when the results are not needed is to use a simple async for loop.

  async for _ in runner.run_async(
      user_id=TEST_USER_ID,
      session_id=TEST_SESSION_ID,
      new_message=types.Content(role="user", parts=[types.Part(text="hi")]),
  ):
      pass

@ryanaiagent ryanaiagent self-assigned this Feb 19, 2026
@ryanaiagent ryanaiagent added the needs review [Status] The PR/issue is awaiting review from the maintainer label Feb 19, 2026
@ryanaiagent
Copy link
Collaborator

Hi @davidahmann, 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.

@ryanaiagent
Copy link
Collaborator

Hi @Jacksunwei , can you please review this. LGTM

GWeale and others added 3 commits February 20, 2026 07:43
Co-authored-by: George Weale <gweale@google.com>
PiperOrigin-RevId: 872503435
This change allows `add_memory` to use the `memories.generate` API with `direct_memories_source` when `custom_metadata["enable_consolidation"]` is set to True. This enables server-side consolidation of the provided memories

Co-authored-by: George Weale <gweale@google.com>
PiperOrigin-RevId: 872554004
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 needs review [Status] The PR/issue is awaiting review from the maintainer

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants

Comments