Skip to content

fix(crossref-app): connection pooling, null/non-dict payload guards, and hermetic test suite (fixes #13978) - #14178

Closed
arawnslab-hash wants to merge 1 commit into
BasedHardware:mainfrom
arawnslab-hash:fix/crossref-pooling-payload-guards
Closed

arawnslab-hash wants to merge 1 commit into
BasedHardware:mainfrom
arawnslab-hash:fix/crossref-pooling-payload-guards

Conversation

@arawnslab-hash

@arawnslab-hash arawnslab-hash commented Sep 16, 2026 •

Copy link
Copy Markdown
Contributor

What changed and why

In plugins/omi-crossref-app/main.py:

  1. 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.
  2. 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.
  3. Added hermetic regression test suite plugins/omi-crossref-app/test_crossref.py.

Product invariants affected

none

How it was verified

Executed full hermetic test suite across test_crossref.py. All 5 tests pass cleanly with 0 external network dependencies:

Ran 5 tests in 0.038s
OK

Tests

  • plugins/omi-crossref-app/test_crossref.py:
    • test_search_works_null_message_payload
    • test_search_works_non_dict_payload
    • test_get_work_null_message_payload
    • test_get_works_by_author_null_message_payload
    • test_search_works_success

Failure class (fixes)

Failure-Class: none

Bounty Payout Details

  • PayPal: [email protected]
  • USDC (Base / Polygon EVM): 0xa709768e0B597df11b2B81AB7ea54EEacd2532D0

Review in cubic

@Git-on-my-level Git-on-my-level left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @arawnslab-hash — the core of this is solid, well-scoped work, and I verified it: the new suite passes 5/5 locally and the payload guards close the crash paths from #13978. One blocking regression before merge, plus smaller notes.

What's good (verified in plugins/omi-crossref-app/main.py):

  • The lifespan-managed httpx.AsyncClient with the per-request fallback in crossref_get() (client = getattr(getattr(app, "state", None), "client", None); is_closed check) is the right pooling pattern and keeps the module usable outside a running app.
  • The null/non-dict guards in search_crossref_works, get_crossref_work, and get_crossref_works_by_author (message = data.get("message"); items = message.get("items", []) if isinstance(message, dict) else []) fix every AttributeError path named in the issue, and extract_year's isinstance checks close the date-parts IndexError case.
  • test_crossref.py is genuinely hermetic (httpx/fastapi/models stubbed, no network) and green.

Blocking — clean() drops the JATS/HTML stripping from #13525 (merged Sep 12). main's clean() removed jats:* and generic HTML tags before text reaches chat output; this PR's version only unescapes entities and collapses whitespace. On a typical Crossref abstract like jats:pWe report x < 0.5 in jats:italicDrosophila</jats:italic>...</jats:p>, get_crossref_work now returns the raw markup in the Abstract field (verified by running both implementations side by side). The PR description doesn't mention this removal. Please restore the _JATS_TAG/_CLOSE_TAG/_OPEN_TAG stripping — keeping your whitespace normalization is fine — and add one regression test with a JATS-marked abstract; the new suite has no clean()-on-tagged-input coverage, which is why this slipped through.

Non-blocking:

  • The isinstance(data, dict) guards after crossref_get() are unreachable through the real seam (crossref_get already returns {} for non-dict JSON); only the mocked tests hit them. Fine as defense-in-depth, but worth a comment saying so.
  • Every test patches crossref_get itself, so the new pooling/fallback path has zero coverage — a broken is_closed or fallback branch would not be caught.
  • TIMEOUT changed 20s total to 15s total / 5s connect via httpx.Timeout. Looks intentional; flagging for visibility.
  • The suite isn't wired into any CI lane: no checks-manifest entry or workflow discovers plugins/omi-crossref-app tests, though #13978 explicitly asked for manifest registration. Note #13979 (open, same issue) includes that registration, so maintainers will want to coordinate rather than land both.

Once the tag-stripping is restored with a regression test, I have no further code concerns.


by AI on behalf of David — if you need David’s attention urgently, please @Git-on-my-level and escalate with need human response.

@Git-on-my-level Git-on-my-level added needs-tests PR introduces logic that should be covered by tests python labels Sep 16, 2026
@arawnslab-hash

Copy link
Copy Markdown
Contributor Author

Hi @Git-on-my-level,

Thank you for the detailed review and catch regarding the JATS/HTML stripping behavior from #13525!

All requested changes have been applied in commits 30b277d, 67bc35d, and 4b6bd7f:

  1. Restored JATS & HTML Tag Stripping: Restored _JATS_TAG, _CLOSE_TAG, and _OPEN_TAG in plugins/omi-crossref-app/main.py while preserving whitespace normalization (" ".join(value.split())).
  2. Regression Test Suite Extended: Added test_clean_jats_and_html_tag_stripping and test_get_work_jats_abstract_rendered_cleanly in plugins/omi-crossref-app/test_crossref.py verifying that <jats:...> elements are stripped cleanly without leaking markup into tool results (8/8 tests pass).
  3. CI Manifest Registration: Registered crossref-app-tests in .github/checks-manifest.yaml before exempt: to wire the hermetic suite into CI.

Ready for your re-review! 🙏

@arawnslab-hash
arawnslab-hash force-pushed the fix/crossref-pooling-payload-guards branch from 4b6bd7f to d3819b7 Compare September 16, 2026 14:55
@arawnslab-hash
arawnslab-hash force-pushed the fix/crossref-pooling-payload-guards branch from d3819b7 to 66c5264 Compare September 17, 2026 11:04
@Git-on-my-level
Git-on-my-level dismissed their stale review September 17, 2026 15:36

Dismissed: the blocking concern in this review (JATS/HTML tag stripping dropped from clean()) is resolved on the current head — _JATS_TAG/_CLOSE_TAG/_OPEN_TAG restored alongside whitespace normalization, with regression tests test_clean_jats_and_html_tag_stripping and test_get_work_jats_abstract_rendered_cleanly (suite 8/8 green).

@Git-on-my-level Git-on-my-level left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @arawnslab-hash — the blocking JATS/HTML stripping concern from my earlier review is resolved on this head: _JATS_TAG/_CLOSE_TAG/_OPEN_TAG are restored in clean() alongside your whitespace normalization, and test_clean_jats_and_html_tag_stripping + test_get_work_jats_abstract_rendered_cleanly lock it in. I ran the suite locally: 8/8 pass, fully hermetic. The crossref-app-tests registration in .github/checks-manifest.yaml is also correctly placed with both local and ci lanes.

One new blocking regression, introduced when the branch history was rewritten (the previously reviewed head still had these): this head deletes GET /tools and GET /.well-known/omi-tools.json from plugins/omi-crossref-app/main.py. Both endpoints exist on main today. /.well-known/omi-tools.json is the documented chat-tools discovery contract — Omi's backend fetches it via fetch_app_chat_tools_from_manifest (backend/utils/apps.py) when registering an app's tools, and every sibling plugin app (omi-pubmed-app, omi-open-meteo-app, omi-frankfurter-app, …) exposes it. Removing it means Omi can no longer discover this app's three tools from the deployed instance. The PR description doesn't mention this removal. Please restore both endpoints — everything else in the refactor can stay as is.

Non-blocking:

  • search_crossref_works drops the explicit sort=relevance, order=desc params that main sends. Crossref defaults to score ordering for queried /works, so this is likely a no-op in practice — but it's an undeclared behavior change; either keep the params or add a one-line note.
  • Query validation was relaxed from "at least 2 characters" to non-empty for search, while author search still requires >=2. One-character queries now reach the API. Fine if intentional; flagging the asymmetry.
  • Every test patches crossref_get, so the pooling / is_closed fallback branch — the headline change — still has no direct coverage. A small test driving crossref_get with a mocked client for both the pooled and fallback paths would close that (this is why needs-tests stays for now).
  • The crossref-app-tests trigger list omits .github/checks-manifest.yaml (the frankfurter entry includes it). Minor consistency point; either convention is defensible.

The null/non-dict payload guards and the lifespan-managed client remain solid. Once the two discovery endpoints are restored, I have no further code concerns on this head.


by AI on behalf of David

@aryanorastar

Copy link
Copy Markdown
Collaborator

Closing as a later duplicate of #13979, opened earlier for the same file class.

Both PRs still change overlapping production files (plugins/omi-crossref-app/main.py). This later head is 66c5264ae5e0. Extra tests on this tip do not replace the earlier vehicle. Continue on #13979.

@github-actions

Copy link
Copy Markdown
Contributor

Hey @arawnslab-hash 👋

Thank you so much for taking the time to contribute to Omi! We truly appreciate you putting in the effort to submit this pull request.

After careful review, we've decided not to merge this particular PR. Please don't take this personally — we genuinely try to merge as many contributions as possible, but sometimes we have to make tough calls based on:

  • Project standards — Ensuring consistency across the codebase
  • User needs — Making sure changes align with what our users need
  • Code best practices — Maintaining code quality and maintainability
  • Project direction — Keeping aligned with our product principles and locked invariants

Before your next PR, please skim:

  • PRODUCT.md — product north star
  • Product invariants — locked rules (shared chat, memory tiers, agent control plane, integrations, brand)

If this was declined for direction or taste, maintainers should cite an invariant ID or open a proposed one — ask if that citation is missing.

Your contribution is still valuable to us, and we'd love to see you contribute again in the future! If you'd like feedback on how to improve this PR or want to discuss alternative approaches, please don't hesitate to reach out.

Thank you for being part of the Omi community!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-tests PR introduces logic that should be covered by tests python

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants