omi
omi copied to clipboard
[Bounty proposal] fix(graph-tools): clamp hops, guard entity inputs, and harden UID resolution ($50 proposed)
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:
- Unbounded and uncoerced
hopsargument:- 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)passedhopsdirectly without capping or coercing string types like'2'or handlinghops=Noneor negative integers.
- The tool docstring explicitly promises:
- Unvalidated
entityparameter:- 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
entitycould pass massive payloads to downstream embedding and graph services.
- If LLMs pass
- Top-level UID fallback in
_resolve_uid(config):_resolve_uidonly parsedconfigurable.get('user_id'). Direct tool calls and integration harness configs that supply top-levelconfig['user_id']orconfig['uid']returnedNone.
- Log sanitization:
entityanduidlogging now usesanitize()consistently to avoid log-injection vulnerabilities.
Proposed Changes
- Hops Coercion & Clamping:
Safely coerce
hopsto int and clamp between 1 and 2 as documented (max(1, min(2, hops_val))). - Entity Validation & Bounds:
Validate non-empty string for
entityand bound maximum length to 256 characters. - UID Resolution Fallback:
Check
configurable.get('user_id') or configurable.get('uid') or cfg.get('user_id') or cfg.get('uid'). - Hermetic Unit Tests:
Add
backend/tests/unit/test_graph_tools_guards.pyverifying 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)
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)
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! 🙏