Session storage error #4931
Replies: 2 comments
-
|
Response from ADK Answering Agent (experimental, answer may be inaccurate) TLDR: This error is a safeguard to prevent stale session data from overwriting newer data in the database. This can happen in environments with multiple application instances, like Cloud Run. To fix this, you should refetch the session from the Hi Mauricio, This is a great question. The Why is this happening?The error message "The last_update_time provided in the session object ... is earlier than the update_time in the storage_session" indicates that the session object your code is trying to use is "stale." Here’s a likely scenario:
How to fix itTo prevent this, you should not hold onto session objects for long periods or across different requests. Instead, adopt a pattern of fetching the latest session state from the database at the beginning of any operation that might modify it. You can do this by calling Here is an example of how you can get the latest session before using it: # Before performing an action, always get the latest session state
session = await session_service.get_session(
app_name=APP_NAME,
user_id=user_id,
session_id=session_id
)
# Now you can safely append an event or perform other actions
# with the up-to-date session object.By following this pattern, you ensure that your application is resilient to the dynamic scaling and concurrent processing inherent to Cloud Run. For more details on session management, you can refer to the ADK documentation. [1][2] [1] https://google.github.io/adk-docs/streaming/dev-guide/part1/ |
Beta Was this translation helpful? Give feedback.
-
|
This is a stale session write, not a Postgres bug. On Cloud Run it usually means two requests updated the same session close together, so the fix is to reload the session before each write and serialize writes per session id. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi everyone,
I have seen this error entry in my Cloud Run logs:
File "/app/.venv/lib/python3.12/site-packages/google/adk/sessions/database_session_service.py", line 437, in append_event
raise ValueError(
ValueError: The last_update_time provided in the session object '2026-03-20 14:59:14' is earlier than the update_time in the storage_session '2026-03-20 14:59:30'. Please check if it is a stale session.
We are using PostgreSQL as the database for the ADK database.
Any help would be really appreciated.
Thank you
Mauricio
Beta Was this translation helpful? Give feedback.
All reactions