Skip to content

fix(omi-hacker-news-app): guard non-dict payloads, validate item_id, and safe limit bounds (#14283) - #14284

Merged
Git-on-my-level merged 3 commits into
BasedHardware:mainfrom
PINYOPATTANAWASANPORN:fix-hacker-news-hardening
Sep 17, 2026
Merged

Git-on-my-level merged 3 commits into
BasedHardware:mainfrom
PINYOPATTANAWASANPORN:fix-hacker-news-hardening

Conversation

@PINYOPATTANAWASANPORN

@PINYOPATTANAWASANPORN PINYOPATTANAWASANPORN commented Sep 17, 2026 •

Copy link
Copy Markdown
Contributor

Summary of Changes

  • Introduced _safe_payload() to prevent unhandled AttributeError: 'NoneType' object has no attribute 'get' when requests arrive with null or non-dict payloads.
  • Hardened _safe_limit() to disallow boolean inputs and safely clamp integer limits between 1 and MAX_LIMIT.
  • Hardened get_discussion to validate item_id: rejects None, booleans, empty strings, and non-positive numbers with clear validation error messages before calling downstream API.
  • Fixed _format_story URL construction to prevent rendering item?id=None when objectID is omitted.
  • Expanded hermetic regression tests in test_main.py covering all new guard paths.

Fixes #14283

Failure-Class: none

Review in cubic

@Git-on-my-level

Copy link
Copy Markdown
Member

Thanks @PINYOPATTANAWASANPORN - this is a tidy hardening pass that addresses all four failure modes from #14283, with hermetic regression tests to match. Reviewed both changed files:

plugins/omi-hacker-news-app/main.py

  • _safe_payload() plus payload: Any = None on all three tool endpoints cleanly removes the AttributeError: 'NoneType' object has no attribute 'get' 500s on null/non-dict bodies; each handler now coerces before first use.
  • _safe_limit() rejecting bools is a real fix - isinstance(True, int) in Python previously mapped limit: true to 1 instead of the default 10.
  • get_discussion item_id validation is well layered: bools/None/empty short-circuit, int() failures for values like "not-a-number" still land in the existing (ValueError, TypeError) handler, and the new <= 0 check stops malformed /items/0 or negative requests before they reach Algolia. Micro-nit, non-blocking: a bool item_id returns "Missing required field: item_id" rather than a type-specific message - fine as-is.
  • _format_story building hn_url once and gating the HN: line on object_id removes the item?id=None output and also fixes the subtle old bug where the fallback URL could still hardcode a missing id.

plugins/omi-hacker-news-app/test_main.py

  • Good coverage of the new paths: _safe_limit boundary clamps (1 and MAX_LIMIT), bool rejection, unparseable inputs; missing-objectID formatting; a subTest-driven invalid-item_id matrix; and direct non-dict payload calls through all three handlers. The harness stays fully hermetic (stubbed httpx/fastapi/pydantic, no network).

Also confirmed the linked issue #14283 describes exactly these four defects, the tool manifest schema (item_id typed as integer, required: ["item_id"]) stays consistent with the new validation, and all 10 tests in test_main.py pass against this head. Checks are green (Hygiene, Backend Hermetic Merge Gate). Nothing blocking found - leaving merge sign-off with the human maintainers.

Feedback generated by automated maintainer tooling on behalf of the Omi maintainers.


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 17, 2026

@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.

Obvious bugfix with tests; CI green on this head. Approving for admin squash.

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.

fix(omi-hacker-news-app): guard non-dict payloads, validate item_id, and safe limit bounds

2 participants