omi
omi copied to clipboard
[Bounty proposal] fix(database): sanitize identifiers, add store failure boundaries, and add client injection to import_jobs ($50 proposed)
What's wrong
- Unsanitized and unvalidated identifiers: Functions in
backend/database/import_jobs.py(create_import_job,update_import_job,update_import_job_unless_cancelled,cancel_import_job_if_active,update_import_job_progress,get_import_job,get_import_jobs,delete_import_job) passjob_idanduiddirectly to Firestore.document(job_id)/.where('uid', '==', uid)without whitespace normalization or path-safety validation. Empty strings, whitespace-only values, or path delimiters (/,\,..) cause invalid Firestore document paths or unguardedKeyError/ client argument exceptions. - Race-condition
NotFoundcrashes on updates and deletes: When an import job is deleted concurrently by a user while a background worker callsupdate_import_job(job_id, updates)or whendelete_import_job(job_id)runs on an already-deleted job,.update()/.delete()raises an uncaughtgoogle.api_core.exceptions.NotFoundexception. Emptyupdatesdicts also raise Firestore client errors. - Uncaught store failures, missing limit clamping, and missing ID hydration on reads:
get_import_jobandget_import_jobslack error boundaries around Firestore reads and streams, causing transient store outages or corrupted document snapshots to fail the caller instead of returning safe fallbacks (None/[]). Additionally,get_import_jobs(uid, limit=50)does not clamplimitat the database boundary (1..1000), and legacy documents missing an internal'id'key are not hydrated fromdoc.id. - Incomplete client dependency injection: Only
cancel_import_job_if_activeaccepted*, firestore_client: Any = None, while all other 7 functions hardcoded module-globaldb, preventing hermetic unit testing without global state mutation.
Proposed Fix
- Add
_sanitize_id()and_clean_optional_id()to trim whitespace and reject empty, non-string, or path-traversal identifiers (ValueErroron writes, safeNone/[]fallbacks on reads). - Guard
update_import_jobanddelete_import_jobagainstNotFoundand empty update payloads, returning a boolean outcome. - Wrap
get_import_jobandget_import_jobsin store failure boundaries, clamplimitto[1, 1000], skip unreadable stream documents, and backfilldata['id'] = str(doc.id)when absent. - Add
*, firestore_client: Optional[Any] = Noneacross all functions inbackend/database/import_jobs.py. - Add 21 hermetic unit tests in
backend/tests/unit/test_import_jobs_resilience.py.
Proposed Bounty
$50
Bounty settlement address (Base Mainnet USDC): 0xb9f3765aeb1974c27a193463f655a1a57b3aec94
Implemented in PR #23257 with identifier sanitization, NotFound guards, store failure boundaries, client injection, and 22 hermetic unit tests:
- Pull Request: https://github.com/BasedHardware/omi/pull/23257
- Unit Tests: 22/22 passing hermetically in
test_import_jobs_resilience.py - Full suite health: 301/301 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! 🙏