diff --git a/src/google/adk/integrations/firestore/firestore_session_service.py b/src/google/adk/integrations/firestore/firestore_session_service.py index 83b97c33c2..e90753be5c 100644 --- a/src/google/adk/integrations/firestore/firestore_session_service.py +++ b/src/google/adk/integrations/firestore/firestore_session_service.py @@ -551,6 +551,7 @@ async def _append_txn(transaction: firestore.AsyncTransaction) -> int: for k, v in session.state.items() if not k.startswith(State.APP_PREFIX) and not k.startswith(State.USER_PREFIX) + and not k.startswith(State.TEMP_PREFIX) } transaction.update( session_ref, diff --git a/tests/unittests/integrations/firestore/test_firestore_session_service.py b/tests/unittests/integrations/firestore/test_firestore_session_service.py index 1445bfe0ef..0a275c2cb8 100644 --- a/tests/unittests/integrations/firestore/test_firestore_session_service.py +++ b/tests/unittests/integrations/firestore/test_firestore_session_service.py @@ -386,6 +386,15 @@ async def test_append_event_with_temp_state(mock_firestore_client): assert "temp:k1" not in event_data["actions"]["state_delta"] assert event_data["actions"]["state_delta"]["session_key"] == "session_val" + # 3. Verify temp keys are NOT written to session state in Firestore + transaction.update.assert_called_once() + update_args, _ = transaction.update.call_args + persisted_state = update_args[1]["state"] + assert "temp:k1" not in persisted_state, ( + "temp: keys must not be persisted to Firestore session state" + ) + assert "session_key" in persisted_state + @pytest.mark.asyncio async def test_list_sessions_with_user_id(mock_firestore_client):