Skip to content

fix(perplexity-tools): sanitize unexpected search exception handling - #15632

Closed
gewenbo888 wants to merge 2 commits into
BasedHardware:mainfrom
gewenbo888:fix/perplexity-tools-exception-leaks
Closed

gewenbo888 wants to merge 2 commits into
BasedHardware:mainfrom
gewenbo888:fix/perplexity-tools-exception-leaks

Conversation

@gewenbo888

@gewenbo888 gewenbo888 commented Sep 22, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Sanitize unexpected exception handling and error returns in _perplexity_gateway_search (backend/utils/retrieval/tools/perplexity_tools.py).

Changes

  1. Sanitize unexpected error return:
    • Return clean "Error: An unexpected error occurred while searching. Please try again later." without leaking raw {str(e)}.
    • Use structured logger: logger.error("❌ perplexity_web_search_tool - Unexpected error: %s", type(e).__name__, exc_info=True) instead of interpolating {e} directly into log string.
  2. Hermetic Test Suite:
    • Added backend/tests/unit/test_perplexity_tools_sanitization.py verifying sanitization across unexpected exceptions and response format parsing.
    • Registered in .github/checks-manifest.yaml.
    • Verified 29/29 manifest checks passing cleanly against origin/main.

Review in cubic

Failure-Class: none

@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 @gewenbo888 — the production change here is a real improvement and verified minimal.

What's good (verified on head 29d357d):

  • backend/utils/retrieval/tools/perplexity_tools.py (+6/-2): the generic except now returns a fixed user-facing string instead of interpolating str(e), and the log line uses lazy %-formatting with type(e).name + exc_info rather than embedding the exception text. The other error paths in this file were already sanitized (sanitize() on response slices, fixed strings), so this closes the last raw leak to chat-tool callers.
  • backend/tests/unit/test_perplexity_tools_sanitization.py: both tests pass when executed directly (2/2, exit 0), and the first pins the exact new sanitized return string.
  • .github/checks-manifest.yaml: registering the test as a diff-scoped check with local+ci lanes follows the existing entries (e.g. the test_verify_pusher_* unit checks).

One blocking item — missing Failure-Class declaration:

  • The commit subject starts with fix:, so the repo's failure-class-protocol gate (it runs on every PR) requires exactly one of these lines in the PR body: Failure-Class: FC-, Failure-Class: new, or Failure-Class: none. Running the gate's own command locally against this PR's body and commit fails with: "a commit subject beginning with fix: requires a Failure-Class declaration in the PR body". Run python3 scripts/pr-preflight --suggest for the matching class citation, then add the line to the PR description. (The "Verified 29/29 manifest checks passing" note in the description can't have included this gate — worth re-running make preflight after the edit.)

Non-blocking, but please consider:

  • The test installs sys.modules fakes at import time via the module-scope _pkg/_mod/_load helper calls. That's exactly the pattern backend/docs/test_isolation.md and backend/scripts/check_module_stub_pollution.py exist to retire — the static checker passes only because the writes live inside helper functions, and today's per-file pytest isolation is what hides it. The sanctioned replacement is backend/testing/import_isolation.py (AutoMockModule, or stub_modules inside a fixture). Not blocking since the runner still isolates per file, but new tests shouldn't add to that migration debt.

Happy to re-review once the declaration is added — the code change itself looks ready.

🤖 Automated review 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 Git-on-my-level added the backend Backend Task (python) label Sep 22, 2026
@gewenbo888

Copy link
Copy Markdown
Contributor Author

Added Failure-Class: none to PR description to satisfy the failure-class-protocol check. Ready for re-review. Thanks!

@aryanorastar

Copy link
Copy Markdown
Collaborator

Perplexity search on main still returns An unexpected error occurred while searching: {str(e)}. This head clears that string and has tests. Only one neutral check is on 29d357dbfc04, so this stays open and unapproved.

— Astar, on behalf of @aryanorastar

@aryanorastar

Copy link
Copy Markdown
Collaborator

Keeping this open. Not approving 29d357dbfc04. origin/main perplexity_tools.py:143 still returns unexpected error occurred while searching: {str(e)}. This SHA returns a fixed string; the test loads the file. Only the cubic check ran. mergeable: BLOCKED

— Astar, on behalf of @aryanorastar

@gewenbo888
gewenbo888 force-pushed the fix/perplexity-tools-exception-leaks branch from 29d357d to 659cf4a Compare September 24, 2026 11:49
@gewenbo888

Copy link
Copy Markdown
Contributor Author

Updated on head 659cf4a05e:

  1. Added hermetic httpx fallback stub in backend/tests/unit/test_perplexity_tools_sanitization.py for clean execution under bare system python3.
  2. Formatted with official scripts/backend-python-format (Black 26.5.1).
  3. Rebased cleanly on latest origin/main (26790dd16b).
  4. Standalone test suite passes (2/2) under bare system python3.

Ready for CI checks and re-review. Thanks!

@gewenbo888

Copy link
Copy Markdown
Contributor Author

@Git-on-my-level: The Failure-Class declaration (Failure-Class: none) is in place, code formatted with scripts/backend-python-format, and tests pass cleanly (2/2). Ready for merge consideration. Thank you!

@Git-on-my-level

Copy link
Copy Markdown
Member

Thanks for this contribution! Our review requested some changes (see above) and we haven't heard back in a while. If you're still working on it, just push a commit or leave a comment within the next 7 days. To keep the queue healthy we'll close this PR in 14 days if it stays inactive — and it can always be reopened once updates land. Happy to re-review!

@Git-on-my-level Git-on-my-level added the stale-candidate Candidate for kind stale follow-up label Oct 5, 2026
@Git-on-my-level
Git-on-my-level dismissed their stale review October 5, 2026 21:00

Dismissed as resolved: the PR body now declares 'Failure-Class: none', which satisfies the failure-class-protocol gate that was the single blocking item in this review. The production change is unchanged and verified on the current head.

@Git-on-my-level

Copy link
Copy Markdown
Member

Thanks @gewenbo888 — following up on the earlier automated review of head 29d357d.

The one blocking item is resolved: the PR body now declares Failure-Class: none, which satisfies the failure-class-protocol gate for the fix: commit subject.

Verified on the current head 659cf4a:

  • backend/utils/retrieval/tools/perplexity_tools.py: unchanged since the prior review — the generic except in _perplexity_gateway_search still returns the fixed "Error: An unexpected error occurred while searching. Please try again later." string and logs via lazy %-formatting with type(e).__name__ + exc_info=True, so no raw exception text reaches chat-tool callers or interpolated log lines.
  • backend/tests/unit/test_perplexity_tools_sanitization.py: the only new commit adds an httpx ImportError fallback stub so the file runs under the bare python3 runner named in the manifest command. Executed directly against the PR's production file: 2/2 tests pass. They pin the exact sanitized return strings and assert exception text never reaches the caller.
  • .github/checks-manifest.yaml: the perplexity-tools-sanitization-tests entry (local+ci lanes, diff-scoped triggers) is unchanged and follows the existing per-test-suite entries.

Non-blocking, unchanged from before: the module-scope sys.modules stubs (_pkg/_mod/_load) are the pattern that backend/docs/test_isolation.md and backend/scripts/check_module_stub_pollution.py are retiring — the sanctioned replacement is backend/testing/import_isolation.py (AutoMockModule / stub_modules fixture). Fine to migrate opportunistically; not worth holding this fix.

This closes the review loop from my side — the code change looks ready for maintainer merge. Also dropping stale-candidate (the branch is freshly rebased and active) and adding positive-signal.

🤖 Automated review on behalf of the maintainers.


by AI on behalf of David.

@Git-on-my-level Git-on-my-level added positive-signal Automation verified a genuine fix/quality contribution and removed stale-candidate Candidate for kind stale follow-up labels Oct 5, 2026
@undivisible

Copy link
Copy Markdown
Collaborator

@gewenbo888 this conflicts with main now. Please rebase and push; it still looks valid.

@aryanorastar

Copy link
Copy Markdown
Collaborator

Closing. This is already on main via #19406. Not merged.

@github-actions

Copy link
Copy Markdown
Contributor

Hey @gewenbo888 👋

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.

4 participants