omi icon indicating copy to clipboard operation
omi copied to clipboard

[Bounty proposal] fix(demand-processing): guard None configurable and coerce bounded hours/limit ($50 proposed)

Open Dimank92 opened this issue 1 month ago • 2 comments

Summary

In backend/utils/retrieval/tools/demand_processing_tools.py, the process_recent_conversations LangChain tool allows the chat agent to trigger processing of recent conversations prior to answering about fresh events.

Runtime Crashes & Vulnerabilities

  1. Fatal AttributeError: 'NoneType' object has no attribute 'get': At line 18:

    uid = config.get('configurable', {}).get('user_id')
    

    When config is a dictionary with 'configurable': None (standard in LangChain runnable configs before sub-runnable initialization), config.get('configurable', {}) returns None. Calling .get('user_id') on None causes an immediate unhandled AttributeError, failing tool execution.

  2. Fatal ValueError: hours must be 1..6 and limit 1..20 on string or out-of-range tool inputs: In process_recent_conversations(config: RunnableConfig, hours: int = 6, limit: int = 20): When an LLM agent generates arguments as strings (e.g., hours="6" or limit="20"), or passes values outside bounds (e.g. hours=24, limit=50), process_recent() in backend/utils/conversations/demand_processing.py enforces:

    if type(hours) is not int or not 1 <= hours <= 6 or type(limit) is not int or not 1 <= limit <= 20:
        raise ValueError('hours must be 1..6 and limit 1..20')
    

    This unhandled exception crashes the agent execution cycle instead of safely coercing and bounding hours to [1, 6] and limit to [1, 20].

  3. Missing Error Boundary: If downstream Redis operations or processing calls fail, the exception propagates unhandled through the LangChain tool interface instead of returning structured JSON output.

Fix

  • In process_recent_conversations, safely extract configurable and user_id supporting both nested configurable and top-level user_id, raising PermissionError('authenticated owner required') if invalid.
  • Parse and safely coerce hours and limit to integers, clamping hours to [1, 6] and limit to [1, 20].
  • Add an exception boundary returning JSON error details if process_recent fails.
  • Add hermetic unit test suite in backend/tests/unit/test_demand_processing_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 19:10 Dimank92

Resolved in PR #23105. Added _get_user_id configurable guard, integer coercion, boundary clamping for hours/limit, and full unit test suite in backend/tests/unit/test_demand_processing_tools.py.

Dimank92 avatar Oct 21 '26 19: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 11:10 undivisible