[Bounty proposal] fix(whoop-app): get_workouts crashes with TypeError on the JSON null the backend sends for omitted days/max_results
Symptom
Asking Omi for Whoop workouts ("show my recent workouts", "what did I train this week?") fails with:
Failed to get workouts: '<' not supported between instances of 'int' and 'NoneType'
This happens on the ordinary call, not an edge case: the user does not have to say anything about a day range or a count.
Evidence
plugins/omi-whoop-app/main.py, tool_get_workouts:
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. 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:
$ python - # 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} and min(None, 30) raises TypeError, which the handler's blanket except turns into the error string above. The other Whoop tools are unaffected because their only optional parameter (date) is guarded with if date_str:.
Secondary: values that do arrive as ints are not bounded from below. days: 0 produces an empty date window (start == end) and max_results: 0 / negative is forwarded to WHOOP as limit, which its collection endpoints reject.
Running the handler in a hermetic harness reproduces it directly (see the regression test below):
$ python3 plugins/omi-whoop-app/test_workouts_input_coercion.py # on main
FAIL: test_json_null_optionals_fall_back_to_defaults
AssertionError: "Failed to get workouts: '<' 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=4)
Fix
Add one boundary helper in plugins/omi-whoop-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]. 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-whoop-app/test_workouts_input_coercion.py (stdlib-only; stubs requests/dotenv, no network) executes the production tool_get_workouts handler through the requests.get seam and asserts:
{"days": null, "max_results": null}produces a 7-day window withlimit=10and a formatted workout (fails onmainwith the TypeError above);- 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 whoop-app-workouts-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
Opened #13962 for this: days and max_results now go through one boundary helper, _coerce_int(value, default, minimum, maximum), so the JSON null the backend forwards for an omitted optional parameter resolves to the documented default instead of reaching min() as None. Non-positive and oversized values are clamped to the documented 1..30 / 1..50 bounds.
Hermetic regression suite plugins/omi-whoop-app/test_workouts_input_coercion.py (9 tests) drives the production handler through the requests.get seam: 13 failures + 10 errors against unchanged main (reproducing '<' not supported between instances of 'int' and 'NoneType' end-to-end), all pass with the fix. Registered in .github/checks-manifest.yaml for the local and ci lanes. scripts/pr_preflight.py --lane local reported all 15 selected checks passing.
I have implemented a clean, hermetic fix with full unit test coverage in PR #14175.
Summary of Changes
- Safely coerces
raw_days = body.get("days")(default 7, clamped to [1, 30]) andraw_max_results = body.get("max_results")(default 10, clamped to [1, 50]) intool_get_workoutsavoidingTypeErroron explicit JSONnull. - Added hermetic regression test suite
plugins/omi-whoop-app/test_get_workouts.py(4 unit tests verifying null parameters, custom ranges, clamped bounds, and non-integer inputs).
PR: https://github.com/BasedHardware/omi/pull/14175
Payout Address (USDC Base/Polygon): 0xa709768e0B597df11b2B81AB7ea54EEacd2532D0
Closing as already fixed on current main.
Merged #14175; current main get_workouts uses raw_days is not None else 7 + test_get_workouts.py