omi
omi copied to clipboard
[Bounty Proposal] Validate inputs and handle exceptions in database recording sessions
Problem
-
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 validateuidorconversation_id. Passing an empty or whitespace-only string raisesValueError: A document id must not be emptywhen accessingusers/{uid}/conversations/{conversation_id}.- If
recording_session_idis a whitespace-only string (e.g.' '),if recording_session_id:evaluates toTrue, causing_session_ref(client, uid, ' ')to build an invalid document path. record_lifecycle_eventdoes not validateuid,recording_session_id, orconversation_id, raising unhandledValueErrorwhen Firestore builds document references.create_or_get_recording_sessionandget_recording_sessioncheckif not uid, which fails to guard against whitespace-only strings.
-
Uncaught
NotFoundduring 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 unhandledgoogle.api_core.exceptions.NotFoundcan escape rather than returningFalse.
- In
-
Potential
KeyErroron partial/legacy documents in_binding(backend/database/recording_sessions.py:72-80):_bindingaccessesdata['conversation_id']directly. If a corrupted, legacy, or partially committed snapshot missing'conversation_id'is read, it raises a bareKeyError.
Proposed Solution
- Add input validation and whitespace stripping for
uid,recording_session_id, andproposed_conversation_idincreate_or_get_recording_sessionandget_recording_session. - Add validation in
tombstone_and_delete_empty_conversationforuidandconversation_id, and coerce whitespacerecording_session_idtoNone. - Wrap the transaction setup and execution in
tombstone_and_delete_empty_conversationintry...except NotFoundto returnFalsesafely on concurrent deletions. - Add input validation and whitespace stripping in
record_lifecycle_event. - Safely default
data.get('conversation_id') or ''in_bindingto eliminate bareKeyError. - Add comprehensive contract and unit test suite in
backend/tests/unit/test_database_recording_sessions_resilience.py.
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! 🙏