[Bounty proposal] fix(database): sanitize uid and guard voice preferences against store failures ($50 proposed)
Problem Description
The assistant voice preferences module (backend/database/voice_preferences.py) reads and persists user voice choices from/to the Firestore data plane. However, it currently has several input sanitization, error resilience, and testability shortcomings:
- Unsanitized UID Paths:
uidvalues containing whitespace (e.g. from headers or bearer tokens like" uid123 ") create corrupted document paths in Firestore (/users/ uid123 /) rather than updating canonical user profiles. - Crash on Data Plane Outage:
get_assistant_voicequeries Firestore without an error handling boundary. If the Firestore data plane experiences a transient timeout or network glitch, calls crash with an unhandled exception instead of safely falling back toDEFAULT_ASSISTANT_VOICE. - Missing Validation on Writes:
set_assistant_voicedoes not validate thatuidis a non-empty string, allowing empty/blank strings to write to invalid Firestore paths. - Missing Client Availability Guard: If
get_data_plane_firestore_client()returnsNone,set_assistant_voiceencounters an unhandledAttributeErrorinstead of a clearRuntimeError. - Zero Unit Test Coverage:
backend/database/voice_preferences.pycurrently has zero dedicated unit tests.
Proposed Solution
- Sanitize UID: Strip whitespace from
uidacrossget_assistant_voiceandset_assistant_voice, rejecting empty or blank strings withValueErroron write operations. - Safe Fallback on Read: Wrap Firestore reads in a
try/exceptboundary, logging a warning and safely returningDEFAULT_ASSISTANT_VOICEon document absence or read failure. - Guarded Client Resolution: Explicitly guard against missing data plane clients on writes.
- Unit Tests: Add comprehensive unit tests in
backend/tests/unit/test_voice_preferences.pycovering success cases, missing documents, unhandled exceptions, whitespace sanitization, and invalid inputs.
Proposed Bounty: $50 PayPal: https://paypal.me/Dragonire9 ([email protected])
Hi @josancamon19 @kodjima33 — is there still an approved paid opening for the complete repair in #21899, given the existing claim and open PR #21936?
I'd cover canonical UID handling, safe read fallbacks, explicit invalid-write and missing-client errors, and the full regression coverage, preserving voice normalization and the existing injected-client seam. Could you confirm the remaining scope and acceptance/assignment, the approved amount and currency, and a lawful payout option for an individual based in mainland China before I start? If the existing PR fully covers the work, a quick confirmation is enough.
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! 🙏