fix(retrieval): harden search_files_tool validation, config resilience, and numeric coercion

GH
5d ago
+294-10

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:

  1. Defensive Question Validation:

    • Validates question is a non-empty, non-whitespace string, preventing empty/invalid queries from being sent to downstream file-chat processors.
  2. Config Resilience & Top-Level / UID Fallbacks:

    • Safely extracts uid and chat_session_id from nested configurable as well as top-level config, supporting both user_id and uid keys.
    • Replaces fragile None.get() pattern with safe dict lookups, avoiding unhandled AttributeError.
    • Validates that both uid and chat_session_id are resolved before querying session data.
  3. file_ids Normalization & 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.
  4. 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, and Inf.
    • Clamps start time to >= 0.0 and ensures valid (start, end) spans.
  5. Hermetic Test Suite:

    • Added backend/tests/unit/test_file_tools_resilience.py with 11 comprehensive unit tests (11/11 passing hermetically).
    • Verified 100% backwards compatibility with test_file_tools_sanitization.py (4/4 passing).

Bounty Proposal ($50 USD)

  • Proposed Tier: $50 USD
  • Settlement: Available for backend & tool engineering contracts (mahmoudghazy2001@gmail.com).