Repository navigation
fix(retrieval-tools): sanitize unexpected exceptions in external and app tools - #19406
Conversation
|
Reviewed - this is a clean, well-scoped hardening change. Verified per file:
I also confirmed all four leak sites are still present on Two minor, non-blocking notes:
Thanks for the tight scope and the sentinel-based tests. Leaving the merge call to the maintainers given the overlapping open PRs. (Automated review on behalf of the maintainer team.) by AI on behalf of David — if you need David’s attention urgently, please @Git-on-my-level and escalate with |
aryanorastar
left a comment
There was a problem hiding this comment.
1b4e54665c0a origin/main ad94069 still returns str(e) in perplexity_tools.py:143 and app_tools.py:440, and sanitize(str(e)) from fetch_url at web_tools.py:300. This head replaces unexpected paths with fixed messages; test_external_tools_sanitization.py pins them. Later #19616/#19601 are same-file copies. CI green. Head 1b4e54665c0a63208067074f91416d20041843a0. Required checks on this head are green.
…tools Prevent internal exception leakage in perplexity_tools, web_tools, graph_tools, and app_tools by returning sanitized error messages and enabling exc_info=True for backend logging. Add comprehensive hermetic unit tests.
1b4e546 to
7746030
Compare
Five unit files fail on current main. Each one passed on its own PR's base and broke when main moved underneath it; none is a product regression. - test_request_context.py (#19738): tested the JIT budget surface that #22209 removed from llm_gateway/gateway/request_context.py. Keep the request-id tests; drop the tests for removed code. - test_users_joan_followup_tombstone_guard.py (#19867): called delete_person_endpoint, but the joan followup route is delete_followup_question_endpoint. - test_developer_from_segments_idempotency.py (#21265): process fakes rejected the trigger=CLIENT_FINALIZE kwarg the router passes since #19788. - test_external_tools_sanitization.py (#19406): the stubbed utils package lacked utils.generated_compute (#21488) and utils.model_text. Stub the default-off gate as disabled and load the stdlib-only model_text for real. - test_batch_upload_storage.py: the database.vector_db stub lacked delete_action_item_vectors_batch, which merge_conversations imports since #15953. Failure-Class: none Co-Authored-By: Claude Opus 5.5 <[email protected]>
) * fix(backend): restore pyright-clean main after #22207 and #22326 Main's backend unit shards fail the enforced pyright lane: - database/desktop_previews.py (#22207): 16 reportUnnecessaryIsInstance errors. The runtime guards stay; they move into validators that take `object` (_payload, _string, _expected_generation, _datetime), so the checks are meaningful to pyright. Public signatures, error messages and check order are unchanged. - utils/sync/pipeline.py:process_segment (#22326 on top of #22452): "code is too complex to analyze". Behaviour-neutral split: the two identical cap-hold defer blocks become one hold_for_cap closure, and the final-pass / speaker-identification block moves to _assign_segment_speakers with the same exception handling. Failure-Class: none Co-Authored-By: Claude Opus 5.5 <[email protected]> * test(backend): repair unit tests that drifted from main across merges Five unit files fail on current main. Each one passed on its own PR's base and broke when main moved underneath it; none is a product regression. - test_request_context.py (#19738): tested the JIT budget surface that #22209 removed from llm_gateway/gateway/request_context.py. Keep the request-id tests; drop the tests for removed code. - test_users_joan_followup_tombstone_guard.py (#19867): called delete_person_endpoint, but the joan followup route is delete_followup_question_endpoint. - test_developer_from_segments_idempotency.py (#21265): process fakes rejected the trigger=CLIENT_FINALIZE kwarg the router passes since #19788. - test_external_tools_sanitization.py (#19406): the stubbed utils package lacked utils.generated_compute (#21488) and utils.model_text. Stub the default-off gate as disabled and load the stdlib-only model_text for real. - test_batch_upload_storage.py: the database.vector_db stub lacked delete_action_item_vectors_batch, which merge_conversations imports since #15953. Failure-Class: none Co-Authored-By: Claude Opus 5.5 <[email protected]> --------- Co-authored-by: Claude Opus 5.5 <[email protected]>
Summary
Prevents sensitive internal runtime exception leakage (stack traces, internal socket errors, database connection strings) to chat users and LLM context across external and app retrieval tools:
backend/utils/retrieval/tools/perplexity_tools.py:f"Error: ... {str(e)}".exc_info=Truetologger.errorfor full backend observability.backend/utils/retrieval/tools/web_tools.py:fetch_url_toolto return generic user message'Error: Failed to fetch the URL. Please verify the URL or try again later.'.exc_info=Truetologger.error.backend/utils/retrieval/tools/graph_tools.py:traverse_knowledge_graph_toolto return"Error traversing knowledge graph. Please try again later.".backend/utils/retrieval/tools/app_tools.py:{e}and{str(e)}.exc_info=Truetologger.error.Verification & Testing
Added hermetic test suite in
backend/tests/unit/test_external_tools_sanitization.py:test_perplexity_unexpected_exception_sanitized: PASStest_fetch_url_unexpected_exception_sanitized: PASStest_traverse_knowledge_graph_unexpected_exception_sanitized: PASStest_call_tool_endpoint_unexpected_exception_sanitized: PASStest_mcp_tool_unexpected_exception_sanitized: PASSAll 5 unit tests pass hermetically in 0.20s.
Failure-Class: none
cc @kodjima33 @aryanorastar
Payout address (Base / EVM):
0x496e32ff3851cdb9146223a811e3d4f9218dd954