omi icon indicating copy to clipboard operation
omi copied to clipboard

[Plugin] Harden error handling, type validation, and Atom feed guards in omi-arxiv-app

Open Ivansky1 opened this issue 2 months ago • 1 comments

Problem Statement

The omi-arxiv-app plugin (plugins/omi-arxiv-app) previously accepted untyped raw dictionaries (payload: dict[str, Any]) across all tool endpoints (/tools/search_papers, /tools/get_paper_details, and /tools/search_author). When an upstream client or LLM runtime invokes these endpoints with null, non-dict JSON bodies, or malformed parameter structures, the application encountered unhandled crashes:

  1. Unhandled crashes on non-dict / null request bodies:
    • search_papers: _build_search_query calls payload.get("query"). When payload is None or non-dict, this immediately raised AttributeError: 'NoneType' object has no attribute 'get'.
    • get_paper_details: payload.get("paper_id") immediately raised AttributeError: 'NoneType' object has no attribute 'get'.
    • search_author: payload.get("author") immediately raised AttributeError: 'NoneType' object has no attribute 'get'.
  2. Missing typed request models:
    • Unlike other hardened community plugins (omi-open-library-app, omi-crossref-app, omi-pubmed-app, omi-stack-overflow-app), omi-arxiv-app had no dedicated models.py schema module.
  3. Fragile Atom feed parsing:
    • When an entry contained sparse/missing XML tags (e.g., missing author, date, category, or summary nodes), string operations and ID extractions were vulnerable to NoneType or indexing failures.
  4. Lack of hermetic test suite & CI manifest registration:
    • The test file only verified 4 URL query string encoding scenarios, without any coverage for the FastAPI endpoints, error handlers, timeout handling, or feed parsing. The plugin was also not registered in .github/checks-manifest.yaml.

Proposed Solution

  1. Typed Request Models (plugins/omi-arxiv-app/models.py):
    • Define typed schemas: SearchPapersRequest, GetPaperDetailsRequest, SearchAuthorRequest, and ChatToolResponse.
  2. Graceful Validation Error Handling:
    • Implement validation_exception_handler mapping RequestValidationError to standard HTTP 200 ChatToolResponse(error="invalid tool request: ...").
  3. Hardened Query & Entry Parsing (plugins/omi-arxiv-app/main.py):
    • Add defensive extraction across all Atom XML fields (title, authors, published, updated, categories, summary, id).
    • Add explicit timeout and HTTP error handling for arXiv query timeouts and status codes (429, 503).
  4. Comprehensive Hermetic Test Suite (plugins/omi-arxiv-app/test_main.py):
    • 37 hermetic unit tests verifying model validation, sanitizers, query builders, Atom feed parsing, and all FastAPI endpoints under success and error conditions.
  5. Checks Manifest Integration (.github/checks-manifest.yaml):
    • Register arxiv-app-tests under both local and ci lanes.

Ivansky1 avatar Sep 16 '26 07:09 Ivansky1

Resolved in PR #14263:

  1. Typed Request Models (models.py): Added SearchPapersRequest, GetPaperDetailsRequest, SearchAuthorRequest, and standard ChatToolResponse.
  2. Standard Error Envelope: Registered @app.exception_handler(RequestValidationError) mapping 422s to standard HTTP 200 ChatToolResponse(error="invalid tool request: ...").
  3. Defensive Parsing & ToU Throttling: Guarded Atom XML extraction (_format_entry, _entry_text, _entry_authors, _entry_arxiv_id) against sparse/missing elements, and wrapped requests in try ... finally to ensure arXiv's 3-second ToU throttle is strictly enforced even on failed calls.
  4. Hermetic Test Suite: Implemented 44 unit tests in test_main.py using minimal standard library stubs (matching the omi-semantic-scholar-app convention), executing cleanly under bare python3 -S in 0.09s without requiring site-packages or network access, and registered arxiv-app-tests in .github/checks-manifest.yaml.

shitobu avatar Sep 16 '26 22:09 shitobu