omi
omi copied to clipboard
[Bounty proposal] fix(file-tools): guard string end_seconds coercion, fallback top-level session config, and validate question ($50 proposed)
Summary
In backend/utils/retrieval/tools/file_tools.py, invoking search_files_tool exhibits several resilience and input-type failure modes:
- String
end_secondsTypeError: When LLM tool calls supplyend_secondsas a string (e.g.,"15") withstart_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) - 5raises an unhandledTypeError: unsupported operand type(s) for -: 'str' and 'int'. - Missing top-level config fallback:
user_idandchat_session_idare only checked incfg.get('configurable', {}). In standard LangChain/LangGraph invocations or alternate runnables where configuration provides top-leveluser_idorchat_session_id, the tool previously defaulted to empty strings without fallback. - 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. - Empty question validation: Empty or whitespace-only questions were passed down to vision/multimodal LLM processing instead of returning an immediate validation message.
- Single string
file_idscoercion: If an LLM supplies a single stringfile_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
- Timestamp Sanitization (
_parse_seconds): Add helper_parse_secondsto safely coerceint,float, or numeric strings to finite non-negative floats, while safely ignoringNone, booleans, non-numeric strings, and infinities/NaNs. - Safe Window Calculation:
Safely compute
(start, end)using sanitized numeric floats, preventing string subtractionTypeError. - Top-Level Configuration Resolution:
Support fallback to top-level
user_idandchat_session_idincfgif not present underconfigurable. - Empty Question & Single File ID Guards:
Validate non-empty question string and normalize single-string
file_idsto a list. - Hermetic Unit Tests:
Add
backend/tests/unit/test_file_tools_coercion_and_guards.pycovering:_parse_secondsbehavior with ints, numeric strings, negative bounds, booleans, NaNs, and text.- Rejection of empty/whitespace questions.
- Top-level
user_id/chat_session_idresolution. - String
end_secondscoercion withoutTypeError. - Single string
file_idscoercion.
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/23200
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! 🙏