Skip to content

fix(retrieval): sanitize raw exception leakage in traverse_knowledge_graph_tool - #15647

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

gewenbo888 wants to merge 2 commits into
BasedHardware:mainfrom
gewenbo888:fix/graph-tools-exception-leak

Conversation

@gewenbo888

@gewenbo888 gewenbo888 commented Sep 22, 2026 •

Copy link
Copy Markdown
Contributor

Summary

This PR sanitizes the error return in backend/utils/retrieval/tools/graph_tools.py (traverse_knowledge_graph_tool):

  • Returns Error traversing knowledge graph instead of appending raw {exc} to the error string.
  • Preserves full logging with traceback via logger.exception for server-side diagnosis while protecting the LLM context from raw connection details, database errors, or stack traces.

Testing

  • Added hermetic unit test suite backend/tests/unit/test_graph_tools_sanitization.py verifying exception sanitization and normal success flow.
  • Passed import isolation checks (check_module_stub_pollution.py).
  • Passed all 29/29 manifest checks via python3 .github/scripts/run_checks.py --lane local --base 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 for this — the fix itself is correct and well-targeted. Verified each changed file:

  • backend/utils/retrieval/tools/graph_tools.py — dropping {exc} from the returned string is the right seam: raw Neo4j/driver exceptions (connection URIs, internal hostnames, credential-bearing strings) no longer flow into LLM tool-result context, while logger.exception keeps the full server-side traceback. I also confirmed via repo code search that nothing consumes the old Error traversing knowledge graph: {exc} wording.
  • backend/tests/unit/test_graph_tools_sanitization.py — genuinely hermetic (sanctioned testing/import_isolation.py primitives, langchain stubbed). I ran it in a network-isolated stdlib-only sandbox: 2/2 pass, asserting secret_password / Neo4j / bolt:// stay out of the returned string.
  • .github/checks-manifest.yaml — graph-tools-sanitization-tests entry is additive, both lanes, triggers correct; follows the documented check-registration process.

One blocking item, and it's a PR-body edit rather than a code change:

Missing Failure-Class: declaration. The commit subject starts with fix:, and the failure-class-protocol check (runs on every PR, with the PR body) requires exactly one declaration line in the PR body. Running the repo's validator against this PR today reports missing_declaration:

python3 scripts/failure-class validate --base origin/main --head <head> --pr-body-file <body>

Your local --lane local run was green because that lane skips PR-body checks — this only surfaces in CI. Accepted forms (pick one, as a single line, no |):

Failure-Class: FC-<lower-kebab-slug>
Failure-Class: new
Failure-Class: none

Failure-Class: new also adds one .github/failure-classes/FC-<slug>.json definition (empty evidence_prs is fine — this PR is the evidence). bash scripts/pr-preflight --suggest prints paste-ready guidance.

Optional follow-up (separate PR, not here): search_memories_tool in backend/utils/retrieval/tools/memory_tools.py (~line 521) still returns Error performing memory search: {str(e)} — same leak class if you want to repeat the pattern there.

🤖 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

Knowledge-graph traversal on main still returns Error traversing knowledge graph: {exc}. This head clears that string and has tests. Only one neutral check is on 62f4cbb80cd5, so this stays open and unapproved.

— Astar, on behalf of @aryanorastar

@aryanorastar

Copy link
Copy Markdown
Collaborator

Keeping this open. Not approving 62f4cbb80cd5. origin/main ca828a8c617d graph_tools.py:80 still returns Error traversing knowledge graph: {exc}. SHA returns a fixed string and the test loads that file. CI rollup SUCCESS. mergeable: UNKNOWN.

— Astar, on behalf of @aryanorastar

@gewenbo888
gewenbo888 force-pushed the fix/graph-tools-exception-leak branch from 62f4cbb to bc01fdf Compare September 24, 2026 11:56
@gewenbo888

Copy link
Copy Markdown
Contributor Author

Updated on head bc01fdf2c2:

  1. Rebased cleanly on latest origin/main (26790dd16b), resolving merge conflict in .github/checks-manifest.yaml.
  2. Formatted with official scripts/backend-python-format (Black 26.5.1).
  3. Verified hermetic test suite passes under plain python3 (2/2).

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, cleanly rebased on origin/main, and unit tests pass cleanly (2/2). Ready for maintainer merge. Thank you!

@Git-on-my-level

Copy link
Copy Markdown
Member

Follow-up review on the rebased head (bc01fdf): the earlier blocking item — the missing Failure-Class: declaration — is resolved (the PR body now ends with Failure-Class: none), so I've dismissed that changes-requested review. Thanks for working through all of the feedback.

Re-verified each changed file on this head:

  • backend/utils/retrieval/tools/graph_tools.py — the except branch now returns the constant "Error traversing knowledge graph" instead of f"...{exc}". Raw Neo4j/driver exception text (bolt URIs, internal hostnames, credential-bearing strings) no longer flows into LLM tool-result context, while logger.exception keeps the full server-side traceback. Confirmed the same leak is still present on current main, so this is not superseded.
  • backend/tests/unit/test_graph_tools_sanitization.py — clean hermetic suite: it uses the sanctioned testing/import_isolation.py primitives, and the stub set covers every import of the module under test (langchain_core*, utils.memory.kg_graph_traversal, utils.retrieval.agentic fallback). The sanitization test asserts the exact constant return and that secret_password / Neo4j / bolt:// are absent; the success-path test covers format_traversal_result passthrough.
  • .github/checks-manifest.yaml — the graph-tools-sanitization-tests entry is additive, registered for both lanes, and its triggers correctly cover the three touched paths; the python3 <test path> command form matches existing entries.

One merge-blocking item remains, and it's mechanical: the PR is currently reporting merge conflicts — main has moved again and .github/checks-manifest.yaml needs one more rebase. The code change itself is unaffected.

Optional follow-up (separate PR, not here): search_memories_tool in backend/utils/retrieval/tools/memory_tools.py (~line 521) still returns Error performing memory search: {str(e)} — same leak class, same one-line pattern if you want to repeat it there.

🤖 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 positive-signal Automation verified a genuine fix/quality contribution label Sep 29, 2026
@Git-on-my-level
Git-on-my-level dismissed their stale review September 29, 2026 00:54

Dismissing as resolved: the blocking item in this review (missing Failure-Class: declaration in the PR body) is fixed on the current head — the PR body now ends with 'Failure-Class: none'. The code fix and tests were re-verified on bc01fdf.

@aryanorastar

Copy link
Copy Markdown
Collaborator

Closing. This is already on main via #19790. 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.

3 participants