[Bounty proposal] fix(crossref-app): connection pooling, null/non-dict payload guards, and hermetic test suite
Description
A reliability and architecture review of plugins/omi-crossref-app identified several key areas needing hardening:
-
Per-Request HTTP Client Allocation (Socket Exhaustion):
crossref_get()instantiates 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_crossref_worksandget_crossref_works_by_authordirectly chainpayload.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 unhandledAttributeError: 'NoneType' object has no attribute 'get'.get_crossref_workaccessesitem = payload.get("message", {})without validating thatitemis a non-empty dictionary, crashing on null payloads or rendering blank placeholder cards for missing records.
-
Fragile Date and Title Parsing:
extract_yearaccesseddate_parts[0][0]without verifying thatdate_parts[0]is a non-empty list, raisingIndexErrororTypeErroron malformed date structures.- Title extraction assumed
item.get("title")is always a non-empty list, crashing on scalar or null title fields.
-
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
lifespanhandler managing a persistenthttpx.AsyncClientwith graceful fallback. - Implement defensive payload validation across
search_crossref_works,get_crossref_work, andget_crossref_works_by_author. - Implement safe
_extract_titleandextract_yearhelpers. - Implement a 31-test hermetic test suite (
test_main.py) running with standard libraryunittestin <0.3s without third-party dependencies, maintaining complete module isolation. - Register
omi-crossref-testsin.github/checks-manifest.yaml.
Implemented in PR #13979 with lifespan connection pooling, defensive payload traversal, 31 hermetic unit tests, and checks manifest registration.
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!
I have implemented a clean, hermetic fix with full unit test coverage in PR #14178.
Summary of Changes
- Replaced per-request
httpx.AsyncClientinstantiation with connection pooling via FastAPIlifespanhandler (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, andget_crossref_works_by_authorto preventAttributeErrorwhen 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
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! 🙏