feat(sessions): introduce pluggable SessionDataTransformer hooks for …#5279
feat(sessions): introduce pluggable SessionDataTransformer hooks for …#5279sgmoorthy wants to merge 1 commit intogoogle:mainfrom
Conversation
…masking in DatabaseSessionService
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
|
Response from ADK Triaging Agent Hello @sgmoorthy, thank you for creating this PR! Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). You can visit https://cla.developers.google.com/ to see your current agreements or to sign a new one. Also, all PRs, other than small documentation or typo fixes, should have an Issue associated. If a relevant issue doesn't exist, please create one first or you may instead describe the bug or feature directly within the PR description, following the structure of our issue templates. This information will help reviewers to review your PR more efficiently. Thanks! |
Please ensure you have read the contribution guide before creating a pull request.
Link to Issue or Description of Change
1. Link to an existing issue (if applicable):
2. Or, if no issue exists, describe the change:
Problem:
Saving sensitive strings, tokens, and identifiers (e.g. LLM inputs) inherently places unencrypted PII straight into the database table JSON schema. The current
DatabaseSessionServicepersists bare event payloads and state natively without an option to selectively redact or encrypt content prior to database ingestion.Solution:
Exposes a
transformer: Optional[SessionDataTransformer] = Noneargument inDatabaseSessionService. It adopts a formal Protocol containing 4 hook strategies ([before|after]_[persist|load]_[event|state]), allowing customized tokenizations, field-level encryption, or redactions natively. This process reliably isolates raw database serialization blocks and keeps caller memory safely un-mutated, protecting local state access while securely scrubbing the storage records.Testing Plan
Unit Tests:
Unit Test Summary:
4 additional tests successfully verified
StorageEventbehaviors using aMockPIIMaskerTransformer. Assertions validated JSON mappings cleanly tokenizing strings (e.g.foo->foo_masked) strictly in SQL layers while raising programmatic failures correctly on bad schemas. All existing legacy unittests successfully passed locally alongside it.Manual End-to-End (E2E) Tests:
I verified tokenizations correctly function within live applications via the standard Python initialization methodology:
Setup Script:
Logs/Evidence:
(The generated SQLite verification successfully proved backend storage intercepts
[REDACTED_NAME], while the caller runtime session objects simultaneously retrieved standardJohn Doestrings).Checklist
Additional context
Built and installed the local configuration to a clean isolated environment using
uv buildanduv venvto guarantee python wheel module imports operated effectively. All legacy instantiations gracefully default to backwards-compatible structures.