omi icon indicating copy to clipboard operation
omi copied to clipboard

[Bounty proposal] fix(file-tools): guard string end_seconds coercion, fallback top-level session config, and validate question ($50 proposed)

Open Dimank92 opened this issue 1 month ago • 2 comments

Summary

In backend/utils/retrieval/tools/file_tools.py, invoking search_files_tool exhibits several resilience and input-type failure modes:

  1. String end_seconds TypeError: When LLM tool calls supply end_seconds as a string (e.g., "15") with start_seconds=None, line 203 previously executed: start = start_seconds if start_seconds is not None else max(0, (end_seconds or 0) - 5) In Python, ("15" or 0) - 5 raises an unhandled TypeError: unsupported operand type(s) for -: 'str' and 'int'.
  2. Missing top-level config fallback: user_id and chat_session_id are only checked in cfg.get('configurable', {}). In standard LangChain/LangGraph invocations or alternate runnables where configuration provides top-level user_id or chat_session_id, the tool previously defaulted to empty strings without fallback.
  3. Unhandled non-numeric / malformed timestamps: Non-numeric strings or invalid float values (such as nan, inf, or malformed text) passed into timestamp fields can cause unexpected math or conversion errors in downstream file window slicing.
  4. Empty question validation: Empty or whitespace-only questions were passed down to vision/multimodal LLM processing instead of returning an immediate validation message.
  5. Single string file_ids coercion: If an LLM supplies a single string file_ids="file_123" instead of a list, iterating or testing membership treats the string as a sequence of single characters unless normalized to [file_ids].

Proposed Changes

  1. Timestamp Sanitization (_parse_seconds): Add helper _parse_seconds to safely coerce int, float, or numeric strings to finite non-negative floats, while safely ignoring None, booleans, non-numeric strings, and infinities/NaNs.
  2. Safe Window Calculation: Safely compute (start, end) using sanitized numeric floats, preventing string subtraction TypeError.
  3. Top-Level Configuration Resolution: Support fallback to top-level user_id and chat_session_id in cfg if not present under configurable.
  4. Empty Question & Single File ID Guards: Validate non-empty question string and normalize single-string file_ids to a list.
  5. Hermetic Unit Tests: Add backend/tests/unit/test_file_tools_coercion_and_guards.py covering:
    • _parse_seconds behavior with ints, numeric strings, negative bounds, booleans, NaNs, and text.
    • Rejection of empty/whitespace questions.
    • Top-level user_id / chat_session_id resolution.
    • String end_seconds coercion without TypeError.
    • Single string file_ids coercion.

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/23200

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