[Bounty proposal] fix(demand-processing): guard None configurable and coerce bounded hours/limit ($50 proposed)
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
-
Fatal
AttributeError: 'NoneType' object has no attribute 'get': At line 18:uid = config.get('configurable', {}).get('user_id')When
configis a dictionary with'configurable': None(standard in LangChain runnable configs before sub-runnable initialization),config.get('configurable', {})returnsNone. Calling.get('user_id')onNonecauses an immediate unhandledAttributeError, failing tool execution. -
Fatal
ValueError: hours must be 1..6 and limit 1..20on string or out-of-range tool inputs: Inprocess_recent_conversations(config: RunnableConfig, hours: int = 6, limit: int = 20): When an LLM agent generates arguments as strings (e.g.,hours="6"orlimit="20"), or passes values outside bounds (e.g.hours=24,limit=50),process_recent()inbackend/utils/conversations/demand_processing.pyenforces: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
hoursto [1, 6] andlimitto [1, 20]. -
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 extractconfigurableanduser_idsupporting both nestedconfigurableand top-leveluser_id, raisingPermissionError('authenticated owner required')if invalid. - Parse and safely coerce
hoursandlimitto integers, clampinghoursto[1, 6]andlimitto[1, 20]. - Add an exception boundary returning JSON error details if
process_recentfails. - 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
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.
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! 🙏