[Bounty proposal] fix(memory-tools): guard string numeric coercion, fallback top-level config, and validate query inputs ($50 proposed)
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:
- String numeric coercion failure (
TypeError: '>' not supported between instances of 'str' and 'int'):get_memories_tool: Iflimitoroffsetare passed as numeric strings by an LLM agent (e.g.limit="50"oroffset="0"),if limit > 5000:andtarget_end = min(max(offset, 0) + limit, 5000)raiseTypeError.search_memories_tool:limit = min(limit, 20)raisesTypeError: '<' not supported between instances of 'int' and 'str'whenlimitis a string (e.g.limit="5"), which triggers the genericexcept Exception:block and aborts the tool call with"Error searching memories. Please try again.".
- Missing top-level config and UID resolution:
- In both
get_memories_toolandsearch_memories_tool: Accessingconfigurable.get('user_id')crashes withAttributeError: 'NoneType' object has no attribute 'get'wheneverconfigurableisNoneor when callers pass top-level{"user_id": "..."}or{"uid": "..."}.
- In both
- Non-string date values crash on
.replace():- In
get_memories_tool: If an agent passes non-string types forstart_dateorend_date(e.g. integer timestamps or booleans),.replace('Z', '+00:00')raisesAttributeError: 'int' object has no attribute 'replace'.
- In
- Empty / None / Whitespace-only search query:
- In
search_memories_tool:querylacked early validation for empty strings, whitespace, None, or non-string inputs. Callingsearch_memories_toolwith omitted or blank queries caused downstream failures or sent blank search vectors.
- In
Proposed Changes
- Safe Integer Coercion Helper (
_safe_int): Safely parse integers and numeric strings while rejecting booleans,None, and invalid text. - Resilient Config & UID Extraction (
_get_config_and_uid): Safely handle non-dict or absentconfigurabledictionaries and resolveuidfromconfigurable['user_id'], top-leveluser_id, oruidacrossconfigand_agent_config(). - Safe Date Formatting:
Validate that
start_dateandend_dateare strings before calling.replace('Z', '+00:00'). - Early Query Validation:
Validate
queryinsearch_memories_tool("Error: Search query cannot be empty") and annotate withOptional[str] = Noneto accept omitted arguments gracefully. - Hermetic Unit Tests:
Add
backend/tests/unit/test_memory_tools_guards.pyverifying 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)
Fix and hermetic test suite opened in PR #23232: https://github.com/BasedHardware/omi/pull/23232
Payout address (USDC Polygon / Base / Arbitrum):
0xC345C07229307d4f1c7935aD2cAe48e390215808
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! 🙏