-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Description
Describe the bug
When using DatabaseSessionService with PostgreSQL as a persistent database for session storage, error messages that exceed the database column length limit (VARCHAR(1024)) cause a StringDataRightTruncation error. Instead of gracefully handling this error, the entire agent execution crashes, preventing proper error reporting and potentially leaving the session in an inconsistent state.
To Reproduce
Steps to reproduce the behavior:
- Set up a PostgreSQL database for session persistence
- Configure
DatabaseSessionServicewith the PostgreSQL connection:
from google.adk.sessions import DatabaseSessionService
from google.adk import Runner
# Using PostgreSQL for persistent session storage
session_service = DatabaseSessionService(
db_url="postgresql://user:password@host:5432/database"
)
# Agent configured with persistent session service
runner = Runner(
agent=agent,
session_service=session_service
)- Run an agent that involves complex data processing (e.g.,
plot_agentwith large datasets) - Trigger a
MALFORMED_FUNCTION_CALLerror with a large payload - Observe the database error and agent crash with this error:
Error: Agent API error: {"error": "(psycopg2.errors.StringDataRightTruncation) value too long for type character varying(1024)\n\n[SQL: INSERT INTO events (...) VALUES (...)]\n[parameters: {..., 'error_message': 'Malformed function call: print(default_api.plot_agent(request='''Create a line graph with this data: [{'transaction_day': '2024-10-24', 'dail ... (40424 characters truncated) ...)', 'interrupted': None}]\n(Background on this error at: https://sqlalche.me/e/20/9h9h)", "timestamp": "2025-10-29T13:00:34.724692", "request_id": "req_1761767910262", "user_id": "2", "session_id": "2025_10_29_19_37_15_A9AA"}
Expected behavior
The agent should handle database insertion errors gracefully and continue operation, rather than crashing when error messages exceed the column size limit. Error logging failures should not cause agent execution failures.
Screenshots
N/A
Desktop (please complete the following information):
- OS: Linux/Ubuntu
- Python version: 3.11+
- ADK version: 1.15.1
Model Information:
- Are you using LiteLLM: No
- Which model is being used: gemini-2.5-flash ( google-adk running in GKE cluster )
Additional context
Root Cause Analysis:
- The
eventstable in the PostgreSQL database used byDatabaseSessionServicedefineserror_messageasVARCHAR(1024) - When using data-intensive agents (especially with
plot_agent), error messages can exceed 40,000 characters DatabaseSessionServicedoes not handle PostgreSQL insertion errors, so the column length violation crashes the agent execution
Current Impact:
- Affects all production deployments using
DatabaseSessionServicewith PostgreSQL - Particularly impacts data-intensive and visualization agents
- Results in agent crashes and potential session state corruption in PostgreSQL
- 97%+ of error context is lost due to truncation
Technical Details:
- Failed SQL Operation:
INSERT INTO events (
id, app_name, user_id, session_id, invocation_id, author,
actions, long_running_tool_ids_json, branch, timestamp,
content, grounding_metadata, custom_metadata,
partial, turn_complete, error_code, error_message, interrupted
) VALUES (...)- Problematic Field:
error_message(VARCHAR(1024)) - Actual Length in Example: ~40,424 characters
- Triggers: plot_agent, large data payloads, MALFORMED_FUNCTION_CALL errors
Temporary Workaround:
Until fixed, users can manually alter their PostgreSQL database:
ALTER TABLE events ALTER COLUMN error_message TYPE TEXT;Proposed Solutions:
- Add error handling in
DatabaseSessionServiceto prevent crashes when PostgreSQL logging fails - Implement smart truncation for oversized error messages
- Update the PostgreSQL schema to use
TEXTtype instead ofVARCHAR(1024) - Add configuration options for max error message length
Dependencies:
- SQLAlchemy 2.0.43
- asyncpg 0.30.0 (async PostgreSQL driver)
- psycopg2-binary 2.9.11 (sync PostgreSQL driver)
- fastapi==0.118.0
- pydantic==2.11.9
- uvicorn==0.37.0
Related Files:
google/adk/sessions/database_session_service.py