Skip to content

fix(retrieval-tools): sanitize internal exception disclosure in action_item_tools - #18486

Merged
aryanorastar merged 1 commit into
BasedHardware:mainfrom
naufalfx805-source:fix/action-items-exception-hardening
Oct 2, 2026
Merged

aryanorastar merged 1 commit into
BasedHardware:mainfrom
naufalfx805-source:fix/action-items-exception-hardening

Conversation

@naufalfx805-source

@naufalfx805-source naufalfx805-source commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

Description

Follow-up to PR #17827 addressing the observation by @Git-on-my-level:

"the same unsanitized pattern still exists in sibling retrieval tool modules — e.g. action_item_tools.py still has ~9 return f"...{e}" sites. A follow-up applying this same treatment there (and to any other chat-exposed tools) would finish the sweep."

This PR hardens error handling and closes all internal exception disclosure sites in backend/utils/retrieval/tools/action_item_tools.py.

Summary of Changes

  1. Sanitize Exception Details: Eliminated raw exception formatting (str(e), f"{e}"), date parsing ValueError leaks, and traceback.print_exc() calls in returned tool strings so internal database queries, credentials, and stack traces are never disclosed to the agent context or end users.
  2. Preserve Observability: Server-side observability is preserved and enhanced by passing exc_info=True to logger.error(...).
  3. Hermetic Test Suite: Added backend/tests/unit/test_action_item_tools_sanitization.py containing 12 unit tests validating error sanitization and hermetic module isolation across all 3 action item tools.
  4. Module Stub Hygiene: Fully compliant with backend/scripts/check_module_stub_pollution.py (0 violations).

Test Verification

Ran full hermetic pytest suite:

backend/tests/unit/test_action_item_tools_sanitization.py::TestGetActionItemsSanitization::test_invalid_start_date_sanitized PASSED
backend/tests/unit/test_action_item_tools_sanitization.py::TestGetActionItemsSanitization::test_invalid_end_date_sanitized PASSED
backend/tests/unit/test_action_item_tools_sanitization.py::TestGetActionItemsSanitization::test_invalid_due_start_date_sanitized PASSED
backend/tests/unit/test_action_item_tools_sanitization.py::TestGetActionItemsSanitization::test_invalid_due_end_date_sanitized PASSED
backend/tests/unit/test_action_item_tools_sanitization.py::TestGetActionItemsSanitization::test_config_error_sanitized PASSED
backend/tests/unit/test_action_item_tools_sanitization.py::TestGetActionItemsSanitization::test_db_exception_sanitized PASSED
backend/tests/unit/test_action_item_tools_sanitization.py::TestCreateActionItemSanitization::test_invalid_due_at_sanitized PASSED
backend/tests/unit/test_action_item_tools_sanitization.py::TestCreateActionItemSanitization::test_db_exception_sanitized PASSED
backend/tests/unit/test_action_item_tools_sanitization.py::TestCreateActionItemSanitization::test_config_error_sanitized PASSED
backend/tests/unit/test_action_item_tools_sanitization.py::TestUpdateActionItemSanitization::test_invalid_due_at_sanitized PASSED
backend/tests/unit/test_action_item_tools_sanitization.py::TestUpdateActionItemSanitization::test_db_exception_sanitized PASSED
backend/tests/unit/test_action_item_tools_sanitization.py::TestUpdateActionItemSanitization::test_config_error_sanitized PASSED

============================= 12 passed in 0.86s ==============================

Regression test suites:

backend/tests/unit/test_action_items_timezone.py (11 passed)
backend/tests/unit/test_action_item_date_validation.py (26 passed)

============================= 37 passed in 3.09s ==============================

Hygiene check:

python backend/scripts/check_module_stub_pollution.py
Checked 1296 backend test file(s); 0 violation(s).

Failure-Class: none

cc @kodjima33
Payout address (Base / EVM): 0x496e32ff3851cdb9146223a811e3d4f9218dd954

Review in cubic

@naufalfx805-source

Copy link
Copy Markdown
Contributor Author

Official bounty proposal submitted at #19363.

All 12 hermetic unit tests in backend/tests/unit/test_action_item_tools_sanitization.py are passing (12/12 PASS). Ready for maintainer review.

@Git-on-my-level

Copy link
Copy Markdown
Member

Thanks @naufalfx805-source — this is a solid, well-scoped follow-up to #17827 that closes out the remaining exception-disclosure sites called out in that review.

backend/utils/retrieval/tools/action_item_tools.py (+24/−28)

  • All nine leak sites are fixed: every returned error string now uses a generic message ("Error: Configuration error.", "Error retrieving action items. Please try again.", etc.) instead of interpolating str(e) or raw ValueError text, and both import traceback; traceback.print_exc() blocks are removed.
  • Observability is preserved and slightly improved — each except now logs with exc_info=True, so full stack traces land in structured server logs instead of agent-facing tool responses. Keeping caller-supplied values (e.g. {start_date}) echoed in validation messages is the right line to draw, since those are user input, not internal state.
  • I verified the full file at this head: no remaining str(e)/{e}/print_exc in returned strings. The one remaining f"Error: {scope_err}" near line 197 is a controlled domain message returned by apply_chat_scope_dates, not an exception leak — correctly left out of scope.

backend/tests/unit/test_action_item_tools_sanitization.py (+229, new)

  • 12 hermetic tests covering all three tools across config errors, date-parse errors, and DB exceptions, using the repo's load_module_fresh/stub_modules isolation. The negative assertions ("postgres://" not in res, planted secret markers absent) are exactly the right shape for this kind of hardening.

CI note: the failing Backend unit suite job is tests/unit/test_app_client_schema_inventory.py::test_inventory_openapi_route_response_decode_migration_complete — an OpenAPI decode-site ratchet unrelated to the two files changed here (that workflow is green on other branches from later in the week). It looks like a stale merge base; a rebase onto latest main should clear it.

This feedback is AI-generated on behalf of the Omi maintainers. Left for human maintainer review before merge.


by AI on behalf of David — if you need David’s attention urgently, please @Git-on-my-level and escalate with need human response.

@Git-on-my-level Git-on-my-level added the backend Backend Task (python) label Sep 28, 2026
…n_item_tools

- Sanitize raw exception formatting (str(e), f{e}) and date parsing ValueError leaks across get_action_items_tool, create_action_item_tool, and update_action_item_tool.
- Remove redundant traceback.print_exc() calls in favor of structured logging with exc_info=True to preserve backend observability.
- Add hermetic unit test suite backend/tests/unit/test_action_item_tools_sanitization.py with 12 test cases.

Failure-Class: none
@naufalfx805-source
naufalfx805-source force-pushed the fix/action-items-exception-hardening branch from a8ec405 to 7911956 Compare September 28, 2026 07:36
@Git-on-my-level

Copy link
Copy Markdown
Member

Incremental note on the earlier review of this head (commit 7911956): the CI failure flagged then — tests/unit/test_app_client_schema_inventory.py::test_inventory_openapi_route_response_decode_migration_complete — has cleared at this head; Backend Hermetic Merge Gate, Backend unit suite, Formatting, and Hygiene are all green. I also re-checked backend/utils/retrieval/tools/action_item_tools.py at this head: all nine exception-disclosure sites remain fixed, no str(e)/print_exc survives in returned strings, and the f"Error: {scope_err}" site near line 197 is still the controlled domain message from apply_chat_scope_dates, not a leak. Nothing further outstanding from my side — the only remaining step is human maintainer merge sign-off.

This feedback is AI-generated on behalf of the Omi maintainers.


by AI on behalf of David — if you need David’s attention urgently, please @Git-on-my-level and escalate with need human response.

@Git-on-my-level Git-on-my-level added the positive-signal Automation verified a genuine fix/quality contribution label Sep 29, 2026

@aryanorastar aryanorastar left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

791195622b95 origin/main ad94069 backend/utils/retrieval/tools/action_item_tools.py:289 returns Error retrieving action items: {str(e)} (create/update paths similar). This head returns static strings; test_action_item_tools_sanitization.py pins them. Hygiene + Backend Hermetic SUCCESS. mergeable_state blocked, not dirty. Earlier than later same-file open copies (#19556/#19680/#19734). Required checks on this head are green.

@aryanorastar
aryanorastar merged commit 4cf5ab7 into BasedHardware:main Oct 2, 2026
44 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backend Backend Task (python) positive-signal Automation verified a genuine fix/quality contribution

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants