omi icon indicating copy to clipboard operation
omi copied to clipboard

[Bounty Proposal] Populate snapshot id and use merge writes in database tasks

Open Ariyachan opened this issue 2 months ago • 2 comments

Problem

  1. Unhandled ValidationError in process_user_expression_measurement_callback (backend/utils/conversations/process_conversation.py:3258) when stored task document lacks explicit id: In backend/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 None
    

    If a task document snapshot in Firestore does not contain an explicit 'id' key in its dictionary payload (or if item.to_dict() evaluates to None), downstream callers unpacking Task(**task_data) fail with a Pydantic ValidationError or TypeError because Task.id is a required non-optional field.

  2. NotFound exception on tasks_db.update (backend/database/tasks.py:16): update invokes task_ref.update(task_data). If the target document is not yet initialized or has been purged, Firestore raises google.api_core.exceptions.NotFound, crashing callback processing instead of performing a resilient merge.

  3. Unchecked KeyError in tasks_db.create (backend/database/tasks.py:9): task_data['id'] raises an unhandled KeyError if task_data is passed without an 'id' field.

Proposed Solution

  • In get_task_by_action_request, safely stream snapshots, verify dictionary type, and populate data.setdefault('id', item.id) so that the canonical Firestore document ID is always present for model validation.
  • In update, switch to task_ref.set(task_data, merge=True) for idempotent persistence without NotFound failures.
  • In create, validate task_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.

Ariyachan avatar Sep 26 '26 02:09 Ariyachan

@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.

Ariyachan avatar Sep 27 '26 06:09 Ariyachan

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! 🙏

undivisible avatar Oct 22 '26 11:10 undivisible