Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions src/google/adk/sessions/database_session_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -607,14 +607,14 @@ async def append_event(self, session: Session, event: Event) -> Event:
StorageSession, (session.app_name, session.user_id, session.id)
)

if storage_session.update_timestamp_tz > session.last_update_time:
raise ValueError(
"The last_update_time provided in the session object"
f" {datetime.fromtimestamp(session.last_update_time):'%Y-%m-%d %H:%M:%S'} is"
" earlier than the update_time in the storage_session"
f" {datetime.fromtimestamp(storage_session.update_timestamp_tz):'%Y-%m-%d %H:%M:%S'}."
" Please check if it is a stale session."
)
# if storage_session.update_timestamp_tz > session.last_update_time:
# raise ValueError(
# "The last_update_time provided in the session object"
# f" {datetime.fromtimestamp(session.last_update_time):'%Y-%m-%d %H:%M:%S'} is"
# " earlier than the update_time in the storage_session"
# f" {datetime.fromtimestamp(storage_session.update_timestamp_tz):'%Y-%m-%d %H:%M:%S'}."
# " Please check if it is a stale session."
# )
Comment on lines +610 to +617

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

Commenting out this optimistic locking check resolves the immediate issue with concurrent requests failing, but it introduces a risk of race conditions and silent data loss. When two requests operate on the same session concurrently, the last one to write will overwrite any state changes made by the other. This could lead to inconsistent session state.

If this check is being removed intentionally, the commented-out code should be deleted rather than left in the source. Leaving dead code can be confusing for future maintenance. It would also be beneficial to add a comment explaining the rationale for removing the check and the accepted concurrency model.

If data consistency is critical, consider alternative concurrency control mechanisms, such as pessimistic locking (e.g., using with_for_update() on the query that fetches storage_session).


# Fetch states from storage
storage_app_state = sql_session.get(StorageAppState, (session.app_name))
Expand Down