omi icon indicating copy to clipboard operation
omi copied to clipboard

[Bounty proposal] fix(preference-tools): guard None replace_memory_id and validate non-empty preference ($50 proposed)

Open Dimank92 opened this issue 1 month ago • 2 comments

Summary

In backend/utils/retrieval/tools/preference_tools.py, save_user_preference_tool() records learned preferences and corrections into the knowledge ledger or canonical memory store.

Runtime Crashes & Vulnerabilities

  1. Fatal AttributeError: 'NoneType' object has no attribute 'strip': At line 218:

    replacement = replace_memory_id.strip()
    

    When optional parameter replace_memory_id is supplied as None (standard for LangChain tools when optional arguments are not explicitly given a string), replace_memory_id.strip() crashes with an unhandled AttributeError outside any exception boundary, terminating the tool call.

  2. AttributeError: 'NoneType' object has no attribute 'split' in _write_provenance(): At line 111:

    normalized_preference = ' '.join(preference.split())
    

    If preference is None, calling .split() raises AttributeError.

  3. Writing Empty / Whitespace-only Preferences: Empty or whitespace strings passed as preference are currently not validated upfront, allowing blank or meaningless memory items to be written to Firestore and the knowledge ledger.

Fix

  • Defensively normalize replace_memory_id via str(replace_memory_id or '').strip().
  • Validate preference upfront (if not preference or not isinstance(preference, str) or not preference.strip(): return "Error: Preference content cannot be empty").
  • In _write_provenance(), normalize preference safely via str(preference or '').split().
  • Annotate replace_memory_id: Optional[str] = "" for typing correctness.
  • Add comprehensive hermetic unit tests in backend/tests/unit/test_preference_tools.py.

Bounty Proposal

  • Proposed tier: $50 (Targeted bug fix + unit test coverage)
  • Settlement: Base Mainnet USDC / Stripe / Singapore Card

Dimank92 avatar Oct 21 '26 19:10 Dimank92

Resolved in PR #23135.

Guarded replace_memory_id against None values, added upfront non-empty validation for preference, ensured robust user_id resolution, and added full hermetic unit test coverage (8/8 passing) in backend/tests/unit/test_preference_tools.py.

Payout address (Base USDC): 0xb95e2AD8E9D9e9BF902c7531577Cd0E1ceB203D4

Booshdag-io avatar Oct 21 '26 20:10 Booshdag-io

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