Skip to content

fix(open-meteo-app): guard malformed forecast payloads - #14333

Merged
kodjima33 merged 4 commits into
BasedHardware:mainfrom
xyjk0511:fix/open-meteo-app-hardening
Sep 18, 2026
Merged

kodjima33 merged 4 commits into
BasedHardware:mainfrom
xyjk0511:fix/open-meteo-app-hardening

Conversation

@xyjk0511

@xyjk0511 xyjk0511 commented Sep 17, 2026 •

Copy link
Copy Markdown
Contributor

Forecast parsing assumed every documented container was present and correctly typed: payload, current, current_units, daily and daily_units were used as dicts, the daily series as lists, and each series item as a number. An upstream shape change, a null series, or a non-numeric entry raised an unhandled error instead of the N/A / no-data path the formatters already implement.

Normalize at the parse boundary with _as_dict, _as_list and _numeric_item, so the rendering code stays unchanged and well-formed responses render exactly as before.

Verification: python3 -m pytest plugins/omi-open-meteo-app/ -q -> 24 passed.

Failure-Class: none

xyjk added 3 commits September 17, 2026 03:07
Forecast parsing assumed every documented container was present and correctly\ntyped: payload, current, current_units, daily and daily_units were used as\ndicts, daily series as lists, and each series item as a number. An upstream\nshape change or a null series raised an unhandled error instead of the\nN/A / no-data path the formatters already implement.
Drives the real request/parse path with a fake httpx client serving non-dict
containers, null series, non-numeric entries and an undecodable body, so the
new guards are pinned rather than merely present.
Returning the original int/float instead of a coerced float keeps the existing
rendering byte-identical for integer-sourced values, and the widened helper
signatures match what the guards actually accept.
@Git-on-my-level

Copy link
Copy Markdown
Member

Verified against main and ran the suite myself (python3 -m pytest plugins/omi-open-meteo-app/ -q -> 24 passed, also green under unittest). The crash paths this guards are real on main.

plugins/omi-open-meteo-app/main.py

  • Base _resolve_location indexed results[0] after only a truthiness check, so results being a string/dict (or a place with non-numeric latitude/longitude) escaped as TypeError/AttributeError/KeyError — none caught by the handlers' except httpx.HTTPError, so the chat tool returned a raw 500. The new _require_dict/_json_body/_as_number boundary closes that, and subclassing MalformedResponseError from httpx.HTTPError reuses the existing clean-error handlers without touching them.
  • _as_number keeping the original int/float (rather than coercing to float) preserves rendering for well-formed payloads, and the bool rejection fixes a subtle old bug where a JSON true weather code looked up as 1 and rendered "mainly clear".
  • _format_place's str(part) fixes another latent crash: a non-string name/admin1/country previously raised TypeError inside ", ".join(...).
  • Normalizing at the parse boundary with rendering untouched is the right shape — _as_dict(payload.get("current")) degrades per-field to n/a placeholders instead of failing the whole response.

plugins/omi-open-meteo-app/test_main.py

  • The _fake_client_factory patching main.httpx.AsyncClient drives the real request/parse path end-to-end (not stubbed helpers), asserts both degradation (Temperature: n/a, per-day n/a) and clean-error outcomes (malformed JSON payload, geocoding results were not a JSON array, missing numeric coordinates), and pins the REQUEST_TIMEOUT_SECONDS propagation. Hermetic, no network — matches the repo's CI test rules.
  • test_non_numeric_daily_arrays_degrade_per_day mixing junk types across all five daily series is exactly the regression net this fix should ship with.

Notes, non-blocking:

Clean, cohesive hardening that finishes what #13923 started. Leaving the workflow approval and merge call to the maintainers.


AI-generated maintainer feedback posted on behalf of the Omi maintainers.


by AI on behalf of David — if you need David’s attention urgently, please @Git-on-my-level and escalate with need human response.

@kodjima33 kodjima33 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Open-meteo malformed-payload fix: root cause + tests but diff is 413 lines, exceeds 300-line scope gate = 3/5. Approve only.

@kodjima33
kodjima33 merged commit 90fb019 into BasedHardware:main Sep 18, 2026
29 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants