omi icon indicating copy to clipboard operation
omi copied to clipboard

[Bounty proposal] fix(graph-tools): clamp hops, guard entity inputs, and harden UID resolution ($50 proposed)

Open Dimank92 opened this issue 1 month ago • 2 comments

Summary

In backend/utils/retrieval/tools/graph_tools.py, several input coercions and edge cases in traverse_knowledge_graph_tool can cause invalid queries or runtime issues:

  1. Unbounded and uncoerced hops argument:
    • The tool docstring explicitly promises: hops: How many relationship hops to expand (1 or 2; values above 2 are capped). However, traverse_knowledge_graph(uid, entity, hops=hops) passed hops directly without capping or coercing string types like '2' or handling hops=None or negative integers.
  2. Unvalidated entity parameter:
    • If LLMs pass entity=None, empty string, whitespace, or non-string objects, unhandled queries are forwarded down to graph retrieval rather than returning a clean error message.
    • Unbounded length for entity could pass massive payloads to downstream embedding and graph services.
  3. Top-level UID fallback in _resolve_uid(config):
    • _resolve_uid only parsed configurable.get('user_id'). Direct tool calls and integration harness configs that supply top-level config['user_id'] or config['uid'] returned None.
  4. Log sanitization:
    • entity and uid logging now use sanitize() consistently to avoid log-injection vulnerabilities.

Proposed Changes

  1. Hops Coercion & Clamping: Safely coerce hops to int and clamp between 1 and 2 as documented (max(1, min(2, hops_val))).
  2. Entity Validation & Bounds: Validate non-empty string for entity and bound maximum length to 256 characters.
  3. UID Resolution Fallback: Check configurable.get('user_id') or configurable.get('uid') or cfg.get('user_id') or cfg.get('uid').
  4. Hermetic Unit Tests: Add backend/tests/unit/test_graph_tools_guards.py verifying hops clamping, entity guards, length truncation, UID resolution, and error handling (9 tests, 100% pass).

Bounty Proposal

Proposed bounty: $50 USDC Payout address: 0xC345C07229307d4f1c7935aD2cAe48e390215808 (USDC Polygon/Base/Arbitrum)

Dimank92 avatar Oct 22 '26 05:10 Dimank92

I have implemented the complete fix and hermetic unit tests in PR #23242.

  • Pull Request: https://github.com/BasedHardware/omi/pull/23242
  • Unit Tests: 9/9 passing hermetically
  • Payout Address: 0xC345C07229307d4f1c7935aD2cAe48e390215808 (USDC Polygon/Base/Arbitrum)

Dimank92 avatar Oct 22 '26 05:10 Dimank92

Thanks for putting this together. We aren't doing bounties at the moment, so we're closing the bounty proposal issues for now — thanks for the fix! 🙏

undivisible avatar Oct 22 '26 11:10 undivisible