omi icon indicating copy to clipboard operation
omi copied to clipboard

[Bounty proposal] fix(database): add stream fault tolerance and client injection to trends ($50 proposed)

Open Dragonire9 opened this issue 1 month ago • 2 comments

Problem Description

The trends data access module (backend/database/trends.py) queries public trends and persists topic aggregations across user memories. However, it currently has several error resilience, input sanitization, and testability shortcomings:

  1. Unprotected Root Stream Collection: get_trends_data calls trends_ref.stream(retry=Retry()) outside of any try/except block and hardcodes the global db client without dependency injection. If the initial stream encounters a network timeout or Firestore unavailability, the /v1/trends endpoint crashes with an unhandled exception instead of safely returning [].
  2. Missing Category ID Crash: When constructing category_topics_ref = trends_ref.document(category_data['id']).collection('topics'), if a Firestore document payload lacks the 'id' field, it raises an unhandled KeyError: 'id'. It should fall back to category.id.
  3. Malformed Memory ID Len Calculation: In topic sorting, len(e.get('memory_ids') or []) throws TypeError if memory_ids is stored as a non-iterable (e.g. an integer or boolean).
  4. Unsanitized Inputs in save_trends: save_trends does not sanitize memory_id or topics strings, allowing empty/blank strings to create invalid documents or duplicate array unions.
  5. Missing Dependency Injection: Neither get_trends_data nor save_trends accepts firestore_client=None.
  6. Zero Unit Test Coverage: backend/database/trends.py currently has zero dedicated unit tests.

Proposed Solution

  1. Root Stream Error Boundary: Wrap collection streaming in a try/except boundary returning [] on error.
  2. Client Dependency Injection: Add firestore_client: Optional[Any] = None parameter across get_trends_data and save_trends.
  3. ID Fallback & Safe Len: Fall back to document id when missing from dictionary payloads, and guard memory_ids length checking with isinstance(..., list).
  4. Input Sanitization: Strip memory_id and topics, skipping blank items and empty payloads.
  5. Unit Tests: Add 8 comprehensive unit tests in backend/tests/unit/test_trends.py covering category filtering, sorting, ID fallbacks, stream failures, and save operations.

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

Dragonire9 avatar Oct 16 '26 17:10 Dragonire9

@josancamon19 @kodjima33 — is the complete trends repair in this issue still wanted as a paid contribution, and available to take on?

The full scope I’m referring to is: return an empty result safely when the root stream fails; fall back to the document ID; handle malformed memory ID lists without losing valid categories; normalize memory/topic inputs and skip blanks; allow an injected Firestore client in both read and save paths; and cover all eight regressions for filtering, sorting, ID fallbacks, stream failures, and saves while preserving existing API behavior.

Could you confirm the current target revision, complete acceptance criteria and assignment process, the approved amount and ISO currency (the posted $50 is only proposed), and the payment process available to a Mainland China based individual using this GitHub identity, including fees and payment timing? Once those and the current implementation are confirmed, I can propose a fixed price and delivery date for the complete fix.

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