Skip to content

Comments

tests(runners): require fresh session fetch for persisted event counts#4596

Open
davidahmann wants to merge 1 commit intogoogle:mainfrom
davidahmann:codex/issue-4595-deterministic-event-count
Open

tests(runners): require fresh session fetch for persisted event counts#4596
davidahmann wants to merge 1 commit intogoogle:mainfrom
davidahmann:codex/issue-4595-deterministic-event-count

Conversation

@davidahmann
Copy link

Problem

Persisted-event assertions can drift when tests rely on stale session snapshots after run_async invocations.

Why now

This is active operator friction in current workflows and needs deterministic behavior for repeatable triage/replay.

What changed

Added a regression test that demonstrates stale snapshot behavior and asserts counts using a freshly fetched persisted session.

Validation

  • .venv/bin/pytest tests/unittests/runners/test_persisted_event_counts.py -q (pass)

Refs #4595

@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 critical issue where assertions on persisted event counts could become unreliable due to tests relying on outdated session data after asynchronous operations. By introducing a dedicated regression test, it ensures that future validations of event counts are performed against the most current session state, thereby improving the determinism and reliability of test results and operational workflows.

Highlights

  • Regression Test Added: A new regression test was added to demonstrate and prevent issues with stale session snapshots affecting persisted event counts after asynchronous operations.
  • Fresh Session Fetch Enforcement: The test specifically asserts that persisted event counts must be validated against a freshly fetched session to ensure accuracy, addressing a known friction point in workflows.

🧠 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/runners/test_persisted_event_counts.py
    • Added a new test file to include a regression test for run_async event count consistency.
    • Implemented test_run_async_event_counts_require_fresh_session_fetch to verify that persisted event counts are accurate only when retrieved from a fresh session fetch.
Activity
  • No human activity has been recorded on this pull request yet.
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

Added a regression test that demonstrates stale session snapshots after run_async and enforces persisted-event assertions against a freshly fetched session state.

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

@adk-bot adk-bot added the core [Component] This issue is related to the core interface and implementation label Feb 23, 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 persisted event counts are asserted against a freshly fetched session, addressing potential issues with stale data. The test is well-written and effectively demonstrates the intended behavior. I have one suggestion to refactor a small part of the test to improve code clarity and reduce duplication.

Comment on lines +33 to +51
stale_session = await runner.runner.session_service.get_session(
app_name=runner.app_name,
user_id="test_user",
session_id=runner.session_id,
)
assert stale_session is not None

second_invocation_events = await runner.run_async("hello again")

# This session snapshot was retrieved before the second invocation and should
# not be used for final persisted-event assertions.
stale_count = len(stale_session.events)
fresh_session = await runner.runner.session_service.get_session(
app_name=runner.app_name,
user_id="test_user",
session_id=runner.session_id,
)
assert fresh_session is not None
fresh_count = len(fresh_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

To improve readability and reduce code duplication, the session fetching logic can be extracted into a local helper function. This makes the test's intent clearer and the code easier to maintain.

Suggested change
stale_session = await runner.runner.session_service.get_session(
app_name=runner.app_name,
user_id="test_user",
session_id=runner.session_id,
)
assert stale_session is not None
second_invocation_events = await runner.run_async("hello again")
# This session snapshot was retrieved before the second invocation and should
# not be used for final persisted-event assertions.
stale_count = len(stale_session.events)
fresh_session = await runner.runner.session_service.get_session(
app_name=runner.app_name,
user_id="test_user",
session_id=runner.session_id,
)
assert fresh_session is not None
fresh_count = len(fresh_session.events)
async def _fetch_session():
session = await runner.runner.session_service.get_session(
app_name=runner.app_name,
user_id="test_user",
session_id=runner.session_id,
)
assert session is not None
return session
stale_session = await _fetch_session()
second_invocation_events = await runner.run_async("hello again")
# This session snapshot was retrieved before the second invocation and should
# not be used for final persisted-event assertions.
stale_count = len(stale_session.events)
fresh_session = await _fetch_session()
fresh_count = len(fresh_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