Skip to content

fix(hacker-news-app): drop deleted comments before applying comment_limit (#14421) - #14422

Merged
kodjima33 merged 2 commits into
BasedHardware:mainfrom
boai-maker:fix/hn-discussion-deleted-comments
Sep 18, 2026
Merged

kodjima33 merged 2 commits into
BasedHardware:mainfrom
boai-maker:fix/hn-discussion-deleted-comments

Conversation

@boai-maker

@boai-maker boai-maker commented Sep 17, 2026 •

Copy link
Copy Markdown
Contributor

Closes #14421

Problem

plugins/omi-hacker-news-app/main.py:252 sliced children before filtering them:

comments = item.get("children", [])[:comment_limit]

Algolia returns deleted and dead comments as ordinary children with a null or blank text. The render loop skipped those, but len(comments) and enumerate both ran over the unfiltered slice, so:

  • the header over-counted (Top 3 comments: followed by one comment);
  • the first visible comment could be numbered 2. when the first child was deleted;
  • an all-deleted slice printed Top N comments: followed by nothing, because the list was still truthy and never reached the existing No top-level comments returned. branch;
  • comment_limit under-delivered while printable comments sat just past the slice.

Separately children arrives as an explicit null for items with no replies. None[:limit] raised TypeError, caught by the handler's except (ValueError, TypeError) and surfaced as item_id must be an integer — misleading for a valid id. A non-dict item payload reached .get unguarded.

Fix

Collect (author, cleaned_text) pairs for children that actually render, stopping at comment_limit, so the header, the numbering and the limit all describe the same set. A null or non-list children coerces to [], and the item payload goes through the module's existing _safe_payload.

Tests

Five regressions appended to the existing hermetic suite. No manifest change needed — test_main.py is already registered as omi-hacker-news-tests.

  • test_deleted_comments_do_not_inflate_the_count
  • test_comment_limit_counts_printable_comments
  • test_all_deleted_comments_reports_none_rather_than_an_empty_list
  • test_null_children_is_not_reported_as_a_bad_item_id
  • test_non_dict_item_payload_does_not_crash

Against main: 4 failures and 5 errors. With the fix, all 15 tests pass.

$ python3 plugins/omi-hacker-news-app/test_main.py   # OK (15 tests)

Orthogonal to #14283/#14284, which added _safe_payload, item_id validation and _safe_limit but left the children slice and the item payload untouched.

Failure-Class: none

🤖 Generated with Claude Code

Review in cubic

@Git-on-my-level

Copy link
Copy Markdown
Member

Thanks @boai-maker — verified end to end. This is a clean fix for a real bug.

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

  • Root cause confirmed: the old item.get("children", [])[:comment_limit] sliced raw children, so deleted/dead Algolia comments (null/blank text) still consumed numbering and the header count, and an explicit children: null raised TypeError that the broad except (ValueError, TypeError) surfaced as the misleading item_id must be an integer.
  • The new loop collecting (author, _clean_text(text)) tuples with the len(comments) >= comment_limit break makes the header, the numbering, and the limit all describe the same printed set; _clean_text returning empty for null/blank text is the right drop predicate, and the [:1200] truncation is preserved.
  • _safe_payload(...) around the fetch plus the isinstance(raw_children, list) coercion now handles non-dict item payloads and null/missing/non-list children without leaning on the broad except clause. comment_limit is clamped to >= 1 by _safe_limit, so the break-after-append can never exit with a short list.

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

  • Five focused hermetic regressions mapping one-to-one onto the reported facets (deleted comments inflating the count, the limit counting printable comments, all-deleted hitting the No top-level comments returned. branch, null/non-list children not reported as a bad item id, and non-dict item payloads). All mock _request_json — no network.
  • Reproduced independently: against main the new suite fails with 4 failures + 5 errors (e.g. header Top 3 comments: over a single comment numbered 2.), and all 15 tests pass on this head. omi-hacker-news-tests is already registered in .github/checks-manifest.yaml under plugins/omi-hacker-news-app/**, so CI picks up the new cases with no manifest change — consistent with the green Backend Hermetic Merge Gate.

No dependency, workflow, or API-surface changes. Ready for a maintainer merge decision — leaving a positive signal here rather than a formal review, since this still needs a maintainer's sign-off.

— automated maintainer review 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 18, 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.

Confirmed on main: children sliced before filtering deleted/dead comments, causing miscounted headers and misleading item_id errors on null children. Fixes #14421, scoped, 5 new tests, 5/5. Merging.

@kodjima33
kodjima33 merged commit 0a2cb8c into BasedHardware:main Sep 18, 2026
41 of 42 checks passed
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

3 participants