Skip to content

Keep the temp: state keys in the in-memory context session#4501

Open
ashubham wants to merge 3 commits intogoogle:mainfrom
thoughtspot:main
Open

Keep the temp: state keys in the in-memory context session#4501
ashubham wants to merge 3 commits intogoogle:mainfrom
thoughtspot:main

Conversation

@ashubham
Copy link

@ashubham ashubham commented Feb 15, 2026

This enables downstream consumers to read temp: state values when set during invocation start.

Please ensure you have read the contribution guide before creating a pull request.

Link to Issue or Description of Change

1. Link to an existing issue (if applicable):

Problem:
When temp: state values are set during invocation start (run_async), these get stripped out for downstream consumers. Making the utility of these variables marginal as stated in the above issues.

Solution:
Do not strip the temp: keys from the in memory session.state. These are still stripped from the state_delta persisted in the session store.

Testing Plan

Unit Tests:

  • I have added or updated unit tests for my change.
  • All unit tests pass locally.
========================================================================= 4281 passed, 2068 warnings in 50.93s =========================================================================

Manual End-to-End (E2E) Tests:

  • When calling Runner run_async, pass a temp:test state_delta.
  • Read the value of temp:test inside a lifecycle callback like before_agent_callback.
  • See, that the value is the same as passed when calling the runner.

Checklist

  • I have read the CONTRIBUTING.md document.
  • I have performed a self-review of my own code.
  • I have commented my code, particularly in hard-to-understand areas.
  • I have added tests that prove my fix is effective or that my feature works.
  • New and existing unit tests pass locally with my changes.
  • I have manually tested my changes end-to-end.
  • Any dependent changes have been merged and published in downstream modules.

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @ashubham, 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 temp: prefixed state values, when initialized during an invocation, were not available to subsequent operations or callbacks within that same invocation. The changes ensure that these temporary state values are maintained in the in-memory session context for the duration of the current execution, enhancing their utility for transient data, without altering their non-persistent nature in the session store.

Highlights

  • Temporary State Accessibility: Modified the _update_session_state method to no longer filter out state keys prefixed with temp: when updating the in-memory session state. This change ensures that temporary state variables are accessible to downstream consumers and lifecycle callbacks during the same invocation.
  • New Test Coverage: Added a new asynchronous unit test (test_temp_state_accessible_in_callbacks_but_not_persisted) to explicitly verify that temp: state variables are correctly accessible within before_agent_callback and after_agent_callback, while also confirming they are not persisted in the session store or event state_delta.

🧠 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/sessions/base_session_service.py
    • Removed the conditional check that previously prevented state keys prefixed with temp: from being updated in the session's in-memory state.
  • tests/unittests/test_runners.py
    • Added a new asynchronous test test_temp_state_accessible_in_callbacks_but_not_persisted to validate the behavior of temp: state variables.
    • Introduced a StateAccessPlugin within the test to simulate setting and accessing state during before_agent_callback and after_agent_callback.
    • Included assertions to confirm temp:test_key is accessible in callbacks but not persisted in the session or event state_delta.
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.

@adk-bot adk-bot added the services [Component] This issue is related to runtime services, e.g. sessions, memory, artifacts, etc label Feb 15, 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 aims to preserve temporary (temp:) state keys in the in-memory session context, so they can be accessed by downstream consumers during an invocation. The change correctly removes the filtering of temp: keys when updating the session state. I've added a suggestion to simplify the updated code.

I've also identified a potential issue where temp: state passed via run_async(state_delta=...) might still be stripped before updating the in-memory session. The new unit test covers state set via callbacks, but not this initial state-passing scenario. I've left a comment with a suggestion to add a test case for this to ensure the feature is complete.

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 modifies the session handling logic to keep temporary (temp:) state keys in the in-memory session context throughout an invocation. This allows downstream consumers like plugins and callbacks to access these temporary values. The changes ensure that these temporary keys are still stripped before being persisted, preventing them from being stored long-term. The implementation is clean and the logic is sound. The accompanying unit tests are comprehensive and correctly validate the new behavior, including both setting temporary state within a callback and passing it via run_async. My review found a minor improvement opportunity in the new tests to remove unused variables.

@ashubham
Copy link
Author

/gemini review

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 correctly modifies the session handling logic to allow temporary state variables (prefixed with temp:) to be accessible within the in-memory session for the duration of an invocation, without persisting them. The changes in BaseSessionService are logical and improve code clarity by centralizing the filtering of temporary keys. The addition of comprehensive unit tests in test_runners.py effectively validates the new behavior from multiple angles, ensuring that temporary state is available in callbacks but excluded from the persisted session and event history. The implementation is clean and the tests are thorough. Great work!

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

Labels

services [Component] This issue is related to runtime services, e.g. sessions, memory, artifacts, etc

Projects

None yet

2 participants