Skip to content

fix(crossref-app): pool httpx client via lifespan, guard null/non-dict payloads (#13978) - #14138

Closed
t3ratech wants to merge 3 commits into
BasedHardware:mainfrom
t3ratech:fix/crossref-pooling-13978
Closed

t3ratech wants to merge 3 commits into
BasedHardware:mainfrom
t3ratech:fix/crossref-pooling-13978

Conversation

@t3ratech

@t3ratech t3ratech commented Sep 15, 2026 •

Copy link
Copy Markdown
Contributor

Closes #13978

Changes

  • lifespan wires a persistent httpx.AsyncClient onto app.state.http_client (same pooling pattern as omi-public-holidays-app / omi-frankfurter-app) — replaces per-request client construction
  • crossref_get reuses the pooled client with per-request fallback
  • New _extract_items / _extract_title helpers; extract_year hardened with isinstance checks on item/container/date-parts
  • All three handlers guard null/non-dict message/items and non-dict item entries; get_crossref_work returns a clean error for missing/empty records
  • New hermetic suite test_main.py — 26 stdlib tests, framework-stubbed
  • checks-manifest.yaml: crossref-pooling-tests, local+ci

Verification

  • Patched: 26/26 green (~0.05s)
  • Unpatched: 5 failures + 27 errors (AttributeError on None/str/list.get, extract_year crashes)
  • run_checks.py --check-id crossref-pooling-tests PASS; failure-class validate OK

Scope note: deliberately left models.py validators and the RequestValidationError envelope to #13983 — this PR covers only the pooling + payload-guard surface.

/claim #13978 PayPal: [email removed]

Review in cubic

Failure-Class: none

@t3ratech

t3ratech commented Sep 15, 2026 •

Copy link
Copy Markdown
Contributor Author

/claim #13978 PayPal: [email removed]

@Git-on-my-level

Copy link
Copy Markdown
Member

Reviewed the three changed files and verified the suite end to end.

plugins/omi-crossref-app/main.py

  • The lifespan-pooled AsyncClient on app.state.http_client matches the exact idiom already used by omi-public-holidays-app and omi-frankfurter-app on main, so this brings the plugin in line with established repo practice.
  • crossref_get reusing the pooled client with a per-request fallback is sensible; the fallback keeps direct invocation working. Minor design note: the fallback is silent, so a deployment where lifespan never ran would lose pooling without any signal — the new tests pin the wiring, so this is acceptable, just worth knowing.
  • The payload guards are thorough: _extract_items rejects non-dict payload/message/items, _extract_title handles str/list/None titles, and the isinstance-hardened extract_year survives every malformed date-parts shape I threw at it. Nice bonus: the old (item.get("title") or ["Untitled"])[0] indexed a scalar title to its first character — _extract_title fixes that real truncation bug (reproduced: 'Machine Learning Survey' rendered as 'M' on the base).
  • get_crossref_work now returns "No Crossref work found" for empty {} messages instead of rendering an Untitled empty record — better UX for a chat tool.

plugins/omi-crossref-app/test_main.py

  • Genuinely hermetic: stdlib-only, stubs httpx/fastapi/pydantic at import time and exercises the module's real lifespan, helpers, and handlers. Ran it in an isolated container with no network: 26/26 pass in ~0.02s.
  • Ran the same suite against the unpatched main.py: 5 failures + 27 errors, exactly matching your verification note — these are real regression tests, not tautologies. The pooling-reuse test (asserting zero extra client constructions) and the closed-after-lifespan assertion are the right shape.

.github/checks-manifest.yaml

  • crossref-pooling-tests is correctly placed under checks: (not exempt:), with local+ci lanes and triggers covering both the plugin path and the manifest itself, consistent with neighboring entries.

Leaving models.py validators to #13983 is a reasonable scope cut — pooling and payload guards here, validation envelope there. No product or security decisions needed; leaving the merge call to a human maintainer.


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 python positive-signal Automation verified a genuine fix/quality contribution labels Sep 16, 2026

@kodjima33 kodjima33 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

crossref-app httpx pooling + null-guard fix for #13978, Hygiene required check is currently failing — approve only.

…t payloads (BasedHardware#13978)

- Add FastAPI lifespan managing a persistent httpx.AsyncClient on app.state.http_client; crossref_get reuses it and falls back to a per-request client when the pool is unavailable.
- Guard search_crossref_works, get_crossref_work, and get_crossref_works_by_author against null/non-dict message/items payloads instead of raising AttributeError.
- Harden extract_year and add _extract_title so malformed date-parts and scalar/empty titles no longer crash or truncate to the first letter.
- Add hermetic stdlib test suite (26 tests, <0.1s, no third-party deps) and register crossref-pooling-tests in .github/checks-manifest.yaml (local+ci).

Verification: python3 plugins/omi-crossref-app/test_main.py - 26 tests fail on unpatched code (AttributeError/IndexError on null/non-dict payloads, per-request client churn), all pass after the fix. python3 .github/scripts/run_checks.py --lane local --check-id crossref-pooling-tests - PASS.

Failure-Class: none
@t3ratech
t3ratech force-pushed the fix/crossref-pooling-13978 branch from 1c1caff to 69fa138 Compare September 17, 2026 05:48
@Git-on-my-level

Copy link
Copy Markdown
Member

Follow-up on the two new manifest-only commits (69fa138, 6c34997) after the force-push — re-verified everything on head.

  • plugins/omi-crossref-app/main.py and plugins/omi-crossref-app/test_main.py are byte-identical to the revision @kodjima33 approved (checked via blob hashes), so that approval and the earlier review findings carry over.
  • The duplicated crossref-pooling-tests entry in .github/checks-manifest.yaml that broke Hygiene is gone: exactly one occurrence on head, under checks: with local+ci lanes. Hygiene is green again.
  • Re-ran the suite hermetically (isolated container, no network) on head: 26/26 pass in ~0.02s. Against the unpatched base main.py the same suite gives 5 failures + 27 errors, matching the verification note — these are real regression tests.

Nothing further from my side; the merge call stays with a human maintainer.


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, plugins/omi-crossref-app/test_main.py). This later head is 6c34997b8910. MERGEABLE or extra tests on this tip do not replace the earlier vehicle. Continue on #13979.

@github-actions

Copy link
Copy Markdown
Contributor

Hey @t3ratech 👋

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

positive-signal Automation verified a genuine fix/quality contribution python

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

4 participants