omi
omi copied to clipboard
[Plugin] Harden error handling, type validation, and Atom feed guards in omi-arxiv-app
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:
- Unhandled crashes on non-dict / null request bodies:
search_papers:_build_search_querycallspayload.get("query"). WhenpayloadisNoneor non-dict, this immediately raisedAttributeError: 'NoneType' object has no attribute 'get'.get_paper_details:payload.get("paper_id")immediately raisedAttributeError: 'NoneType' object has no attribute 'get'.search_author:payload.get("author")immediately raisedAttributeError: 'NoneType' object has no attribute 'get'.
- 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-apphad no dedicatedmodels.pyschema module.
- Unlike other hardened community plugins (
- 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
NoneTypeor indexing failures.
- 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
- 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.
- 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
Proposed Solution
- Typed Request Models (
plugins/omi-arxiv-app/models.py):- Define typed schemas:
SearchPapersRequest,GetPaperDetailsRequest,SearchAuthorRequest, andChatToolResponse.
- Define typed schemas:
- Graceful Validation Error Handling:
- Implement
validation_exception_handlermappingRequestValidationErrorto standard HTTP 200ChatToolResponse(error="invalid tool request: ...").
- Implement
- 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).
- Add defensive extraction across all Atom XML fields (
- 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.
- Checks Manifest Integration (
.github/checks-manifest.yaml):- Register
arxiv-app-testsunder bothlocalandcilanes.
- Register
Resolved in PR #14263:
- Typed Request Models (
models.py): AddedSearchPapersRequest,GetPaperDetailsRequest,SearchAuthorRequest, and standardChatToolResponse. - Standard Error Envelope: Registered
@app.exception_handler(RequestValidationError)mapping 422s to standard HTTP 200ChatToolResponse(error="invalid tool request: ..."). - Defensive Parsing & ToU Throttling: Guarded Atom XML extraction (
_format_entry,_entry_text,_entry_authors,_entry_arxiv_id) against sparse/missing elements, and wrapped requests intry ... finallyto ensure arXiv's 3-second ToU throttle is strictly enforced even on failed calls. - Hermetic Test Suite: Implemented 44 unit tests in
test_main.pyusing minimal standard library stubs (matching theomi-semantic-scholar-appconvention), executing cleanly under barepython3 -Sin 0.09s without requiring site-packages or network access, and registeredarxiv-app-testsin.github/checks-manifest.yaml.