Skip to content

fix(retrieval): sanitize unexpected exception leakage in perplexity search tool - #19601

Closed
Mateidslx wants to merge 1 commit into
BasedHardware:mainfrom
Mateidslx:fix/perplexity-search-tool-exception-sanitization
Closed

Mateidslx wants to merge 1 commit into
BasedHardware:mainfrom
Mateidslx:fix/perplexity-search-tool-exception-sanitization

Conversation

@Mateidslx

@Mateidslx Mateidslx commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor

Failure-Class: none

Description

Sanitize raw exception detail returned by _perplexity_gateway_search when an unexpected exception occurs. Internal database, auth, network exception details, and raw stack trace messages are logged via logger.error while returning a generic message to callers.

Changes

  • In �ackend/utils/retrieval/tools/perplexity_tools.py, mask raw str(e) in the generic exception handler with Error: An unexpected error occurred while searching. Please try again later..
  • Added isolated unit test �ackend/tests/unit/test_perplexity_search_sanitization.py with mock gateway raising runtime error.

Review in cubic

…earch tool

Failure-Class: none

Sanitize raw exception detail returned by _perplexity_gateway_search when an unexpected exception occurs. Internal database, auth, or network exception details are logged via logger.error while returning a generic message to callers. Includes an import-isolated unit test.
@Git-on-my-level

Copy link
Copy Markdown
Member

Thanks @Mateidslx - tight, well-targeted hardening fix.

  • backend/utils/retrieval/tools/perplexity_tools.py: the generic except Exception handler in _perplexity_gateway_search no longer interpolates str(e) into the tool's return value. This closes a path where internal exception detail (auth/db/network internals) could flow back into the chat response. It also makes the handler consistent with its siblings - httpx.TimeoutException (line 134), httpx.HTTPError (line 137), and the response-format errors (line 140) already return generic messages. Raw detail is still preserved in logger.error (line 142) for debugging, which is the right split.
  • backend/tests/unit/test_perplexity_search_sanitization.py: the new test stubs utils.http_client / utils.llm.gateway_client / utils.log_sanitizer, loads the module fresh via load_module_fresh, makes the mocked client raise RuntimeError("INTERNAL_DATABASE_CREDENTIALS_LEAK"), and asserts both the exact generic message and that the raw detail is absent. That directly exercises the changed line, with clean isolation and no network access.

One non-blocking observation: line 142's logger.error(f"... {e}") still writes raw exception text to logs, while other log lines in this file wrap response payloads in sanitize(). If exception messages in this service can ever carry sensitive payload, a small follow-up (sanitize that line, or log type(e).__name__ only, as line 136 does) would make the file fully consistent. Not required for this PR.

Checks are green (Backend unit suite, Backend Hermetic Merge Gate, Hygiene, Formatting). The formal approve/merge call stays with a human maintainer.


This feedback is AI-generated on behalf of the Omi maintainers; a human maintainer makes the final merge decision.


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 backend Backend Task (python) labels Sep 28, 2026
@aryanorastar

Copy link
Copy Markdown
Collaborator

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

@github-actions

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) positive-signal Automation verified a genuine fix/quality contribution

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants