fix(file-tools): harden search_files_tool input validation, numeric coercion, and configurable resilience (#23292)

DI
6h ago
+185-10

Summary

Closes #23292

Resolves input validation errors, TypeError exceptions, and configurable dictionary fragility in backend/utils/retrieval/tools/file_tools.py:

  1. Timestamp Numeric Coercion: Implements safe _parse_seconds(val) helper to parse video timestamps in seconds, correctly handling string integers, floats, negative values (clamping to 0.0), while rejecting non-numerics, booleans, NaN, and Inf without throwing ValueError or TypeError.
  2. Empty Question Guard: Returns clear guidance "Please provide a question about the files." when question is empty, whitespace, or non-string.
  3. Session Missing created_at Fallback: Protects ChatSession(**session_data) deserialization by ensuring created_at defaults to UTC now if omitted in Firestore.
  4. Config & UID Fallback: Supports both config['configurable']['user_id'] and top-level config['user_id'] / chat_session_id.
  5. Single File ID Coercion: Handles string file_ids by automatically wrapping them into a list.
  6. Tests: Added 8 hermetic unit tests in backend/tests/unit/test_file_tools_coercion_and_guards.py (100% passing).

Verification

tests\unit\test_file_tools_coercion_and_guards.py ........ [100%]
======================= 8 passed in 6.77s =======================

Payout Address

  • Wallet: 0xC345C07229307d4f1c7935aD2cAe48e390215808
  • Network: Polygon / Base / Arbitrum / Stellar