Repository navigation
fix(file-tools): harden search_files_tool input validation, numeric coercion, and configurable resilience (#23292) - #23832
Conversation
Git-on-my-level
left a comment
There was a problem hiding this comment.
One fix needed before merge: the new session-type check breaks an existing test suite (passes on main, fails on this head). The hardening direction itself is right and the new tests are good.
Blocking
backend/utils/retrieval/tools/file_tools.py:193—elif isinstance(session_data, ChatSession):breaksbackend/tests/unit/test_file_tools_sanitization.py::test_search_files_provider_rejection_does_not_leak_provider_text. That suite loads file_tools withmodels.chat.ChatSessionstubbed as a MagicMock, so the isinstance call raisesTypeError: isinstance() arg 2 must be a type, the generic handler swallows it, and the provider-rejection path returns the generic error instead of "The file could not be processed." Verified by running the suite at this head (4/4 pass on main, 1 fails here). Sincechat_db.get_chat_session_by_idis typedOptional[Dict[str, Any]]and always returns a normalized dict, theChatSessionand finalelsebranches are unreachable in production — simplest fix is to drop them and keep the dict branch (plus the created_at fallback).
What's good (verified)
_parse_seconds(file_tools.py:58) fixes a real crash: oldmax(0.0, (end_seconds or 0) - 5)raised TypeError on string inputs likeend_seconds="15". Bool/NaN/Inf rejection and negative clamping are correct, and theis not Nonechecks also stopend_seconds=0.0from being treated as missing.file_idsstr→list wrap (file_tools.py:199) fixes the per-character iteration bug from #23292; the empty-question guard (line 177) and top-level config fallback are sensible.- All 8 tests in
backend/tests/unit/test_file_tools_coercion_and_guards.pypass hermetically (I ran them); the mock sessions withoutcreated_atalso exercise the newcreated_atfallback implicitly.
Nits (non-blocking)
created_atfallback injectsdatetime.now(timezone.utc)— a fabricated timestamp; harmless here since onlyfile_idsis used downstream, but a short comment ("legacy docs missing created_at") would help.- Blank-line spacing around
_parse_seconds(3 before / 1 after; PEP 8 wants two). - Unused imports in the new test file:
pytest,ChatSession.
For maintainers: this is a second open implementation of #23292 alongside #23290 (opened by the issue/bounty author) — an explicit call is needed on which claim to take.
- Security: no new attack surface; error sanitization is preserved (the TypeError path returns a generic message, nothing leaks).
- Blast radius:
search_files_toolfor agentic chat file queries — if wrong, file/video questions return generic errors instead of accurate ones.
USER IMPACT: file and video questions with string or invalid timestamps no longer error out, and empty questions get clear guidance; no negative user-facing change once the test regression is fixed.
Still wanted as a reviewer: (1) remove or make test-safe the isinstance branch so the existing sanitization suite passes, (2) a CI run of tests/unit/test_file_tools_* (this PR triggered no backend workflow — I ran them locally: new suite 8/8 pass, sanitization 3/4), (3) an explicit test asserting the created_at fallback value. Code-wise this is one small fix away; the duplicate-claim arbitration vs #23290 is left for human maintainer review.
by AI on behalf of David — if you need David’s attention urgently, please @Git-on-my-level and escalate with need human response.
…oercion, and configurable resilience (BasedHardware#23292)
…t, and format code
2af0730 to
b49cd54
Compare
|
@Git-on-my-level Addressed all review feedback for PR #23832:
Ready for merge! Bounty Requisites:
|
|
@Git-on-my-level Thank you for the detailed and constructive review! All requested changes have been addressed and verified:
Unified Payout Address: |
|
Since the prior automated review: addressed (the The production change is correct and the earlier blocking issue is fixed; one test-harness issue remains before merge. Verified on this head (both suites run in an ephemeral worktree):
Remaining issue (test isolation, not a production defect): the new file's module-level
Security: no new surface; the exception-sanitization guarantees the existing suite checks are preserved by the production diff. USER IMPACT: users get a clear reply ("Please provide a question about the files.") instead of silent errors when the chat agent sends empty questions or odd timestamps; no other behavior change. To close out:
Leaving for human maintainer review: first-time-contributor bounty PR closing #23292; once the test-suite coexistence is settled it just needs a maintainer sign-off before merge. by AI on behalf of David — if you need David’s attention urgently, please @Git-on-my-level and escalate with |
Dismissed: the blocking concern from the prior automated review — the isinstance(session_data, ChatSession) branch breaking test_file_tools_sanitization.py — is resolved on head b49cd54 (branch removed; suite passes standalone). A separate, non-blocking test-isolation note is in the latest comment.
…tion with sanitization suite
|
@Git-on-my-level Updated!
Ready for maintainer merge! |
|
Since the prior automated review: addressed (the suite now loads file_tools through testing.import_isolation's stub_modules + load_module_fresh — verified on this head: all 9 tests pass and the new file no longer writes sys.modules at module scope, so the earlier collection conflict with test_file_tools_sanitization.py is gone) · still open (nothing) · newly noted (one semantic nuance and one verification limit, below — neither blocking). The production change is correct and both prior close-out items are done; nothing blocking remains from my side. Verified on this head (ephemeral worktree, backend venv):
Newly noted (not blocking): with file_ids whose entries are all whitespace/non-string (e.g. [" "]), clean_file_ids ends up empty and the tool now falls through to searching ALL session files, where the old code returned "The specified files are not available in this chat session." Garbage file_ids now widens rather than narrows the search — defensible normalization, but worth a deliberate maintainer choice and a pinning test. USER IMPACT: users asking about chat files with oddly-typed inputs (string timestamps, a single file id passed as a string, legacy sessions missing created_at) now get answers instead of error strings or a broken tool call. Still wanted: a test pinning the empty-after-cleaning file_ids behavior (whitespace-only → search-all) so the semantic choice stays intentional, and coverage for uid unresolved while chat_session_id is present. Leaving for human maintainer sign-off before merge — maintainer product call wanted on the garbage-file_ids → search-all semantics and on adopting #23292's hardened behavior set. by AI on behalf of David |
|
@Git-on-my-level Thank you for the insightful follow-up and verification! Added both requested pinning test cases in
All 11 tests pass cleanly: $ pytest backend/tests/unit/test_file_tools_coercion_and_guards.py
============================= 11 passed in 0.56s ============================= |
|
Solid hardening of search_files_tool — the failure modes from #23292 are addressed correctly and the test coverage is genuinely hermetic. No blocking issues found; two judgment calls below for a maintainer. backend/utils/retrieval/tools/file_tools.py
backend/tests/unit/test_file_tools_coercion_and_guards.py
Security: no new network/exec surface; identity-resolution fallback noted above. Performance/cost: not material for this diff. What I'd still want as a reviewer: green CI on this head, and maintainer confirmation that the top-level user_id fallback and the uid=None-when-configurable-present path are both intended. Leaving for human maintainer review on those two points. by AI on behalf of David — if you need David’s attention urgently, please @Git-on-my-level and escalate with |
|
@Git-on-my-level Thank you for the thorough verification and positive review! To address the two review points:
|
|
My verdict on the code is unchanged since the earlier review of this head: the production change is correct and well-covered. What's new below is CI/process, not code. New items since the last review:
Context: the underlying issue #23292 was closed by a maintainer ("we aren't doing bounties at the moment — thanks for the fix"), so the bounty itself won't pay out. The fix remains welcome on its merits — I verified nothing equivalent has landed on main, so this PR is not superseded. Code stands as reviewed: USER IMPACT: fewer dead-ends when asking the chat agent about uploaded files — malformed video timestamps and legacy sessions without created_at no longer error out, and an empty question gets a clear prompt instead of a failure. Blast radius: single backend chat file-search tool; no external calls, no dependency changes. Still leaving the top-level by AI on behalf of David — if you need David’s attention urgently, please @Git-on-my-level and escalate with |
|
Since the prior automated review: addressed (the body now declares Verdict: no blocking issues remain; this PR is ready for maintainer sign-off.
Security: no new external calls or data flows — pure input validation on existing paths. Blast radius: one retrieval tool; malformed inputs now return guidance strings instead of raising. USER IMPACT: asking about chat files with an empty/malformed query or bad video timestamps gets a graceful reply instead of a tool error; whitespace-only file ids now search all session files instead of returning "not available" — a deliberate behavior change pinned by tests. What I'd still want as a reviewer: the repo CI lanes (Hygiene/Formatting/Detect Changes) stay skipped for external contributors until first approval, so this suite has only run hermetically — Actions will exercise it on approval. The two judgment calls from my earlier review stand for a maintainer: the search-all fallback semantics for malformed by AI on behalf of David — if you need David’s attention urgently, please @Git-on-my-level and escalate with |
|
Hey @Dimank92 👋 Thank you so much for taking the time to contribute to Omi! We truly appreciate you putting in the effort to submit this pull request. After careful review, we've decided not to merge this particular PR. Please don't take this personally — we genuinely try to merge as many contributions as possible, but sometimes we have to make tough calls based on:
Before your next PR, please skim:
If this was declined for direction or taste, maintainers should cite an invariant ID or open a proposed one — ask if that citation is missing. Your contribution is still valuable to us, and we'd love to see you contribute again in the future! If you'd like feedback on how to improve this PR or want to discuss alternative approaches, please don't hesitate to reach out. Thank you for being part of the Omi community! |
Summary
Closes #23292
Resolves input validation errors, TypeError exceptions, and configurable dictionary fragility in
backend/utils/retrieval/tools/file_tools.py:_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."Please provide a question about the files."whenquestionis empty, whitespace, or non-string.ChatSession(**session_data)deserialization by ensuringcreated_atdefaults to UTC now if omitted in Firestore.config['configurable']['user_id']and top-levelconfig['user_id']/chat_session_id.file_idsby automatically wrapping them into a list.backend/tests/unit/test_file_tools_coercion_and_guards.py(100% passing).Verification
Product invariants affected
none
UI evidence
UI-Evidence: none -- internal logic and test suite only; no UI change.
Failure class (fixes)
Failure-Class: none