omi icon indicating copy to clipboard operation
omi copied to clipboard

[Bounty proposal] fix(wikipedia-app): connection pooling, null/non-dict payload guards, and hermetic test suite

Open shitobu opened this issue 2 months ago • 1 comments

Description

A reliability and architecture review of plugins/omi-wikipedia-app identified several key areas needing hardening:

  1. Per-Request HTTP Client Allocation (Socket Exhaustion):

    • _request_json() instantiated a new httpx.AsyncClient on every request. Under load, this creates rapid socket churn and connection exhaustion instead of reusing a managed client pool via FastAPI's lifespan.
  2. Fatal Crashes on Null or Non-Dict Payloads:

    • search_articles and get_random_article chained .get("query", {}).get(...) without verifying whether data or data["query"] is a dictionary. If Wikipedia returns a non-dict error page (e.g. 504 Gateway Timeout or Cloudflare challenge), this raises an unhandled AttributeError: 'NoneType' object has no attribute 'get'.
    • _format_summary chained data.get("content_urls", {}).get("desktop", {}).get("page"). If content_urls is None or not a dict, this crashes with AttributeError.
    • In search_articles, if elements within search are malformed or non-dict, extracting title or snippet crashes.
  3. Defensive Input Validation:

    • Non-string or missing query and title fields now return clear user-facing error messages instead of unhandled exceptions.
  4. Missing Checks Manifest Registration & Hermetic Test Suite:

    • The plugin had 0 unit tests and was completely absent from .github/checks-manifest.yaml.

Proposed Fix

  • Add FastAPI lifespan handler managing a persistent httpx.AsyncClient with graceful fallback for unmanaged contexts.
  • Implement defensive payload validation across search_articles, get_article_summary, and get_random_article.
  • Implement safe _format_summary, _clean_snippet, and _article_url helpers.
  • Implement a 27-test hermetic test suite (test_main.py) running with standard library unittest in <0.3s without third-party dependencies, maintaining complete module isolation.
  • Register omi-wikipedia-tests in .github/checks-manifest.yaml.

shitobu avatar Sep 15 '26 23:09 shitobu

Later copy of the same wikipedia null-nested report. Keep #13948 / PR #13949 as the vehicle.

aryanorastar avatar Sep 22 '26 05:09 aryanorastar