Skip to content

fix(retrieval): sanitize raw system exceptions in action item tools - #19680

Closed
xyz-is-best wants to merge 3 commits into
BasedHardware:mainfrom
xyz-is-best:fix/action-item-tools-exception-sanitization
Closed

xyz-is-best wants to merge 3 commits into
BasedHardware:mainfrom
xyz-is-best:fix/action-item-tools-exception-sanitization

Conversation

@xyz-is-best

@xyz-is-best xyz-is-best commented Sep 29, 2026 •

Copy link
Copy Markdown

Summary

Sanitizes unhandled database and serialization exceptions across action item retrieval and mutation tools under backend/utils/retrieval/tools/action_item_tools.py.

Problem Statement

Action item retrieval tools did not uniformly sanitize unexpected database connection dropped events or malformed entity attributes, leading to unhandled 500-level tracebacks surfaced to client interfaces.

Solution & Changes

  • Enforces defensive exception handling across action item query and update workflows.
  • Logs unexpected underlying failures via standard error loggers while returning structured, graceful fallback messages to the agent.
  • Adds dedicated unit tests verifying that corrupted action item records or database connection faults do not crash the tool execution loop.

Verification

  • Verified with unit tests covering simulated database timeouts and schema mismatches.

Review in cubic

Failure-Class: FC-exception-leak

@Git-on-my-level Git-on-my-level left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks @xyz-is-best — the core change here is verified correct, and it closes a real leak: until now the three action-item tools returned f-strings built from raw exception text straight to the agent. Details below, plus three items that need another push before this can merge.

What's good (verified against current main):

  • backend/utils/retrieval/tools/action_item_tools.py: all three handlers (get_action_items_tool, create_action_item_tool, update_action_item_tool) now log the exception through utils.log_sanitizer.sanitize() and return a fixed fallback message instead of "Error ...: {str(e)}". This matches the established sanitization pattern already on main for the file and calendar tools. Dropping the traceback.print_exc() call also removes raw stack traces from stdout. The import is valid — backend/utils/log_sanitizer.py exists on current main and your branch is up to date with it.
  • backend/tests/unit/test_action_item_tools_sanitization.py: all three new tests ran and passed (3/3) in this head's CI run, asserting the Firestore document path never reaches the tool result and that an ERROR log is still emitted.

What needs fixing before merge:

  1. Formatting check fails: the pinned black would reformat backend/tests/unit/test_action_item_tools_sanitization.py (e.g. the multi-line assert (res == \"...\") blocks fit on one line). Please run the repo's black over the file.
  2. Hygiene check fails: the PR body is missing the required Failure-Class: FC-<lower-kebab-slug> declaration (failure-class-protocol). Please add it to the description.
  3. Backend unit shards 1/3 fail — this is a test-isolation artifact rather than a defect in your production change, but it does need a fix in this PR. tests/unit/test_action_item_date_validation.py, tests/unit/test_action_items_timezone.py and tests/unit/test_action_item_tool_result_bound.py load action_item_tools.py through _load_module_from_file after replacing the whole utils package with an empty stub (_stub_package("utils") with path=[]). The new from utils.log_sanitizer import sanitize import therefore fails at collection with ModuleNotFoundError: No module named 'utils.log_sanitizer'. Fix: add "utils.log_sanitizer" to those files' stubbed-module lists with a passthrough sanitize (e.g. a stub whose sanitize is str), the same way utils.conversations.render is stubbed.

One non-blocking observation: sanitize() only masks token-like strings that contain digits/base64 characters, plus emails — pure-alpha identifiers pass through. So for an error like "Firestore connection failed: /databases/default/documents/users//action_items" with an all-alpha uid, the masked log line still contains the full document path. The tool response no longer leaks it (the important part); you may want to pin that log-side behavior in a test or note it as best-effort.

Requesting changes for items 1–3; happy to re-review after the push. The production-code path itself was verified correct against current main.

Automated maintainer-review feedback 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 backend Backend Task (python) label Sep 29, 2026
@aryanorastar

Copy link
Copy Markdown
Collaborator

Closing as a later copy of #19661. The earlier pull request is the one to keep.

@github-actions

Copy link
Copy Markdown
Contributor

Hey @xyz-is-best 👋

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:

  • Project standards — Ensuring consistency across the codebase
  • User needs — Making sure changes align with what our users need
  • Code best practices — Maintaining code quality and maintainability
  • Project direction — Keeping aligned with our product principles and locked invariants

Before your next PR, please skim:

  • PRODUCT.md — product north star
  • Product invariants — locked rules (shared chat, memory tiers, agent control plane, integrations, brand)

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backend Backend Task (python)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants