[Plugin] Harden error handling, null guards, and type validation in omi-usgs-earthquake-app
Author: TheRWXCreated Sep 16, 2026Updated Sep 18, 2026
Problem Description
In plugins/omi-usgs-earthquake-app/, several edge cases, missing defensive guards, and unhandled type/overflow exceptions cause runtime crashes across chat tool endpoints:
Timestamp Overflow and Year Out of Range Crashes in
_timestamp_to_utc:- Extreme, negative, or malformed millisecond timestamps (e.g.
1e16or-1e16) passed todatetime.fromtimestamp()crash withValueError: year is out of rangeorOverflowErrorinstead of returningNonesafely. - Non-finite float values (
NaN,Infinity) crash or format unpredictably.
- Extreme, negative, or malformed millisecond timestamps (e.g.
Null & Non-Dict Crashes in
_summarize_feature:_summarize_featurecrashes withAttributeError: 'NoneType' object has no attribute 'get'whenfeatureis non-dict (None, scalar, or string).geometry.get("coordinates")crashes withAttributeErrorifgeometryis non-dict or malformed.- Indexing
coordinates[0]crashes or produces invalid values ifcoordinatesis non-list or contains non-numeric strings/nulls.
NaN/InfCoordinate & Bounds Bypass:_parse_floatand_safe_floatlackmath.isfinite()validation, permittingNaNandInfinityto bypass coordinate range checks and propagate into query parameters sent to the USGS FDSN API.
USGS Event URL Passing in
tool_earthquake_details:- Users or LLMs frequently pass complete USGS URLs (e.g.
https://earthquake.usgs.gov/earthquakes/eventpage/us7000m8v4or with query strings/hash prefixes).tool_earthquake_detailspasses the raw URL directly toeventid=..., causing HTTP 400 Client Error from the USGS API.
- Users or LLMs frequently pass complete USGS URLs (e.g.
Ephemeral HTTP Client Churn & Missing Lifespan Pooling:
_usgs_getspins up a brand-newhttpx.AsyncClienton every single invocation without persistent connection pooling.- Unhandled
httpx.TimeoutExceptionor HTTP status errors lack explicit friendly envelopes.
Missing Typed Models, Request Validation, and Status Observability:
- Missing typed request models and standard
RequestValidationErrorenvelope handler. - Missing
/statusendpoint with runtime configuration and observability metadata.
- Missing typed request models and standard
Proposed Fixes
- Add defensive null and non-dict guards across
_summarize_feature, safely handling missing or malformedproperties,geometry, andcoordinates. - Guard
_timestamp_to_utcagainstValueError,OverflowError, andOSError, validating finite bounds before conversion. - Validate finite floats in
_parse_floatand_safe_float, rejectingNaNandInfinity. - Implement
_clean_event_idsupporting clean USGS IDs, eventpage URLs, query parameters, and stripping#/whitespace. - Implement pooled
httpx.AsyncClientlifecycle via FastAPIlifespanwith graceful fallback for isolated testing. - Add typed Pydantic request models (
RecentEarthquakesRequest,NearbyEarthquakesRequest,EarthquakeDetailsRequest) andRequestValidationErrorhandler. - Expose
/statusendpoint reporting configuration, timeout, and health status. - Expand test suite in
plugins/omi-usgs-earthquake-app/test_main.pyfrom 5 to 29 hermetic tests running in <0.05s under pure Python stdlib (python3 -S).
Proposed bounty: 0.00 USD PayPal: [email protected]
Source: BasedHardware/omi