[Bounty Proposal] Populate snapshot id and use merge writes in database tasks
Problem
-
Unhandled
ValidationErrorinprocess_user_expression_measurement_callback(backend/utils/conversations/process_conversation.py:3258) when stored task document lacks explicitid: Inbackend/database/tasks.py:def get_task_by_action_request(action: str, request_id: str) -> dict[str, Any] | None: ... tasks: list[dict[str, Any]] = [item.to_dict() for item in query.stream()] if len(tasks) > 0: return tasks[0] return NoneIf a task document snapshot in Firestore does not contain an explicit
'id'key in its dictionary payload (or ifitem.to_dict()evaluates toNone), downstream callers unpackingTask(**task_data)fail with a PydanticValidationErrororTypeErrorbecauseTask.idis a required non-optional field. -
NotFoundexception ontasks_db.update(backend/database/tasks.py:16):updateinvokestask_ref.update(task_data). If the target document is not yet initialized or has been purged, Firestore raisesgoogle.api_core.exceptions.NotFound, crashing callback processing instead of performing a resilient merge. -
Unchecked
KeyErrorintasks_db.create(backend/database/tasks.py:9):task_data['id']raises an unhandledKeyErroriftask_datais passed without an'id'field.
Proposed Solution
- In
get_task_by_action_request, safely stream snapshots, verify dictionary type, and populatedata.setdefault('id', item.id)so that the canonical Firestore document ID is always present for model validation. - In
update, switch totask_ref.set(task_data, merge=True)for idempotent persistence withoutNotFoundfailures. - In
create, validatetask_id = task_data.get('id')and use.set(task_data, merge=True). - Add unit test suite in
backend/tests/unit/test_database_tasks_resilience.py.
@kodjima33 Would you consider #19044 for a $50 paid bounty under the Contribution Guide, and confirm whether it is eligible? The fix and focused verification are in #19046, which has your approval but has not merged. I will treat the amount as a proposal unless you confirm it. Thank you.
Thanks for putting this together. We aren't doing bounties at the moment, so we're closing the bounty proposal issues for now — thanks for the fix! 🙏