omi icon indicating copy to clipboard operation
omi copied to clipboard

[Bounty proposal] fix(database): sanitize inputs and add stream error boundaries to batch pipeline privacy queries ($50 proposed)

Open Dragonire9 opened this issue 1 month ago • 2 comments

Problem Description

The batch privacy query layer (backend/database/batch_pipeline_privacy_queries.py) executes bounded Firestore queries for retention, segment artifact lifecycles, and user data purge flows across batch jobs. However, it currently has several input sanitization, error resilience, and testability shortcomings:

  1. Unsanitized Query Parameters: namespace, table, key, and segment_id are directly concatenated into collection names (e.g. client.collection(f'{namespace}_{table}')) without whitespace stripping or non-empty validation. Leading/trailing whitespace or empty strings produce malformed collection paths.
  2. Unprotected Stream Queries: owner_documents, predecessor_documents, segment_artifacts, and due_artifacts call .stream() outside of any error boundary. Transient Firestore network timeouts or service contention crash retention workers with unhandled exceptions instead of returning [].
  3. Missing Client Injection Fallback: Functions require caller-supplied client without get_firestore_client() fallback when omitted or None.
  4. Limit Validation: In owner_documents, limit is hardcoded to 100 rather than accepting an optional clamped bound max(1, min(100, limit)).
  5. Zero Dedicated Unit Tests: backend/database/batch_pipeline_privacy_queries.py currently has zero dedicated unit tests in backend/tests/unit/test_batch_pipeline_privacy_queries.py.

Proposed Solution

  1. Parameter Sanitization: Strip namespace, table, key, and segment_id across all query builders, returning [] on empty/None parameters.
  2. Stream Error Boundaries: Wrap all collection stream queries in try/except Exception boundaries, logging warnings and safely returning [].
  3. Firestore Client Fallback: Inject get_firestore_client() when client is None.
  4. Bounded Limits: Clamp limits with max(1, min(100, limit)) safely.
  5. Comprehensive Unit Tests: Add 16 dedicated unit test functions (35 test assertions) in backend/tests/unit/test_batch_pipeline_privacy_queries.py verifying collection naming, query construction, cursor handling, input validation, and exception handling.

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

Dragonire9 avatar Oct 16 '26 17:10 Dragonire9

Hi @josancamon19 @kodjima33 — is there still a paid scope for the complete #21916 repair beyond the work in #21928, with #21917 now closed unmerged?

I mean the full result: identifier sanitization, all four stream error boundaries, Firestore client fallback, bounded limits, and the requested 16 tests/35 assertions covering query construction and cursor/error cases. If work remains, which revision and acceptance checks should I use, and should I coordinate with the current contributor?

The issue proposes $50 but has no Paid Bounty label. Could you confirm the approved cash amount and currency, and whether you can pay a mainland-China individual in the same legal name — through which permitted method, with what fees and timing?

Once scope and payment are clear, I can check the complete implementation and give a delivery estimate.

ayqy avatar Oct 17 '26 04: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