Skip to content

fix: read deeply nested JSON-LD without recursion - #394

Merged
allenhutchison merged 1 commit into
Vycari:mainfrom
bniladridas:fix/388-jsonld-nesting
Nov 30, 2026
Merged

allenhutchison merged 1 commit into
Vycari:mainfrom
bniladridas:fix/388-jsonld-nesting

Conversation

@bniladridas

@bniladridas bniladridas commented Nov 29, 2026 •

Copy link
Copy Markdown
Contributor

Human overview

pepper feed show N --read could fail a whole read when a page's JSON-LD metadata was nested deeply: the stdlib JSON decoder, and the recursive walk over the decoded block, both raise RecursionError, which the code did not catch. Decoding and traversing now treat that as unreadable metadata, so the page's title and paragraphs still render. Fixes #388.

AI reviewer

Details for agents: what the diff does, invariants, verification, checklist

What the diff does

src/pepper_cli/article_reader.py:

  • _walk() now iterates with an explicit stack instead of recursing. Dict values and list items are pushed reversed so the pop order matches the old traversal, which means a page with several matches still yields the same first value under a key.
  • _name() is iterative too. Author values can nest as deeply as the rest of the block ({"author": {"name": {"name": ...}}}), and the old version could raise RecursionError from a second recursive path that the decoder exception never covered. It still follows only the name key on dicts and joins list entries with ", " in order.
  • parse() now catches RecursionError alongside ValueError around json.loads(). A block that cannot be decoded is skipped, and later blocks still contribute metadata.

Tests in tests/test_article_reader.py cover a 1500-deep valid block whose author is found, a 1500-deep author name, a 10,000-deep array that json.loads() rejects with RecursionError, and a malformed deep block followed by a normal one. Each asserts the readable title and paragraphs survive.

Invariants: JSON-LD stays best-effort metadata. A page whose metadata is unusable still returns its title and paragraphs, and one bad block never suppresses another. No network, credential, or wire-contract code is touched, so the private-address guard, byte cap, and deadline are unchanged.

Alternatives rejected: a depth counter would still need an arbitrary limit and would drop metadata that the iterative walk reads for free. Raising the interpreter recursion limit is process-global and unsafe in a long-lived TUI process.

Failure posture: if the traversal order were wrong, metadata could pick a different author or date on a page with several matches, which only affects display. If RecursionError escaped again, the read would fail instead of degrading, which is the reported bug.

Look hardest at _name(): the old dict branch read only name, and the new stack must keep that plus list order and the dropping of empty strings.

Verification, exactly as run:

  • uv run pytest -q tests/test_article_reader.py: 37 passed
  • uv run pytest -n auto -q: 4214 passed, 21 skipped in 201.55s
  • uv run pytest -n auto --cov --cov-report=json:coverage-summary.json: 4214 passed, 21 skipped in 346.02s; coverage 95.54% (17725/18552), floor 88
  • uv run ruff format --check: 175 files already formatted
  • uv run ruff check: All checks passed
  • uv run ty check src/pepper_cli/: All checks passed
  • git diff --check: clean, and no em or en dashes in the changed files or the commit message
  • The new deep-block tests were also run against the unmodified article_reader.py, where they fail with RecursionError from the old recursive _walk() and _name()

Deferred work: none.

Checklist (repo-specific)

  • uv run ruff format --check and uv run ruff check clean (no new lint ignores)
  • uv run ty check src/pepper_cli/ clean
  • uv run pytest passes; coverage floor in .claude/maintainerd.json not lowered
  • Server-contract changes: not applicable, only stdlib JSON-LD parsing changed
  • No token or credential is logged, printed, or put in a fixture
  • README and the bundled SKILL.md updated if commands or output changed: not applicable, neither changed
  • Help: help/cli.md updated for a new or changed command, or not user-facing because the output for a readable page is unchanged

Confidence Score: 5/5 · The PR appears safe to merge; no actionable issues were found.RetriggerView in GreptileConfidence Score: 5/5

The PR appears safe to merge; no actionable issues were found.

Summary

The PR keeps deeply nested JSON-LD from breaking article reads.

  • Feed reads keep article text when JSON-LD is deeply nested.

Reviews (1) · Last reviewed commit: "fix: read deeply nested JSON-LD without ..." · Reviewed by Greptile

article_reader walked JSON-LD metadata and author names recursively, so a block nested past the interpreter's depth limit raised RecursionError even when json.loads() accepted it, and json.loads() itself raises RecursionError rather than ValueError on very deep input. Both walks now use an explicit stack, and decoding treats RecursionError as unreadable metadata, so the page title and paragraphs still come through.

Closes Vycari#388

Signed-off-by: Niladri Das <125604915+bniladridas@users.noreply.github.com>
@vycari-review

vycari-review Bot commented Nov 29, 2026 •

Copy link
Copy Markdown

Vycari Review

Round 1 on faa969f. The verdict is the Vycari Review check run, and each open finding is an inline thread. Reply on every P0 and P1 thread: Fixed in <sha>, or Disputed: with a reason. P2s are the author's call: fix one, or reply Deferred: #<issue> (the PR's one follow-up issue) or Declined: with a reason, and VR stops re-raising it. From round 2 on, VR raises no new P2s: it checks the fixes and looks for P0s and P1s.

Open: P0 0 · P1 0 · P2 0 · disputed 0 · confirmed fixed 0 · withdrawn 0

Hand-off: Greptile requested on faa969f.

No open findings this round.

P2s, judge's notes and closed findings

Judge's notes

No candidate findings were raised.

@chatgpt-codex-connector

Copy link
Copy Markdown
Codex Review Summary: ❌ Failed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ❌ Failed 2026-11-29T10:03:38.512638Z
We couldn’t complete this review. Comment @codex review to try again.
faa969f PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@vycari-review

vycari-review Bot commented Nov 29, 2026

Copy link
Copy Markdown

@greptileai review

@allenhutchison allenhutchison left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for the fix!

@allenhutchison
allenhutchison added this pull request to the merge queue Nov 30, 2026
Merged via the queue into Vycari:main with commit 7717116 Nov 30, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Handle deeply nested or oversized JSON-LD without crashing article reads

2 participants