omi icon indicating copy to clipboard operation
omi copied to clipboard

[Bounty proposal] fix(database): sanitize phone call overrides and add fault-tolerant client injection ($50 proposed)

Open Dragonire9 opened this issue 1 month ago • 2 comments

Problem Description

The catalog-backed phone call configuration module (backend/database/phone_call_config.py) overlays live Firestore settings onto catalog defaults. However, it suffers from several sanitization, validation, error-handling, and testability shortcomings:

  1. Unsanitized Allowed Countries: In _declared_override, allowed_countries is taken directly from the Firestore document without validation. If the override contains non-string elements (e.g. None, numbers), lowercase or unpadded codes (" us ", "ca"), or a non-list type ("US"), country restriction checks and callers encounter subtle bugs or runtime exceptions.
  2. Boolean and Negative Limit Coercion: monthly_call_limit and max_duration_seconds do not reject booleans (True evaluates to 1 in Python's isinstance(val, int)), nor negative values (-1), which can cause unintended limit lockouts or negative allowances.
  3. Firestore Outage Fragility: _fetch_config calls Firestore without a try/except boundary or dependency injection (firestore_client=None). If Firestore experiences transient latency or connectivity failures, phone call policy resolution crashes callers instead of falling back to safe defaults.
  4. Zero Unit Test Coverage: backend/database/phone_call_config.py currently has zero dedicated unit tests.

Proposed Solution

  1. Sanitize Country Codes: In _declared_override, ensure allowed_countries is a list, stripping and uppercasing 2-letter ISO codes while ignoring malformed items.
  2. Strict Limit Validation: Explicitly reject booleans and negative integers for monthly_call_limit and max_duration_seconds, while preserving valid non-negative ints and explicit None (unlimited).
  3. Resilient Firestore Fetch & DI: Add firestore_client=None parameter and wrap Firestore access in try/except returning {} safely on error.
  4. Unit Tests: Add comprehensive test cases in backend/tests/unit/test_phone_call_config.py covering defaults, overrides, sanitization, and fallback boundaries.

Proposed Bounty: $50 PayPal: https://paypal.me/Dragonire9 ([email protected])

Dragonire9 avatar Oct 16 '26 16:10 Dragonire9

Hi maintainers, is #21895 still available for a complete paid contribution? I would cover all four requested parts: normalize and validate the country-code list, reject boolean/negative limits while preserving valid non-negative integers and explicit None, add injectable Firestore access with safe outage fallback, and add regression tests for defaults, overrides, malformed inputs and failure paths. The catalog defaults, overlay metadata/cache and existing callers should remain compatible.

I see the proposed $50 and an existing claim. Is there remaining work you are commissioning, and which target revision and acceptance checks should a new contribution satisfy? Please confirm the approved amount/currency and official payout route, including contributor eligibility, fees and payment timing. I can then give a fixed-scope quote and delivery estimate before starting.

Thanks!

ayqy avatar Oct 17 '26 09:10 ayqy

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 12:10 undivisible