omi icon indicating copy to clipboard operation
omi copied to clipboard

[Bounty proposal] fix(notification-tools): guard string hour coercion, fallback top-level config, and add database error resilience ($50 proposed)

Open Dimank92 opened this issue 1 month ago • 2 comments

Summary

In backend/utils/retrieval/tools/notification_settings_tools.py, invoking manage_daily_summary_tool exhibits several resilience and input coercion failure modes:

  1. String hour TypeError: When LLMs invoke set_time with hour as a string (e.g., hour="21" or hour="9"), the check 0 <= hour <= 23 raises an unhandled TypeError: '<=' not supported between instances of 'int' and 'str'.
  2. Boolean hour false-positive: Because isinstance(True, int) is True in Python, passing hour=True or hour=False passes 0 <= hour <= 23 and silently schedules the user's daily reflection to 1 AM (1) or midnight (0).
  3. Missing top-level config fallback: user_id is only checked inside cfg.get('configurable', {}). In direct caller invocations or alternate runnables where configuration provides top-level user_id, the tool previously failed with "Error: User ID not found".
  4. Action input validation: If an LLM passes action=None or a non-string object, action.lower().strip() crashes with an unhandled AttributeError.
  5. 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

  1. Safe Hour Parsing (_parse_hour): Implement _parse_hour helper 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, and inf.
  2. Safe Hour Formatting (_format_hour): Ensure _format_hour normalizes parsed hour bounds safely to friendly 12-hour format (12:00 AM (midnight), 12:00 PM (noon), 9:00 AM, 9:00 PM).
  3. Top-Level Configuration Fallback: Support resolution of top-level cfg.get('user_id') when configurable is absent or lacks user_id.
  4. Action Validation & Exception Resilience: Validate non-empty string action early and wrap database operations in try/except Exception, logging failure context with logger.error and returning "Error: Failed to update notification settings. Please try again later.".
  5. Hermetic Unit Tests: Add backend/tests/unit/test_notification_settings_tools_guards.py verifying:
    • _parse_hour with ints, strings, integer floats, non-integer floats, booleans, NaNs, and text.
    • _format_hour conversion 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)

Dimank92 avatar Oct 22 '26 04:10 Dimank92

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)

Dimank92 avatar Oct 22 '26 04: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