Skip to content

Title: DatabaseSessionService.append_event raises stale session error with LongRunningFunctionTool ADK Version #3717

@hungpq-ai

Description

@hungpq-ai

ADK 1.17
When using LongRunningFunctionTool with DatabaseSessionService, the append_event method raises a ValueError about stale session even when timestamps are equal (not earlier). Error:
ValueError: The last_update_time provided in the session object '2025-11-26 04:50:50' is earlier than the update_time in the storage_session '2025-11-26 04:50:50'. Please check if it is a stale session.
Stack trace:
File "google/adk/cli/adk_web_server.py", line 1418, in event_generator
File "google/adk/runners.py", line 655, in _exec_with_plugin
await self.session_service.append_event(
File "google/adk/sessions/database_session_service.py", line 649, in append_event
raise ValueError(...)
Root cause: In database_session_service.py:648, the comparison uses >:
if storage_session.update_timestamp_tz > session.last_update_time:
raise ValueError("stale session...")
But the error message says "earlier than" when timestamps are actually equal. This happens due to floating-point precision issues when multiple events are yielded in quick succession. Steps to reproduce:
Use DatabaseSessionService
Create agent with LongRunningFunctionTool
User triggers the tool (e.g., checkout popup)
Frontend sends functionResponse back
Error occurs when ADK tries to append the response event
Expected behavior: Equal timestamps should not raise stale session error. Suggested fix: Add small tolerance for timestamp comparison or use >= with microsecond precision check.

Metadata

Metadata

Labels

core[Component] This issue is related to the core interface and implementationrequest clarification[Status] The maintainer need clarification or more information from the author

Type

No fields configured for Bug.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions