[Bounty proposal] fix(notification-tools): guard string hour coercion, fallback top-level config, and add database error resilience ($50 proposed)
Summary
In backend/utils/retrieval/tools/notification_settings_tools.py, invoking manage_daily_summary_tool exhibits several resilience and input coercion failure modes:
- String
hourTypeError: When LLMs invokeset_timewithhouras a string (e.g.,hour="21"orhour="9"), the check0 <= hour <= 23raises an unhandledTypeError: '<=' not supported between instances of 'int' and 'str'. - Boolean
hourfalse-positive: Becauseisinstance(True, int)isTruein Python, passinghour=Trueorhour=Falsepasses0 <= hour <= 23and silently schedules the user's daily reflection to 1 AM (1) or midnight (0). - Missing top-level config fallback:
user_idis only checked insidecfg.get('configurable', {}). In direct caller invocations or alternate runnables where configuration provides top-leveluser_id, the tool previously failed with"Error: User ID not found". - Action input validation:
If an LLM passes
action=Noneor a non-string object,action.lower().strip()crashes with an unhandledAttributeError. - Database error resilience:
Database calls to
notification_db(set_daily_summary_enabled,get_daily_summary_hour_local, etc.) lacked structured exception handling, letting transient connection or store errors escape as unhandled 500 crashes in the agent turn.
Proposed Changes
- Safe Hour Parsing (
_parse_hour): Implement_parse_hourhelper that safely coerces integers, integer floats (e.g.,21.0), and numeric digit strings ("21"), while cleanly rejecting booleans (True/False), floats with fractional parts, non-numeric strings,NaN, andinf. - Safe Hour Formatting (
_format_hour): Ensure_format_hournormalizes parsed hour bounds safely to friendly 12-hour format (12:00 AM (midnight),12:00 PM (noon),9:00 AM,9:00 PM). - Top-Level Configuration Fallback:
Support resolution of top-level
cfg.get('user_id')whenconfigurableis absent or lacksuser_id. - Action Validation & Exception Resilience:
Validate non-empty string action early and wrap database operations in
try/except Exception, logging failure context withlogger.errorand returning"Error: Failed to update notification settings. Please try again later.". - Hermetic Unit Tests:
Add
backend/tests/unit/test_notification_settings_tools_guards.pyverifying:_parse_hourwith ints, strings, integer floats, non-integer floats, booleans, NaNs, and text._format_hourconversion across 24h cycle.- Action validation rejecting None and empty strings.
- Resolution of top-level
user_id. - String hour coercion in
set_time. - Boolean hour rejection in
set_time. - Out-of-bounds hour rejection.
- Enabling when previously disabled.
- Graceful error message on database exceptions.
Bounty Proposal
Proposed bounty: $50 USDC
Payout address: 0xC345C07229307d4f1c7935aD2cAe48e390215808 (USDC Polygon/Base/Arbitrum)
PR created with comprehensive hermetic unit tests: https://github.com/BasedHardware/omi/pull/23206
Bounty proposal: $50 USDC
Payout address: 0xC345C07229307d4f1c7935aD2cAe48e390215808 (USDC Polygon/Base/Arbitrum)
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! 🙏