Skip to content

Fall back to the whole page when the article is a small part of it - #8

Open
sharmis-tp wants to merge 3 commits into
cppalliance:masterfrom
sharmis-tp:issue-1-fallback
Open

sharmis-tp wants to merge 3 commits into
cppalliance:masterfrom
sharmis-tp:issue-1-fallback

Conversation

@sharmis-tp

Copy link
Copy Markdown
Collaborator

Part 1 of #1.

The whole-page rendering, used for raw and for the fallback, now leaves out script and style. noscript stays, because Discourse serves its topic list in it.

The fallback now fires when the article is under 250 characters, or under 3,000 characters and under a fifth of the whole page, as in the field survey. Before, it fired only under 100 characters, so a profile or a list of links came back as one small fragment. An article of 3,000 characters or more is returned without rendering the whole page.

The two tests from the description of #1 are added as they are, and both pass. Three more cover the 20% rule in both directions and script, style and noscript on both paths. The share-rule test and the script/style test fail on master. The goldens are unchanged.

Scored with this crate's extract_html on the 15 saved pages from research/2026-11-20-web-fetch-measurements.md:

master this PR
Content phrases kept 35/49 (71%) 45/49 (92%)
Pages with every phrase 7 11
Boilerplate phrases leaked 6/37 10/37

The issue #1 profile, lobste.rs, DuckDuckGo and a GitHub profile now come back whole. The crates.io page no longer shows its window.onerror and SvelteKit bootstrap code. The new leaks are navigation text that the whole page brings back ("Sign in", "Navigation Menu", the DuckDuckGo region list).

Part 2, the title line and a note of how much the extraction kept, follows in its own PR.

@coderabbitai

coderabbitai Bot commented Nov 27, 2026 •

Copy link
Copy Markdown

Important

  • Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: b3a5aa6f-93fd-4a5f-8470-a68650d746fd
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

@sharmis-tp

Copy link
Copy Markdown
Collaborator Author

@vinniefalco, could you review this when you have time? It is part 1 of #1. I also tested it on top of current master (1d5aefc): it applies cleanly, and fmt, clippy and all 171 tests pass on Linux. Part 2 is ready, and I'll open it after this merges.

@vinniefalco

Copy link
Copy Markdown
Member

Thanks for the fixture results. Could you make the automatic fallback account for max_chars before merging?

A loopback test put a short article below a long archive menu. The base revision returned the article. This PR returned 40,000 characters of navigation and cut the article out entirely, because it chose the whole page before applying the cap.

Please keep the extracted article when the automatic fallback would cut it out, and add a regression test that checks the final web/fetch response. Explicit raw: true should still return the whole-page prefix.

@sharmis-tp

Copy link
Copy Markdown
Collaborator Author

Thanks, good catch. Pushed a fix: the automatic fallback now uses the whole page only when it fits within the call's max_chars. If the page would be cut, the article stays. raw: true still returns the start of the whole page.

Regression test: a_short_article_below_a_long_menu_is_returned_and_raw_returns_the_menu fetches a short article below 1,500 archive links. Without max_chars, the response is the article (extraction: readability, truncated: false) with no menu. With raw: true, it's the start of the menu (truncated: true). A unit test also checks the exact limit, one character either side. Both tests fail without the fix.

This rule is stricter than "only when the article itself would be cut", but it's deterministic. My 15 saved pages still score the same with the default cap, since every page that falls back is under 40,000 characters.

@vinniefalco

Copy link
Copy Markdown
Member

An oversized page now returns an empty body when Readability finds no article. I reproduced this with a forum topic list inside . The previous revision returned the capped topic list. The current head returns an empty body labeled extraction: readability and truncated: false. Apply the cap-based preference only when Readability has content to preserve. If extraction is empty, return the whole-page prefix and let the existing truncation code flag it:

if page_chars == 0 || page_chars > max_chars {

@sharmis-tp

Copy link
Copy Markdown
Collaborator Author

Thanks, confirmed and fixed. The cap-based preference now applies only when Readability returned some text. When the article is empty, the whole page is returned and the existing truncation cuts it at max_chars and flags it.

Regression test: a_page_with_no_article_over_max_chars_returns_the_cut_whole_page fetches a forum topic list of 1,500 links served only inside , and checks the final response is extraction: raw-html, truncated: true, with the topic list in the body. A unit test covers the same case at max_chars = 1. Both fail on the previous head.

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.

2 participants