Skip to content

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

Open
ducanh3005 wants to merge 1 commit into
BasedHardware:mainfrom
ducanh3005:fix/issue-15633-perplexity-tools-sanitization
Open

ducanh3005 wants to merge 1 commit into
BasedHardware:mainfrom
ducanh3005:fix/issue-15633-perplexity-tools-sanitization

Conversation

@ducanh3005

Copy link
Copy Markdown
Contributor

Closes #15633

Failure-Class: none

Summary

Rebases and completes the unexpected search exception sanitization in backend/utils/retrieval/tools/perplexity_tools.py:

  • Replaces f-string exception interpolation (f"... {e}") in _perplexity_gateway_search with lazy %s logging of type(e).__name__ (exc_info=True) while returning the sanitized user-facing error message ("Error: An unexpected error occurred while searching. Please try again later.").
  • Adds hermetic unit tests in backend/tests/unit/test_perplexity_tools_sanitization.py with setUpClass/tearDownClass sys.modules restoration so no module-scope stubs leak across test files.
  • Registers perplexity-tools-sanitization-tests in .github/checks-manifest.yaml.

Verification

  • python3 backend/tests/unit/test_perplexity_tools_sanitization.py -v (2/2 passing)
  • python3 backend/scripts/check_module_stub_pollution.py --files backend/tests/unit/test_perplexity_tools_sanitization.py (0 violations)

@ducanh3005

Copy link
Copy Markdown
Contributor Author

Payout & Verification Info (@ducanh3005)

  • Author GitHub: @ducanh3005 (ynsuperit2@gmail.com)
  • Bounty Recipient Wallet (EVM - Base / Polygon / Arbitrum): 0xdF4Ff9D2f45f99f11A90b16F277D4B7EddDB72A5
  • Solana Wallet: 3peh7eRyemZQ3ppVC9CeUeEbHq6aADmwqvSTRnQf17b7
  • Preferred Token: USDC

@Git-on-my-level Git-on-my-level added the backend Backend Task (python) label Oct 24, 2026
@Git-on-my-level

Copy link
Copy Markdown
Member

Verdict: the production change is correct and nicely scoped — the failing "Backend unit suite" check is pre-existing main noise, not this diff; it just needs a rebase so the new test actually runs in CI.

Per file:

  • backend/utils/retrieval/tools/perplexity_tools.py — the final except Exception handler in _perplexity_gateway_search now logs type(e).__name__ via lazy %s formatting instead of interpolating str(e) into the log message, while exc_info=True keeps the full traceback server-side for diagnostics. This matches the TimeoutException/HTTPError handlers just above it, which already log only the type name, and the user-facing return string is unchanged. Good consistency.
  • backend/tests/unit/test_perplexity_tools_sanitization.py — hermetic unittest whose stub list matches the module's actual imports exactly (httpx, langchain_core.tools, utils.executors / generated_compute / http_client / llm.gateway_client / log_sanitizer / model_text), with sys.modules restored in tearDownClass. Both tests assert the sanitized return string, and the exception test pins the exact logger call. The ENCRYPTION_SECRET default is the same dummy value used across the existing unit suite.
  • .github/checks-manifest.yaml — the new perplexity-tools-sanitization-tests entry follows the adjacent entry's shape and its triggers correctly cover the source file, the test, and the manifest itself.

On the failing check: all six backend unit shards abort at the pyright step in "Run authoritative backend unit contract" with 5 errors, every one in files this PR does not touch (omi_tools.py:64, result_bounds.py:40/65/67, generate_2025.py:102). Those errors were present at your merge base and have since been suppressed on main (type-ignores from #23410); Backend unit suite is green on current main. Because the shard aborts at pyright, your new test has not actually executed in CI on this head.

Security: this is the material dimension here — str(e) can carry gateway/credential fragments, and this change removes it from the interpolated log line while preserving the traceback for internal logs.

USER IMPACT: none — users see the same "Error: An unexpected error occurred while searching. Please try again later." message; only internal log formatting changes.

Action items:

  1. Rebase (or update the branch) onto current main so the [Bounty proposal] fix(retrieval): harden result_bounds edge cases and apply context bounding to omi_tools ( proposed) #23410 pyright suppressions land and the suite — including your new test — actually runs.
  2. After the rebase, confirm the perplexity-tools-sanitization check goes green.

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.

This branch has not been deployed

No deployments
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.

[Bounty Request] : Sanitize unexpected search exception leaks in perplexity chat tool

2 participants