Skip to content

fix(retrieval): sanitize raw exception leakage in action items and memory tools - #19661

Closed
Mateidslx wants to merge 4 commits into
BasedHardware:mainfrom
Mateidslx:fix/action-items-and-memory-tools-exception-sanitization
Closed

Mateidslx wants to merge 4 commits into
BasedHardware:mainfrom
Mateidslx:fix/action-items-and-memory-tools-exception-sanitization

Conversation

@Mateidslx

@Mateidslx Mateidslx commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor

Failure-Class: none

Summary

Sanitizes raw unexpected exception details across action item and memory retrieval tools:

  • get_action_items_tool
  • create_action_item_tool
  • update_action_item_tool
  • search_memories_tool

Changes

  • Replace raw {str(e)} error returns with safe, clean error strings while logging error types internally for debugging.
  • Add hermetic unit tests verifying that sensitive internal exception details are never returned to agent callers.

@Mateidslx
Mateidslx force-pushed the fix/action-items-and-memory-tools-exception-sanitization branch 4 times, most recently from f8dff3e to 21bb83b Compare September 28, 2026 23:20
…mory tools

Failure-Class: none
Sanitize raw unexpected exception disclosure across get_action_items_tool, create_action_item_tool, update_action_item_tool, and search_memories_tool.
@Mateidslx
Mateidslx force-pushed the fix/action-items-and-memory-tools-exception-sanitization branch from 21bb83b to efbed4a Compare September 28, 2026 23:20

@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 @Mateidslx — sanitizing raw exception details out of agent-facing tool output is a worthwhile hardening change, and the production-side edits here look right. The blocking problems are in the new tests and one undocumented behavior change.

backend/utils/retrieval/tools/action_item_tools.py — Good: the three except blocks now return clean strings ('Error retrieving action items', 'Error creating action item', 'Error updating action item') while still logging the full error via logger.error/traceback, so debuggability is preserved.

backend/utils/retrieval/tools/memory_tools.py — The search_memories_tool sanitization matches the pattern above. One concern: this PR also prepends memory_id: to the agent-visible evidence suffixes in get_memories_tool (~line 326) and search_memories_tool (~line 493). That's a real behavior change to the evidence format the agent sees, it isn't mentioned in the PR description, and it has no test coverage. Please either move it to its own PR with tests, or keep it here but document it in the description and add a test for the suffix format.

backend/tests/unit/test_action_item_and_memory_tools_sanitization.py — All four tests currently fail in CI (Backend unit shard 2/4), for three separate reasons in the test code itself:

  1. The first three tests call action_item_tools.get_action_items_tool(...) etc. directly, but these are langchain @tool-decorated StructuredTool objects, so CI hits TypeError: 'StructuredTool' object is not callable. Call the underlying function via .func, as tests/unit/test_calendar_tools_sanitization.py does (e.g. get_calendar_events_tool.func(...)).
  2. The update test patches action_items_db.update_action_item_description, which doesn't exist — the tool calls action_items_db.update_action_item (action_item_tools.py:635). The search test patches utils.retrieval.tools.memory_tools.memory_service, which also doesn't exist — MemoryService(db_client=firestore_db) is instantiated locally (memory_tools.py:443). Patch utils.memory.memory_service.MemoryService instead.
  3. The assertion strings don't match the implementation: the tests expect 'Error: Failed to retrieve action items.' / 'Error: Failed to create action item.' / 'Error: Failed to update action item.' / 'Error searching memories: Failed to search memories.', but the tools (in this PR) return 'Error retrieving action items', 'Error creating action item', 'Error updating action item', and 'Error searching memories'. Align the assertions with the actual strings.

Once the tests are fixed and green, this should be a clean, low-risk hardening change — happy to re-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.

@Git-on-my-level Git-on-my-level added the backend Backend Task (python) label Sep 29, 2026
@Mateidslx

Copy link
Copy Markdown
Contributor Author

Updated! Reverted the memory_id: prefix in memory_tools.py back to original behavior, switched all tests to invoke underlying functions via .func(...), and aligned assertion strings with the exact sanitized returns ('Error retrieving action items', 'Error creating action item', 'Error updating action item', 'Error searching memories').

@Git-on-my-level
Git-on-my-level dismissed their stale review September 30, 2026 03:19

Dismissed: all three concerns from this review are resolved on head 4374d4f — tests now invoke tools via .func, mock targets corrected (action_items_db.update_action_item, MemoryService.search), assertions aligned, and the memory_id evidence-suffix change was reverted in 895601c. New tests pass in CI.

@Git-on-my-level

Copy link
Copy Markdown
Member

Thanks @Mateidslx — all three blocking points from the earlier review are resolved on this head, and the new tests now pass in CI (Backend unit shard 3/4):

test_action_item_and_memory_tools_sanitization.py — Tools are invoked via .func (commit a699a13), assertions match the actual error strings, and the mock targets are now real: action_items_db.get_action_item/update_action_item and MemoryService.search (commit 4374d4f). All four tests green.

memory_tools.py — The undocumented memory_id: evidence-suffix change was cleanly reverted (commit 895601c); the net diff here is exactly one line, the sanitized 'Error searching memories' return. search_memories_tool keeps logging the full error before returning the clean string.

action_item_tools.py — The three except blocks return clean strings while logger.error/traceback still capture detail, so debuggability is preserved.

Note on CI: the red 'Backend unit suite' is not from this PR. test_paywall_reconnect_gate.py (7 failures, websocket close code 1011 vs 1003) fails identically on main, and the single test_memory_use.py param case is in a module this diff doesn't touch and doesn't import. Adding ci-failing-pre-existing for visibility.

This is a worthwhile hardening change — internal exception details (DB errors, connection strings) no longer reach agent-visible tool output. Leaving 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 positive-signal Automation verified a genuine fix/quality contribution ci-failing-pre-existing CI check failing for reasons pre-existing/unrelated to this PR (red main) labels Sep 30, 2026
@Git-on-my-level

Copy link
Copy Markdown
Member

Thanks @Mateidslx — verified this end to end at the current head, and it's a solid, security-positive change.

What I checked per file:

  • backend/utils/retrieval/tools/action_item_tools.py — the three edited returns (get_action_items_tool, create_action_item_tool, update_action_item_tool) are exactly the generic except Exception handlers; the detail still reaches logger.error/traceback server-side, so debuggability is preserved.
  • backend/utils/retrieval/tools/memory_tools.py — search_memories_tool's final handler now returns a constant; the str(e) built just above it (L522) goes to logger.info only, never the returned string. Correct.
  • backend/tests/unit/test_action_item_and_memory_tools_sanitization.py — hermetic, and the patch targets (action_items_db.get/create/update_action_item, MemoryService.search) match the module aliases the production code actually uses. The sentinel-not-in-output assertions are exactly the right shape for this fix.

Two optional follow-ups, non-blocking: the date-format ValueError handlers in both files still echo {str(e)} — those derive from user-supplied date strings rather than internal state, so lower risk, but the same sanitization could be applied for consistency; and action_item_tools.py:186 (Configuration error - {str(config_error)}) is one step from internal details in the same pattern.

Note on CI: the "Backend unit suite" failure is the fork-PR gate (annotations say a maintainer needs to add ci:full and re-run), not a test failure — consistent with the existing ci-failing-pre-existing label.

Leaving the merge call to a human maintainer; adding ci:full would confirm the fork-gated backend suites if desired.


Feedback generated by AI on behalf of the 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

Copy link
Copy Markdown
Member

Closing per the maintainer's bounty-policy ruling (2026-10-01).

The maintainer reviewed this batch of exception-sanitization PRs: the underlying issues are real but minor, and the ask (per-PR bounties on a templated sweep) doesn't fit how bounties are awarded here. The genuinely valuable fix in this family — Firebase ID token verification error reflection on the OAuth token endpoint (#16029) — has been cherry-picked and re-landed with full credit at #20168. The remainder of the sweep is being closed rather than paid or merged piecemeal.

If you believe a specific PR in this set addresses a serious issue (user-visible crash, data exposure beyond error-detail hygiene, security impact beyond internal message leakage), comment on it and a maintainer will take a direct look — that path stays open.

Thanks for the contributions; the oauth fix was good work.

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

@github-actions

github-actions Bot commented Oct 1, 2026

Copy link
Copy Markdown
Contributor

Hey @Mateidslx 👋

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) ci-failing-pre-existing CI check failing for reasons pre-existing/unrelated to this PR (red main) positive-signal Automation verified a genuine fix/quality contribution

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants