omi
omi copied to clipboard
[Bounty proposal] fix(wikipedia-app): connection pooling, null/non-dict payload guards, and hermetic test suite
Description
A reliability and architecture review of plugins/omi-wikipedia-app identified several key areas needing hardening:
-
Per-Request HTTP Client Allocation (Socket Exhaustion):
_request_json()instantiated a newhttpx.AsyncClienton every request. Under load, this creates rapid socket churn and connection exhaustion instead of reusing a managed client pool via FastAPI'slifespan.
-
Fatal Crashes on Null or Non-Dict Payloads:
search_articlesandget_random_articlechained.get("query", {}).get(...)without verifying whetherdataordata["query"]is a dictionary. If Wikipedia returns a non-dict error page (e.g. 504 Gateway Timeout or Cloudflare challenge), this raises an unhandledAttributeError: 'NoneType' object has no attribute 'get'._format_summarychaineddata.get("content_urls", {}).get("desktop", {}).get("page"). Ifcontent_urlsisNoneor not a dict, this crashes withAttributeError.- In
search_articles, if elements withinsearchare malformed or non-dict, extracting title or snippet crashes.
-
Defensive Input Validation:
- Non-string or missing
queryandtitlefields now return clear user-facing error messages instead of unhandled exceptions.
- Non-string or missing
-
Missing Checks Manifest Registration & Hermetic Test Suite:
- The plugin had 0 unit tests and was completely absent from
.github/checks-manifest.yaml.
- The plugin had 0 unit tests and was completely absent from
Proposed Fix
- Add FastAPI
lifespanhandler managing a persistenthttpx.AsyncClientwith graceful fallback for unmanaged contexts. - Implement defensive payload validation across
search_articles,get_article_summary, andget_random_article. - Implement safe
_format_summary,_clean_snippet, and_article_urlhelpers. - Implement a 27-test hermetic test suite (
test_main.py) running with standard libraryunittestin <0.3s without third-party dependencies, maintaining complete module isolation. - Register
omi-wikipedia-testsin.github/checks-manifest.yaml.
Later copy of the same wikipedia null-nested report. Keep #13948 / PR #13949 as the vehicle.