fix(file-tools): harden search_files_tool input validation, numeric coercion, and configurable resilience (#23292)
DI
6h ago+185+185+012345678901234567890123456789-10-10-01234567890123456789
Summary
Closes #23292
Resolves input validation errors, TypeError exceptions, and configurable dictionary fragility in backend/utils/retrieval/tools/file_tools.py:
- 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 throwingValueErrororTypeError. - Empty Question Guard: Returns clear guidance
"Please provide a question about the files."whenquestionis empty, whitespace, or non-string. - Session Missing created_at Fallback: Protects
ChatSession(**session_data)deserialization by ensuringcreated_atdefaults to UTC now if omitted in Firestore. - Config & UID Fallback: Supports both
config['configurable']['user_id']and top-levelconfig['user_id']/chat_session_id. - Single File ID Coercion: Handles string
file_idsby automatically wrapping them into a list. - 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