[Bounty proposal] fix(memory-tools): resolve top-level user_id, coerce limit/offset, and guard None configurable ($50 proposed)
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
-
Broken
user_idresolution for top-level configurations and None configurable:- In both
get_memories_toolandsearch_memories_tool:
Whenconfigurable: Any = cfg.get('configurable') uid = configurable.get('user_id')configis a dictionary containing top-leveluser_id(e.g.{"user_id": "test_uid"}),configurableisNone. Calling.get('user_id')onNoneraises an unhandledAttributeError: 'NoneType' object has no attribute 'get'. - In
_publish_memory_refs:
Ifchannel_items = configurable.get('channel_items')configurableis passed asNone, this immediately raisesAttributeError.
- In both
-
Fatal
TypeError: '>' not supported between instances of 'str' and 'int'on stringlimitoroffset:- In
get_memories_tool:
Andif limit > 5000:max(offset, 0): When an LLM agent provides arguments with string numbers (e.g.limit="50"oroffset="0"), relational comparison against integers raisesTypeError, aborting tool execution. - In
search_memories_tool:
Whenlimit = min(limit, 20)limitis passed as a string,min()raisesTypeError.
- In
-
Missing input sanitization on search
query: Insearch_memories_tool, empty or null queries proceed into downstream vector search services without early input validation.
Fix
- Introduced
_extract_user_context(cfg)helper extractinguser_idfrom either nestedconfigurableor top-levelcfg, safely guaranteeingconfigurableis a dictionary. - Guarded
_publish_memory_refsto ensureconfigurableis always a dictionary. - Defensively coerced and clamped
limitto[1, 5000],offsetto>= 0, and searchlimitto[1, 20]. - Normalized and validated non-empty
querybefore 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
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.
I would like to work on this. I will open a pull request that addresses the acceptance criteria.
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! 🙏