Skip to content

fix: make temp: state keys accessible in session.state during invocation#5387

Closed
miyannishar wants to merge 1 commit intogoogle:mainfrom
miyannishar:fix/temp-state-in-callbacks
Closed

fix: make temp: state keys accessible in session.state during invocation#5387
miyannishar wants to merge 1 commit intogoogle:mainfrom
miyannishar:fix/temp-state-in-callbacks

Conversation

@miyannishar
Copy link
Copy Markdown

@miyannishar miyannishar commented Apr 19, 2026

Summary

Fixes #3047

temp: prefixed state keys were being dropped from session.state before lifecycle callbacks (after_agent_callback, after_tool_callback, etc.) could access them.

Closing

This PR is now redundant — the fix was already merged via #4501 which introduced _apply_temp_state and _trim_temp_delta_state in base_session_service.py. The upstream main branch already contains the fix and regression tests.

Closing in favor of #4501.

Fixes google#3047

temp: prefixed state keys (e.g. set via output_key='temp:...') were
being dropped from session.state before lifecycle callbacks could
read them.

Root cause: BaseSessionService.__update_session_state() explicitly
skipped keys starting with 'temp:', preventing them from ever
reaching session.state.

Changes:
- base_session_service.py: Remove the temp: skip in
  __update_session_state() so all keys flow into the in-memory
  session.state.
- in_memory_session_service.py: Strip temp: keys from
  event.actions.state_delta after updating the caller's session but
  before writing to the storage session, preventing temp keys from
  leaking into persisted state.
- test_session_service.py: Update existing tests to reflect that
  temp: keys are now accessible in-memory, and add a dedicated
  regression test.

Temp keys remain non-persistent:
- DatabaseSessionService uses _extract_state_delta() which already
  filters temp: keys before writing to the database.
- InMemorySessionService now strips temp: keys before updating
  shared state stores and the storage session.
- Runner creates a deepcopy of session at invocation start,
  preventing temp keys from leaking across invocations.
@google-cla
Copy link
Copy Markdown

google-cla bot commented Apr 19, 2026

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@adk-bot adk-bot added the services [Component] This issue is related to runtime services, e.g. sessions, memory, artifacts, etc label Apr 19, 2026
@adk-bot
Copy link
Copy Markdown
Collaborator

adk-bot commented Apr 19, 2026

Response from ADK Triaging Agent

Hello @miyannishar, thank you for creating this PR!

Could you please add a testing plan section in your PR to describe how you tested your changes? This will help reviewers to review your PR more efficiently.

Thanks!

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

Development

Successfully merging this pull request may close these issues.

Temp prefixed state key not available on after_agent_callback

2 participants