FirestoreSessionService loses the event when app: or user: state holds a date, UUID, Decimal or other value Firestore can't store
Maintainer thường phản hồi trong vòng 3 ngày
Đánh giá
Issue này chưa được đánh giá.
Mô tả
🔴 Required Information
Describe the Bug:
FirestoreSessionService writes app: and user: state to Firestore natively, so it can keep rich types such as datetime. Before writing, _encode_firestore_value only reshapes dicts and lists. Every other value goes to the Firestore client unchanged. The client can only encode None, bool, int, float, str, bytes, datetime.datetime, lists, dicts and its own types. Anything else raises TypeError: Cannot convert to a Firestore Value, including a datetime.date, uuid.UUID, decimal.Decimal, a plain Enum or a Pydantic model.
The error happens inside the write transaction:
append_eventraises, and the event is never added to the session. The turn is lost.create_sessionraises when the initial state contains such a value.
The same value works everywhere else:
- Under a session-level key in Firestore, because that bucket goes through
_session_util.make_json_safe_state. - Under
app:anduser:inDatabaseSessionServiceandSqliteSessionService. Both store it in JSON-safe form, for example"2024-06-15".
So an agent that works on the database or SQLite backend fails once it is switched to Firestore. #7826 made this same fix for VertexAiSessionService. Its description lists Firestore as already coercing state, which is true only for session-level state.
Steps to Reproduce:
pip install google-adk[gcp].- Run the script under Minimal Reproduction Code. It mocks the Firestore client, but the transaction's
set()runs the client's realpbs_for_set_no_merge, which is whatTransaction.set()runs, so no Firestore project is needed. - Or with a live Firestore database: in a tool, set
tool_context.state["user:due"] = datetime.date.today(), then run the agent withFirestoreSessionService.
Expected Behavior:
The value is stored in the JSON-safe form that the session bucket and the other backends use ("2026-11-18", the UUID string, "1.50"), and the event is appended.
Observed Behavior:
session state with a date: stored
user: state with a date: append_event failed: TypeError('Cannot convert to a Firestore Value', datetime.date(2026, 11, 18), 'Invalid type', <class 'datetime.date'>)
events: 0
Environment Details:
- ADK Library Version (pip show google-adk): 2.14.1 (
mainat c74df83c0) - google-cloud-firestore: 2.34.1
- Desktop OS: Windows 11 (the bug isn't OS-specific)
- Python Version (python -V): 3.12.0
Model Information:
- Are you using LiteLLM: No
- Which model is being used: N/A (session service only)
🟡 Optional Information
Regression:
No. App and user state have been written natively since nested-array support was added. That change handled nested lists but not other non-native values.
Minimal Reproduction Code:
import asyncio
import datetime
from unittest import mock
from google.adk.events.event import Event
from google.adk.events.event_actions import EventActions
from google.adk.integrations.firestore import FirestoreSessionService
from google.cloud.firestore_v1 import _helpers
# A mocked client whose transaction.set() encodes the document exactly as the
# real Transaction.set() does, so unsupported values fail the same way.
client = mock.MagicMock()
doc = mock.MagicMock(exists=False)
doc.to_dict.return_value = {}
client.collection.return_value.document.return_value.get = mock.AsyncMock(return_value=doc)
ref = client.collection.return_value.document.return_value.collection.return_value.document.return_value
ref.get = mock.AsyncMock(return_value=doc)
ref.collection.return_value.document.return_value.get = mock.AsyncMock(return_value=doc)
client.transaction.return_value.set.side_effect = (
lambda _ref, data, **_: _helpers.pbs_for_set_no_merge("projects/p/databases/(default)/documents/c/d", data)
)
async def main():
service = FirestoreSessionService(client=client)
with mock.patch("google.cloud.firestore.async_transactional", lambda f: f):
session = await service.create_session(
app_name="app", user_id="u1", state={"due": datetime.date(2026, 11, 18)}
)
print("session state with a date: stored")
stored = mock.MagicMock(exists=True)
stored.to_dict.return_value = {"revision": 0}
ref.collection.return_value.document.return_value.get = mock.AsyncMock(return_value=stored)
try:
await service.append_event(
session,
Event(
author="agent",
actions=EventActions(state_delta={"user:due": datetime.date(2026, 11, 18)}),
),
)
print("user: state with a date: stored, events:", len(session.events))
except TypeError as e:
print("user: state with a date: append_event failed:", repr(e))
print("events:", len(session.events))
asyncio.run(main())
How often has this issue occurred?:
- Always (100%), whenever
app:oruser:state holds such a value.
I have a fix with regression tests ready and will open a PR for it.
- Ngôn ngữ chính
- Python
- Star
- 22.3k
- Fork
- 4.4k
- Merge trung bình
- 1 ngày 2 giờ
- Pull request đã merge (30 ngày)
- 6
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của google/adk-python
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
google/adk-python#8360 ·
Maintainer thường phản hồi trong vòng 3 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
google/adk-python#8359 ·
Maintainer thường phản hồi trong vòng 3 ngày
-
Can pin to litellm version be changed?Có thể đã có người làm @llalitkumarrr đã nhận 10 ngày trước. Đang mởmodels
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 65/100
google/adk-python#8129 · 2 bình luận · 1 người được giao ·
Maintainer thường phản hồi trong vòng 3 ngày
-
OpenAPI tools ignore operation- and path-level server overridesCó thể đã có người làm @sanketpatil06 đã nhận 14 ngày trước. Đang mởtools
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
google/adk-python#8064 · 4 bình luận · 1 người được giao ·
Maintainer thường phản hồi trong vòng 3 ngày
-
Two docstrings in openapi_tool document parameters the signatures do not acceptCó thể đã có người làm @surajksharma07 đã nhận 17 ngày trước. Đang mở
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 88/100
google/adk-python#8024 · 1 bình luận · 1 người được giao ·
Maintainer thường phản hồi trong vòng 3 ngày
Tất cả issue của google/adk-python
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
vllm-project/vllm#70030 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
TigreGotico/tugaphone#408 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
needs-triage
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 74/100
gke-labs/kube-agents#7308 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
t: bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
Maintainer thường phản hồi trong vòng 3 ngày
-
chore
Độ khó 1/5 1-3 giờ Mức phù hợp với người mới 88/100
lugassawan/swe-workbench#841 ·