Skip to content

DatabaseSessionService error : Database Column Length Exceeded for Error Messages in Sequential Agent Workflows #3351

@prasadskarmarkar

Description

@prasadskarmarkar

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:

  1. Set up a PostgreSQL database for session persistence
  2. Configure DatabaseSessionService with 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
)
  1. Run an agent that involves complex data processing (e.g., plot_agent with large datasets)
  2. Trigger a MALFORMED_FUNCTION_CALL error with a large payload
  3. 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:

  1. The events table in the PostgreSQL database used by DatabaseSessionService defines error_message as VARCHAR(1024)
  2. When using data-intensive agents (especially with plot_agent), error messages can exceed 40,000 characters
  3. DatabaseSessionService does not handle PostgreSQL insertion errors, so the column length violation crashes the agent execution

Current Impact:

  • Affects all production deployments using DatabaseSessionService with 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:

  1. Add error handling in DatabaseSessionService to prevent crashes when PostgreSQL logging fails
  2. Implement smart truncation for oversized error messages
  3. Update the PostgreSQL schema to use TEXT type instead of VARCHAR(1024)
  4. 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

Metadata

Metadata

Labels

services[Component] This issue is related to runtime services, e.g. sessions, memory, artifacts, etc

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions