omi icon indicating copy to clipboard operation
omi copied to clipboard

[Bounty proposal] fix(google-calendar-app): list_events crashes with TypeError on the JSON null the backend sends for omitted days/max_results

Open goldnbones opened this issue 2 months ago • 1 comments

Symptom

Asking Omi about the calendar ("what's on my calendar this week?", "any meetings tomorrow?") through the Google Calendar app fails with:

Failed to list events: '<' not supported between instances of 'int' and 'NoneType'

This is the ordinary call: the user does not have to mention a day range or a count.

Evidence

plugins/omi-google-calendar-app/main.py, tool_list_events:

uid = body.get("uid")
days = min(body.get("days", 7), 30)
max_results = min(body.get("max_results", 10), 50)

body.get("days", 7) only falls back to 7 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(days=(Optional[int], None), max_results=(Optional[int], None))
{} -> {'days': None, 'max_results': None}
{'days': None} -> {'days': None, 'max_results': None}
{'days': '3'} -> {'days': 3, 'max_results': None}

So the plugin receives {"uid": ..., "days": null, "max_results": null}, min(None, 30) raises TypeError, and the handler's blanket except turns it into the error above. The other Google Calendar tools are unaffected: none of them compares an optional integer.

Secondary: ints that do arrive are capped from above only. days: 0 yields timeMin == timeMax (always "No events"), and max_results: 0 / negative is forwarded as maxResults, which the Calendar API rejects.

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

$ python3 plugins/omi-google-calendar-app/test_list_events_inputs.py   # main
FAIL: test_json_null_optionals_fall_back_to_defaults
AssertionError: "Failed to list events: '<' not supported between instances of 'int' and 'NoneType'" is not None
FAIL: test_non_positive_values_are_clamped_to_one
AssertionError: -2 != 1
FAILED (failures=5)

Same defect class as the Whoop get_workouts report (#13931); this is the Google Calendar instance.

Fix

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

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

that maps None/booleans/unparseable values to the default, accepts ints and numeric strings, and clamps into [minimum, maximum], and use it for both inputs:

days = _coerce_int(body.get("days"), default=7, minimum=1, maximum=30)
max_results = _coerce_int(body.get("max_results"), default=10, minimum=1, maximum=50)

The manifest's documented defaults and caps (7/30 days, 10/50 results) are unchanged; they are now enforced instead of assumed.

Tests

New hermetic suite plugins/omi-google-calendar-app/test_list_events_inputs.py (stdlib-only; stubs requests/dotenv, no network) executes the production tool_list_events handler through the requests.get seam and asserts:

  • {"days": null, "max_results": null} produces a request to /calendars/primary/events with a 7-day timeMin/timeMax window and maxResults=10, and a formatted event list (fails on main with the TypeError above); with no events it answers "No events in the next 7 days.";
  • numeric strings are coerced; 0/negative values are clamped to 1; oversized values are capped at 30/50; unparseable values fall back to defaults.

Registered as google-calendar-app-list-events-input-tests in .github/checks-manifest.yaml (local + ci lanes). This plugin had no registered test before.


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 have implemented a clean, hermetic fix with full unit test coverage in PR #14174.

Summary of Changes

  • Safely coerces raw_days = body.get("days") (default 7, clamped to [1, 30]) and raw_max_results = body.get("max_results") (default 10, clamped to [1, 50]) in tool_list_events avoiding TypeError on explicit JSON null.
  • Added hermetic regression test suite plugins/omi-google-calendar-app/test_list_events.py (4 unit tests verifying null parameters, custom ranges, clamped bounds, and non-integer inputs).

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

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