Migrating DatabaseSessionService to use JSON serialization #3605
Pinned
DeanChensj
announced in
Announcements
Replies: 1 comment 1 reply
-
|
One thing worth discussing is the performance overhead—are there any anticipated impacts on read/write speed or storage size compared to pickle? Also, regarding complex nested objects or custom types, will additional validation or conversion be required? Overall, this is a much-needed and progressive change. Cheers ! |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Problem Statement
Pickle Serialization Causes Breaking Changes
The current DatabaseSessionService stores the EventActions object using pickle serialization.
When the EventActions Pydantic model schema changes (e.g., adding new fields like compaction, agent_state, or rewind_before_invocation_id), existing pickled data in the database cannot be properly deserialized. This creates a breaking change that requires database migration.
Inconsistent storage schema with LlmResponse
Adding new fields to LlmResponse necessitates explicit inclusion in the Events table. This has historically led to discrepancies between the database schema and the corresponding Python objects.
Incompatible schema for different language
EventAction is stored in pickle, which can not be shared between languages
Proposed Solution: JSON Representation
The solution is to refactor StorageEvent to use JSON serialization instead of pickle, similar to how other fields like content are already handled. For key fields like ID, timestamp, invocation_id, we will still keep dedicated columns for them.
Implementation Pattern
The conversion from Event to StorageEvent already uses JSON serialization for complex fields. And deserialization uses a utility function. The decode_model utility function handles JSON-to-Pydantic conversion.
ADK team will provide a one-time migration script to update existing databases to the new schema, compatible with both PostgreSQL and MySQL.
Benefits of JSON Representation
We are planning to deploy this migration in the near future. We would greatly appreciate any feedback, insights, or potential concerns from the community regarding this proposed change. Please feel free to share your comments or feedback within this thread.
APPENDIX
Beta Was this translation helpful? Give feedback.
All reactions