fix(retrieval): harden search_files_tool validation, config resilience, and numeric coercion
GH
5d ago+294+294+012345678901234567890123456789-10-10-01234567890123456789
Failure-Class: none
Summary
Hardens backend/utils/retrieval/tools/file_tools.py (search_files_tool) against model hallucinated parameters, config structure variations, and numeric coercion faults:
-
Defensive Question Validation:
- Validates
questionis a non-empty, non-whitespace string, preventing empty/invalid queries from being sent to downstream file-chat processors.
- Validates
-
Config Resilience & Top-Level / UID Fallbacks:
- Safely extracts
uidandchat_session_idfrom nestedconfigurableas well as top-levelconfig, supporting bothuser_idanduidkeys. - Replaces fragile
None.get()pattern with safe dict lookups, avoiding unhandledAttributeError. - Validates that both
uidandchat_session_idare resolved before querying session data.
- Safely extracts
-
file_idsNormalization & Type Safety:- Normalizes single string arguments (e.g.
file_ids="file_123") into a single-element list, avoiding Python string character iteration bugs. - Accepts tuples, sets, and lists while stripping whitespace and filtering empty/None elements.
- Safely handles non-iterable arguments without raising
TypeError.
- Normalizes single string arguments (e.g.
-
Numeric Coercion & Bounds for Video Windows:
- Added
_parse_seconds()helper to parse numeric string arguments (e.g.start_seconds="10.5") to float while filtering out non-numeric inputs,NaN, andInf. - Clamps start time to
>= 0.0and ensures valid(start, end)spans.
- Added
-
Hermetic Test Suite:
- Added
backend/tests/unit/test_file_tools_resilience.pywith 11 comprehensive unit tests (11/11 passing hermetically). - Verified 100% backwards compatibility with
test_file_tools_sanitization.py(4/4 passing).
- Added
Bounty Proposal ($50 USD)
- Proposed Tier: $50 USD
- Settlement: Available for backend & tool engineering contracts (
mahmoudghazy2001@gmail.com).