tests: assert post-run session state from refetched snapshot#4550
tests: assert post-run session state from refetched snapshot#4550davidahmann wants to merge 5 commits intogoogle:mainfrom
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 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
🧠 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 the issue-scoped change with targeted regression coverage and validation:
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 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.
tests/unittests/test_runners.py
Outdated
| _ = [ | ||
| 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")]), | ||
| ) | ||
| ] |
There was a problem hiding this comment.
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|
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. |
|
Hi @Jacksunwei , can you please review this. LGTM |
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
Problem
Post-
run_asyncassertions 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
test_run_async_assertions_use_refetched_session_snapshotintests/unittests/test_runners.py.get_session(...)for authoritative assertions.Validation
uv run pytest tests/unittests/test_runners.py -k refetched_session_snapshot -q(pass)Refs #4547