Skip to content

fix(crossref-app): validate tool inputs, guard non-dict payloads, pool HTTP client (#13983) - #14139

Closed
t3ratech wants to merge 3 commits into
BasedHardware:mainfrom
t3ratech:fix/crossref-validation-13983
Closed

t3ratech wants to merge 3 commits into
BasedHardware:mainfrom
t3ratech:fix/crossref-validation-13983

Conversation

@t3ratech

@t3ratech t3ratech commented Sep 15, 2026 •

Copy link
Copy Markdown
Contributor

Closes #13983

Changes

  • models.py: validators strip query/doi/author, clamp max_results 1–10 (non-numeric → 5); ChatToolResponse requires exactly one of result/error
  • main.py: RequestValidationError → HTTP 200 ChatToolResponse envelope (raw 422 crashes the Omi chat agent); lifespan-pooled httpx.AsyncClient on app.state with polite User-Agent + per-request fallback; crossref_get rejects non-dict JSON; defensive _extract_title/_clean_field/_message_dict/_work_items helpers; hardened extract_year + clamp
  • test_main.py (new): 30 hermetic stdlib tests — functional mini-pydantic executes real validators, controllable FakeAsyncClient transport seam
  • checks-manifest.yaml: crossref-validation-tests, local+ci

Verification

  • Patched: 30/30 green
  • Unpatched: 21/30 fail (10 failures + 11 errors)
  • run_checks.py --check-id crossref-validation-tests: SELECTED via triggers + PASS

Overlap note: this branch independently includes the httpx pooling from #14138 — whichever merges first, the other rebases cleanly.

/claim #13983 PayPal: [email removed]

Review in cubic

Failure-Class: none

@t3ratech

t3ratech commented Sep 15, 2026 •

Copy link
Copy Markdown
Contributor Author

/claim #13983 PayPal: [email removed]

@Git-on-my-level

Copy link
Copy Markdown
Member

Verified this against #13983 end to end — nice, complete fix. Details per file:

plugins/omi-crossref-app/models.py — field_validator(mode="before") trimmers for query/doi/author plus _bounded_max_results (clamp 1–10, non-numeric → 5) cover the unvalidated-input issue, and the ChatToolResponse model_validator enforcing exactly-one-of result/error locks in the chat-tool envelope at the model layer.

plugins/omi-crossref-app/main.py — the RequestValidationError handler returning HTTP 200 with {result: None, error: ...} restores the envelope contract the Omi chat agent expects (raw 422s break it); _extract_title/_clean_field/_message_dict/_work_items and the hardened extract_year fix the AttributeError/IndexError crashes on scalar, non-dict, and non-list payloads; the lifespan-pooled httpx.AsyncClient with polite User-Agent and per-request fallback addresses the socket churn and rate-limit courtesy.

plugins/omi-crossref-app/test_main.py — the hermetic stub approach (functional mini-pydantic + controllable FakeAsyncClient) matches the repo's existing convention from plugins/notifications/test_hey_omi_extraction.py. I ran it: 30/30 pass on this head, and 21/30 fail against the pre-PR code (10 failures + 11 errors) — exactly the regression coverage claimed.

.github/checks-manifest.yaml — crossref-validation-tests is correctly placed under checks: (before the exempt: block). I resolved and ran it through .github/scripts/run_checks.py at this commit: SELECTED via triggers and PASS.

Two non-blocking nits, neither worth a re-spin: clamp_max_results in main.py now duplicates the model-level clamp (harmless defense in depth), and the try/except around AsyncClient(...) construction in lifespan is effectively unreachable — fine to keep for the fallback contract it documents.

Re base: plugins/omi-crossref-app/ hasn't changed on main since the branch point, so the rebase surface is just manifest context. The overlap with #14138 (httpx pooling) is appreciated and clearly disclosed — leaving the merge-order call between the two to maintainers, along with the bounty claim payout.


🤖 This was an automated review on behalf of the maintainers. Verified by actually running the new suite on this head and on pre-PR code, and by executing the new manifest check via run_checks.py. Leaving for human maintainer review for the merge-order decision versus #14138 and the #13983 bounty claim; the code itself looks merge-ready.


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 positive-signal Automation verified a genuine fix/quality contribution python 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 input-validation fix for #13983, Hygiene required check is currently failing — approve only.

@t3ratech
t3ratech force-pushed the fix/crossref-validation-13983 branch from 77bcd68 to 935c8a9 Compare September 17, 2026 05:49
@Git-on-my-level

Copy link
Copy Markdown
Member

Follow-up on the two commits pushed after the earlier automated review (rebase + chore(manifest): drop duplicate crossref-validation-tests id):

  • Plugin code unchanged by the rebase — diffed plugins/omi-crossref-app/main.py, models.py, and test_main.py between the commit the approval was left on and the current head: byte-identical, so that approval still covers exactly this code.
  • Manifest entry lands cleanly: single crossref-validation-tests id (no duplicates), placed beside the other plugin checks with local+ci lanes, and no id collision with current main post-merge.
  • Suite re-verified on the new head: 30/30 green locally, and still 21/30 failing against the pre-fix files — the coverage is real, not vacuous.
  • All checks green on this head, including Hygiene (which was failing at the time of the original approval).

One merge-ordering note: #14138 (pooling-only, #13978) is fully subsumed by this PR — whichever lands first, the other can be closed with credit. Thanks @t3ratech — the pooled-client fallback path and the HTTP 200 validation envelope are exactly the right shape for the chat-tool contract.


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

@t3ratech

Copy link
Copy Markdown
Contributor Author

Rebased onto current main in 99aa767 — CONFLICTING cleared. Resolutions: manifest entries unioned (whoop + crossref); the duplicate crossref-validation-tests id stays deduped.

Four DOI test fixtures needed updating for upstream's _DOI_RE (^10\.\d{4,9}/): 10.1/test style registrants are not real DOIs and now fail normalize_doi before reaching the mocked handler. Fixtures moved to 10.1038/*; the error assertion is the uniform Invalid DOI format string upstream returns.

python3 plugins/omi-crossref-app/test_main.py → 30/30 on the rebased head.

@t3ratech
t3ratech force-pushed the fix/crossref-validation-13983 branch from 99aa767 to 8b6cce3 Compare September 22, 2026 13:15
…l HTTP client (BasedHardware#13983)

- models.py: strip whitespace on query/doi/author, clamp max_results to
  1-10 (default 5 on garbage), and require exactly one of result/error
  on ChatToolResponse.
- main.py: RequestValidationError handler returns HTTP 200 with the
  {result, error} envelope instead of FastAPI's default 422; lifespan
  handler pools an httpx.AsyncClient on app.state.http_client with a
  polite User-Agent and per-request fallback; _extract_title,
  extract_year, _message_dict, and _work_items survive scalar,
  non-dict, and empty payloads; crossref_get rejects non-dict JSON.
- test_main.py: 30 hermetic stdlib tests (unittest + framework stubs)
  covering validation, extraction, pooling, envelope, and handlers.
- checks-manifest.yaml: register crossref-validation-tests in local+ci.

Verified: python3 plugins/omi-crossref-app/test_main.py -> 30 tests OK
(patched); same suite against pre-fix main.py/models.py -> 21 of 30
fail (10 failures, 11 errors). Manifest runner: SELECTED + PASS
crossref-validation-tests (local lane).

Failure-Class: none
…asedHardware#13983)

Upstream's normalize_doi enforces ^10\.\d{4,9}/... — a 4-9 digit
registrant per the DOI spec — and returns one uniform error string.
Test fixtures using registrant '1' (10.1/test) are not real DOIs and
now fail validation before reaching the mocked handler; updated to
10.1038/* and the uniform 'Invalid DOI format' assertion.

python3 plugins/omi-crossref-app/test_main.py → 30/30.
@t3ratech
t3ratech force-pushed the fix/crossref-validation-13983 branch from 8b6cce3 to 149489a Compare September 23, 2026 09:47
@aryanorastar

Copy link
Copy Markdown
Collaborator

Closing as a later copy of #13985 on plugins/omi-crossref-app/main.py and models.py. The keep for the non-dict payload guard is #13979. This head adds no extra production file.

@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

4 participants