omi icon indicating copy to clipboard operation
omi copied to clipboard

[Bounty Proposal] Validate inputs and handle exceptions in database recording sessions

Open Ariyachan opened this issue 2 months ago • 1 comments

Problem

  1. Missing input validation and crash on whitespace identifiers (backend/database/recording_sessions.py):

    • tombstone_and_delete_empty_conversation(uid, conversation_id, recording_session_id) does not validate uid or conversation_id. Passing an empty or whitespace-only string raises ValueError: A document id must not be empty when accessing users/{uid}/conversations/{conversation_id}.
    • If recording_session_id is a whitespace-only string (e.g. ' '), if recording_session_id: evaluates to True, causing _session_ref(client, uid, ' ') to build an invalid document path.
    • record_lifecycle_event does not validate uid, recording_session_id, or conversation_id, raising unhandled ValueError when Firestore builds document references.
    • create_or_get_recording_session and get_recording_session check if not uid, which fails to guard against whitespace-only strings.
  2. Uncaught NotFound during concurrent conversation deletion (backend/database/recording_sessions.py:202-252):

    • In tombstone_and_delete_empty_conversation, if the conversation document is purged or deleted concurrently by another worker before or during transaction execution, an unhandled google.api_core.exceptions.NotFound can escape rather than returning False.
  3. Potential KeyError on partial/legacy documents in _binding (backend/database/recording_sessions.py:72-80):

    • _binding accesses data['conversation_id'] directly. If a corrupted, legacy, or partially committed snapshot missing 'conversation_id' is read, it raises a bare KeyError.

Proposed Solution

  • Add input validation and whitespace stripping for uid, recording_session_id, and proposed_conversation_id in create_or_get_recording_session and get_recording_session.
  • Add validation in tombstone_and_delete_empty_conversation for uid and conversation_id, and coerce whitespace recording_session_id to None.
  • Wrap the transaction setup and execution in tombstone_and_delete_empty_conversation in try...except NotFound to return False safely on concurrent deletions.
  • Add input validation and whitespace stripping in record_lifecycle_event.
  • Safely default data.get('conversation_id') or '' in _binding to eliminate bare KeyError.
  • Add comprehensive contract and unit test suite in backend/tests/unit/test_database_recording_sessions_resilience.py.

Ariyachan avatar Sep 26 '26 07: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