omi icon indicating copy to clipboard operation
omi copied to clipboard

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

Open shitobu opened this issue 2 months ago • 4 comments

Description

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

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

    • crossref_get() instantiates 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_crossref_works and get_crossref_works_by_author directly chain payload.get("message", {}).get("items", []). If Crossref returns {"message": null} or a non-dict error page (such as a 504 Gateway Timeout or Cloudflare challenge), this raises an unhandled AttributeError: 'NoneType' object has no attribute 'get'.
    • get_crossref_work accesses item = payload.get("message", {}) without validating that item is a non-empty dictionary, crashing on null payloads or rendering blank placeholder cards for missing records.
  3. Fragile Date and Title Parsing:

    • extract_year accessed date_parts[0][0] without verifying that date_parts[0] is a non-empty list, raising IndexError or TypeError on malformed date structures.
    • Title extraction assumed item.get("title") is always a non-empty list, crashing on scalar or null title fields.
  4. Missing Checks Manifest Registration & Hermetic Test Suite:

    • The plugin only had a basic regex test for JATS tags and had no tests for FastAPI endpoints, route wiring, or payload error paths.
    • It was missing from .github/checks-manifest.yaml.

Proposed Fix

  • Add FastAPI lifespan handler managing a persistent httpx.AsyncClient with graceful fallback.
  • Implement defensive payload validation across search_crossref_works, get_crossref_work, and get_crossref_works_by_author.
  • Implement safe _extract_title and extract_year helpers.
  • Implement a 31-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-crossref-tests in .github/checks-manifest.yaml.

shitobu avatar Sep 15 '26 07:09 shitobu

Implemented in PR #13979 with lifespan connection pooling, defensive payload traversal, 31 hermetic unit tests, and checks manifest registration.

shitobu avatar Sep 15 '26 07:09 shitobu

Hi there! I'd love to work on this issue. I'll fix per-request HTTP client allocation by using a connection pool and add null/non-dict payload guards to avoid crashes. Let me know if that works!

nazasnow avatar Sep 15 '26 15:09 nazasnow

I have implemented a clean, hermetic fix with full unit test coverage in PR #14178.

Summary of Changes

  • Replaced per-request httpx.AsyncClient instantiation with connection pooling via FastAPI lifespan handler (app.state.client), preventing socket churn and connection exhaustion under load while retaining client lifecycle fallback.
  • Added defensive type and null guards in search_crossref_works, get_crossref_work, and get_crossref_works_by_author to prevent AttributeError when Crossref returns {"message": null} or non-dict error payloads.
  • Added hermetic regression test suite plugins/omi-crossref-app/test_crossref.py (5 unit tests verifying all null/edge-case conditions). All tests pass cleanly.

PR: https://github.com/BasedHardware/omi/pull/14178 Payout Address (USDC Base/Polygon): 0xa709768e0B597df11b2B81AB7ea54EEacd2532D0

arawnslab-hash avatar Sep 16 '26 07:09 arawnslab-hash

Thanks for putting this together. We aren't doing bounties at the moment, so we're closing the bounty proposal issues for now — thanks for the fix! 🙏

undivisible avatar Oct 22 '26 11:10 undivisible