omi icon indicating copy to clipboard operation
omi copied to clipboard

[Bounty proposal] fix(memory-tools): resolve top-level user_id, coerce limit/offset, and guard None configurable ($50 proposed)

Open Dimank92 opened this issue 1 month ago • 3 comments

Summary

In backend/utils/retrieval/tools/memory_tools.py, get_memories_tool and search_memories_tool provide access to user facts, preferences, and long-term memory retrieval.

Runtime Crashes & Vulnerabilities

  1. Broken user_id resolution for top-level configurations and None configurable:

    • In both get_memories_tool and search_memories_tool:
      configurable: Any = cfg.get('configurable')
      uid = configurable.get('user_id')
      
      When config is a dictionary containing top-level user_id (e.g. {"user_id": "test_uid"}), configurable is None. Calling .get('user_id') on None raises an unhandled AttributeError: 'NoneType' object has no attribute 'get'.
    • In _publish_memory_refs:
      channel_items = configurable.get('channel_items')
      
      If configurable is passed as None, this immediately raises AttributeError.
  2. Fatal TypeError: '>' not supported between instances of 'str' and 'int' on string limit or offset:

    • In get_memories_tool:
      if limit > 5000:
      
      And max(offset, 0): When an LLM agent provides arguments with string numbers (e.g. limit="50" or offset="0"), relational comparison against integers raises TypeError, aborting tool execution.
    • In search_memories_tool:
      limit = min(limit, 20)
      
      When limit is passed as a string, min() raises TypeError.
  3. Missing input sanitization on search query: In search_memories_tool, empty or null queries proceed into downstream vector search services without early input validation.

Fix

  • Introduced _extract_user_context(cfg) helper extracting user_id from either nested configurable or top-level cfg, safely guaranteeing configurable is a dictionary.
  • Guarded _publish_memory_refs to ensure configurable is always a dictionary.
  • Defensively coerced and clamped limit to [1, 5000], offset to >= 0, and search limit to [1, 20].
  • Normalized and validated non-empty query before querying memory services.
  • Added comprehensive hermetic unit tests in backend/tests/unit/test_memory_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 20:10 Dimank92

Resolved in PR #23116. Added _extract_user_context helper for robust user_id resolution, parameter integer coercion, empty query validation, and full unit test suite in backend/tests/unit/test_memory_tools.py.

Dimank92 avatar Oct 21 '26 20:10 Dimank92

I would like to work on this. I will open a pull request that addresses the acceptance criteria.

airdropia avatar Oct 21 '26 20:10 airdropia

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