omi icon indicating copy to clipboard operation
omi copied to clipboard

[Bounty proposal] Harden desktop_prompts router against malformed Firestore prompt documents and store errors ($50 proposed)

Open huynhnhatquandongnai-source opened this issue 1 month ago • 2 comments

Problem

backend/routers/desktop_prompts.py polls active prompt documents from Firestore via GET /v2/desktop/prompts and evaluates prompt_matches_audience(doc, uid, channel, build) and spec_from_doc(doc) across every snapshot without type guards or per-document error isolation:

  1. Non-dict nested fields crash the endpoint (AttributeError):
    • audience = doc.get('audience') or {}, trigger = doc.get('trigger') or {}, and cta = doc.get('cta') or {} assume that any truthy value is a dict. If a legacy or malformed document stores a string or list in audience, trigger, or cta, .get(...) raises an unhandled AttributeError and fails the entire GET /v2/desktop/prompts response for all desktop users.
  2. Non-sequence channels and options cause substring false-positives or split strings into characters:
    • If audience.channels is a string (e.g. 'stable-beta'), channel not in channels performs a substring check instead of rejecting the malformed channel list; if it is an int or bool, in raises TypeError.
    • If doc.options is a string (e.g. 'yes,no'), [str(o) for o in (doc.get('options') or [])][:6] iterates over individual characters (['y', 'e', 's', ',', 'n', 'o']) instead of treating non-list options as empty.
  3. Unchecked numeric conversions and < comparisons (TypeError / ValueError):
    • build < min_build raises TypeError when min_build is a numeric string ('12000') or non-integer, and int(rollout_pct), int(trigger.get('count') or 0), and int(doc.get('max_per_day') or 1) raise ValueError/TypeError on non-numeric strings, NaN, or booleans (bool is a subclass of int in Python).
  4. No per-snapshot isolation or store error boundary:
    • A single corrupted snapshot in desktop_prompts crashes the entire endpoint instead of being skipped, and an upstream Firestore read failure surfaces as an unhandled exception without sanitized logging.

Impact

  • Any single malformed or partially edited document in the desktop_prompts collection breaks GET /v2/desktop/prompts (HTTP 500) for all desktop clients polling on launch.

Proposed Fix

  • Harden prompt_matches_audience and spec_from_doc to validate types on doc, audience, channels, min_build, rollout_pct, trigger, cta, and options, rejecting booleans and safely coercing/clamping integer fields.
  • Isolate per-snapshot evaluation in get_desktop_prompts so a malformed document is logged (with sanitize()) and skipped while valid prompts continue to be served.
  • Add a store error boundary around list_active_desktop_prompt_snapshots() that logs sanitized errors and returns a clean HTTP 500 Failed to load desktop prompts.
  • Add 34 hermetic unit tests in backend/tests/unit/test_desktop_prompts_resilience.py.

Proposed Bounty

$50 USDC

Implemented in PR #23255 with complete type guards, store error boundary, per-snapshot error isolation, and 34 hermetic unit tests:

  • Pull Request: https://github.com/BasedHardware/omi/pull/23255
  • Unit Tests: 34/34 passing hermetically in test_desktop_prompts_resilience.py
  • Full suite health: 244/244 passing (0 failures)
  • Payout Address: 0xC345C07229307d4f1c7935aD2cAe48e390215808 (USDC Polygon/Base/Arbitrum)

Dimank92 avatar Oct 22 '26 06:10 Dimank92

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