omi
omi copied to clipboard
[Bounty proposal] Harden desktop_prompts router against malformed Firestore prompt documents and store errors ($50 proposed)
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:
- Non-dict nested fields crash the endpoint (
AttributeError):audience = doc.get('audience') or {},trigger = doc.get('trigger') or {}, andcta = doc.get('cta') or {}assume that any truthy value is adict. If a legacy or malformed document stores a string or list inaudience,trigger, orcta,.get(...)raises an unhandledAttributeErrorand fails the entireGET /v2/desktop/promptsresponse for all desktop users.
- Non-sequence
channelsandoptionscause substring false-positives or split strings into characters:- If
audience.channelsis a string (e.g.'stable-beta'),channel not in channelsperforms a substring check instead of rejecting the malformed channel list; if it is anintorbool,inraisesTypeError. - If
doc.optionsis 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-listoptionsas empty.
- If
- Unchecked numeric conversions and
<comparisons (TypeError/ValueError):build < min_buildraisesTypeErrorwhenmin_buildis a numeric string ('12000') or non-integer, andint(rollout_pct),int(trigger.get('count') or 0), andint(doc.get('max_per_day') or 1)raiseValueError/TypeErroron non-numeric strings,NaN, or booleans (boolis a subclass ofintin Python).
- No per-snapshot isolation or store error boundary:
- A single corrupted snapshot in
desktop_promptscrashes the entire endpoint instead of being skipped, and an upstream Firestore read failure surfaces as an unhandled exception without sanitized logging.
- A single corrupted snapshot in
Impact
- Any single malformed or partially edited document in the
desktop_promptscollection breaksGET /v2/desktop/prompts(HTTP 500) for all desktop clients polling on launch.
Proposed Fix
- Harden
prompt_matches_audienceandspec_from_docto validate types ondoc,audience,channels,min_build,rollout_pct,trigger,cta, andoptions, rejecting booleans and safely coercing/clamping integer fields. - Isolate per-snapshot evaluation in
get_desktop_promptsso a malformed document is logged (withsanitize()) 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 500Failed 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)
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! 🙏