[Bounty proposal] fix(conversation-tools): guard string numeric coercion, fallback top-level config, and sanitize transcript segments ($50 proposed)
Summary
In backend/utils/retrieval/tools/conversation_tools.py, several input coercions and edge cases in get_conversations_tool and search_conversations_tool lead to runtime exceptions or failed retrievals:
- String numeric coercion failure (
TypeError: '<' not supported between instances of 'int' and 'str'):get_conversations_tool: Iflimit,offset, ormax_transcript_segmentsare passed as numeric strings by an LLM agent (e.g.limit="10"), bounds checks likemin(max_transcript_segments, 1000)andmin(limit, 5000)raiseTypeError.search_conversations_tool:min(limit, 20)andmin(max_transcript_segments, 1000)raiseTypeErrorwhen values are strings.
- Missing top-level config and UID resolution:
Both
get_conversations_toolandsearch_conversations_toolextractedconfigurable = cfg.get('configurable')and immediately calledconfigurable.get('user_id'). WhenconfigurableisNone(or callers pass top-level{"user_id": "..."}), this crashes withAttributeError: 'NoneType' object has no attribute 'get'and prematurely aborts with"Error: Configuration not available". - Empty / None / Whitespace-only search query:
In
search_conversations_tool:- If
queryis empty, whitespace-only, orNone,query.strip()raisesAttributeError: 'NoneType' object has no attribute 'strip', and vector embedding queries are dispatched with empty strings.
- If
- Non-string date values crash on
.replace(): If an agent passes non-string types forstart_dateorend_date(e.g. integer timestamps or booleans),start_date.replace('Z', '+00:00')raisesAttributeError. - Non-dict / None transcript segment crash in
all_person_idscollection: In bothget_conversations_toolandsearch_conversations_tool, extracting person IDs via[s.get('person_id') for s in segments if s.get('person_id')]crashes withAttributeErroriftranscript_segmentscontainsNoneor non-dict items. statusesparameter list support:statuses.split(',')crashes withAttributeError: 'list' object has no attribute 'split'if passed as a list of strings (e.g.['processing', 'completed']).
Proposed Changes
- Safe Integer Coercion Helper (
_safe_int): Add_safe_int(val, default)to 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, oruidacrossconfigandagent_config_context. - Early Query Validation:
Validate
queryinsearch_conversations_tooland annotate withOptional[str] = Noneto accept omitted arguments gracefully. - Safe Date & Status Parsing:
Validate that
start_dateandend_dateare strings before calling.replace(). Support both comma-separated strings and lists/tuples forstatuses. - Guarded Person ID Extraction:
Ensure
isinstance(s, dict)check befores.get('person_id'). - Hermetic Unit Tests:
Add
backend/tests/unit/test_conversation_tools_guards.pyverifying integer coercion, top-level UID resolution, query validation, date string validation, transcript segment resilience, and status parsing.
Bounty Proposal
Proposed bounty: $50 USDC
Payout address: 0xC345C07229307d4f1c7935aD2cAe48e390215808 (USDC Polygon/Base/Arbitrum)
Fix and hermetic test suite opened in PR #23220: https://github.com/BasedHardware/omi/pull/23220
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! 🙏