omi icon indicating copy to clipboard operation
omi copied to clipboard

[Bounty proposal] fix(notion-app): search, list_pages, list_databases and query_database crash with TypeError on the JSON null the backend sends for omitted max_results

Open goldnbones opened this issue 2 months ago • 4 comments

Symptom

Every Notion listing tool fails on an ordinary request. "Search my Notion for the weekly plan", "what are my recent pages?", "list my databases", "show entries in my tasks database" all come back as:

Search failed: '<' not supported between instances of 'int' and 'NoneType'
Failed to list pages: '<' not supported between instances of 'int' and 'NoneType'
Failed to list databases: '<' not supported between instances of 'int' and 'NoneType'
Failed to query database: '<' not supported between instances of 'int' and 'NoneType'

The user does not have to mention a result count for this to happen.

Evidence

plugins/omi-notion-app/main.py has four copies of the same line (in tool_search, tool_list_pages, tool_list_databases, tool_query_database):

max_results = min(body.get("max_results", 10), 20)   # 50 in query_database

body.get("max_results", 10) only falls back to 10 when the key is absent, and the Omi backend never omits it. backend/utils/retrieval/tools/app_tools.py::_create_pydantic_model_from_schema turns every non-required manifest parameter into Optional[int] with Field(default=None), and _call_tool_endpoint forwards the model's kwargs verbatim as the JSON body. With the backend's pinned langchain-core==1.3.3, a StructuredTool built from that schema passes the defaulted fields through even when the LLM did not supply them:

# langchain-core 1.3.3, args_schema = create_model(max_results=(Optional[int], None))
{} -> {'max_results': None}
{'max_results': None} -> {'max_results': None}
{'max_results': '5'} -> {'max_results': 5}

So each handler receives {"uid": ..., "max_results": null, ...}, min(None, 20) raises TypeError, and the blanket except turns it into the strings above. get_page, create_page, update_page and append_content are unaffected because they take no optional integer.

Secondary: ints that do arrive are capped from above only, so max_results: 0 or a negative value is sent to Notion as page_size, which the API rejects (page_size must be 1..100).

Running the four handlers in a hermetic harness against main reproduces it (see the regression test below):

$ python3 test_max_results_inputs.py   # with main.py from origin/main
tool_search: Search failed: '<' not supported between instances of 'int' and 'NoneType'
tool_list_pages: Failed to list pages: '<' not supported between instances of 'int' and 'str'
tool_list_databases: Failed to list databases: '<' not supported between instances of 'int' and 'str'
tool_query_database: Failed to query database: '<' not supported between instances of 'int' and 'str'
AssertionError: -3 != 1   (negative page_size forwarded)
FAILED (failures=25)

Same defect class as #13931 (Whoop) and #13937 (Google Calendar); this is the Notion instance, with four affected tools.

Fix

Add one boundary helper in plugins/omi-notion-app/main.py:

def _coerce_int(value, default, minimum, maximum) -> int

that maps None/booleans/unparseable/overflowing values to the default, accepts ints and numeric strings, and clamps into [minimum, maximum], and use it at all four sites:

max_results = _coerce_int(body.get("max_results"), default=10, minimum=1, maximum=20)   # 50 for query_database

The manifest's documented defaults and caps (10 / 20, and 10 / 50 for query_database) are unchanged; they are now enforced instead of assumed, and the resulting page_size is always inside Notion's 1..100 range.

Tests

New hermetic suite plugins/omi-notion-app/test_max_results_inputs.py (stdlib-only, same double pattern as the existing test_main.py; no network) executes all four production handlers through the requests.post seam and decodes the posted body to assert:

  • max_results: null produces page_size: 10 and a rendered result (fails on main with the TypeError above);
  • numeric strings are coerced; 0/negative values are clamped to 1; oversized values are capped at each tool's documented maximum (20/20/20/50); unparseable and overflowing (1e309 → inf) values fall back to 10.

Registered as notion-app-max-results-input-tests in .github/checks-manifest.yaml (local + ci lanes).


Proposed Bounty Reward: $50.00 USD Bounty Payout Destination (PayPal): will be provided by email to [email protected] on payout

cc @josancamon19 @kodjima33

goldnbones avatar Sep 14 '26 21:09 goldnbones

I implemented the requested fix in PR #13957: https://github.com/BasedHardware/omi/pull/13957

It normalizes optional Notion max_results values (including JSON null, booleans, malformed/non-integral values, and numeric strings) and clamps valid values to each tool’s documented cap for search, list_pages, list_databases, and query_database. I verified all four handlers locally across those edge cases; the existing Notion tests pass 19/19.

I’m claiming the proposed $50 bounty. Reward and payment remain subject to maintainer review and the bounty terms.

cuentapraces07-ops avatar Sep 14 '26 22:09 cuentapraces07-ops

Same root cause as #13974 — _create_pydantic_model_from_schema types non-required params as Optional[...] with default None, and the backend forwards them as null to the app. Fix: add _drop_none() helper in app_tools.py to strip None-valued kwargs before forwarding. Also fix the 4 Notion handlers to use a _coerce_int boundary helper for limit clamping (see #13944 description for the exact fix).

devloper961-maker avatar Sep 15 '26 12:09 devloper961-maker

I have implemented a clean, hermetic fix with complete unit test coverage in PR #14173.

Summary of Changes

  • Safely coerces raw_max_results = body.get("max_results") with defensive integer parsing and fallback default 10 across all Notion listing/query tools (tool_search, tool_list_pages, tool_list_databases, and tool_query_database).
  • Clamps values to appropriate tool caps (20 for searches/pages/databases, 50 for queries) avoiding TypeError on explicit JSON null.
  • Added hermetic regression test suite plugins/omi-notion-app/test_max_results_limits.py (5 unit tests verifying all null/edge-case conditions). All 37 tests across the notion plugin pass cleanly.

PR: https://github.com/BasedHardware/omi/pull/14173 Payout Address (USDC Base/Polygon): 0xa709768e0B597df11b2B81AB7ea54EEacd2532D0

arawnslab-hash avatar Sep 16 '26 06:09 arawnslab-hash

Closing as already fixed on current main.

Current main notion listing tools use _coerce_int(max_results) for JSON null (no min(None) TypeError)

aryanorastar avatar Sep 20 '26 16:09 aryanorastar