omi icon indicating copy to clipboard operation
omi copied to clipboard

[Bounty proposal] fix(memory-tools): guard string numeric coercion, fallback top-level config, and validate query inputs ($50 proposed)

Open Dimank92 opened this issue 1 month ago • 2 comments

Summary

In backend/utils/retrieval/tools/memory_tools.py, several input coercions and edge cases in get_memories_tool and search_memories_tool lead to runtime exceptions or failed memory lookups:

  1. String numeric coercion failure (TypeError: '>' not supported between instances of 'str' and 'int'):
    • get_memories_tool: If limit or offset are passed as numeric strings by an LLM agent (e.g. limit="50" or offset="0"), if limit > 5000: and target_end = min(max(offset, 0) + limit, 5000) raise TypeError.
    • search_memories_tool: limit = min(limit, 20) raises TypeError: '<' not supported between instances of 'int' and 'str' when limit is a string (e.g. limit="5"), which triggers the generic except Exception: block and aborts the tool call with "Error searching memories. Please try again.".
  2. Missing top-level config and UID resolution:
    • In both get_memories_tool and search_memories_tool: Accessing configurable.get('user_id') crashes with AttributeError: 'NoneType' object has no attribute 'get' whenever configurable is None or when callers pass top-level {"user_id": "..."} or {"uid": "..."}.
  3. Non-string date values crash on .replace():
    • In get_memories_tool: If an agent passes non-string types for start_date or end_date (e.g. integer timestamps or booleans), .replace('Z', '+00:00') raises AttributeError: 'int' object has no attribute 'replace'.
  4. Empty / None / Whitespace-only search query:
    • In search_memories_tool: query lacked early validation for empty strings, whitespace, None, or non-string inputs. Calling search_memories_tool with omitted or blank queries caused downstream failures or sent blank search vectors.

Proposed Changes

  1. Safe Integer Coercion Helper (_safe_int): Safely parse integers and numeric strings while rejecting booleans, None, and invalid text.
  2. Resilient Config & UID Extraction (_get_config_and_uid): Safely handle non-dict or absent configurable dictionaries and resolve uid from configurable['user_id'], top-level user_id, or uid across config and _agent_config().
  3. Safe Date Formatting: Validate that start_date and end_date are strings before calling .replace('Z', '+00:00').
  4. Early Query Validation: Validate query in search_memories_tool ("Error: Search query cannot be empty") and annotate with Optional[str] = None to accept omitted arguments gracefully.
  5. Hermetic Unit Tests: Add backend/tests/unit/test_memory_tools_guards.py verifying integer coercion, top-level UID resolution, date validation, and query guards (7 tests, 100% pass).

Bounty Proposal

Proposed bounty: $50 USDC Payout address: 0xC345C07229307d4f1c7935aD2cAe48e390215808 (USDC Polygon/Base/Arbitrum)

Dimank92 avatar Oct 22 '26 05:10 Dimank92

Fix and hermetic test suite opened in PR #23232: https://github.com/BasedHardware/omi/pull/23232

Payout address (USDC Polygon / Base / Arbitrum): 0xC345C07229307d4f1c7935aD2cAe48e390215808

Dimank92 avatar Oct 22 '26 05:10 Dimank92

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