Skip to content

feat(rules): content/near-duplicate groups pages with nearly identical main text (repo#1369) - #1913

Closed
nc9 wants to merge 1 commit into
mainfrom
boat/near-duplicate-1369
Closed

nc9 wants to merge 1 commit into
mainfrom
boat/near-duplicate-1369

Conversation

@nc9

@nc9 nc9 commented Nov 15, 2026

Copy link
Copy Markdown
Contributor

Adds content/near-duplicate, a site rule that groups indexable pages whose main text is nearly identical, beyond the exact matches content/duplicate-content finds (squirrelscan/repo#1369).

How it works

  • Per page, a 64-bit simhash of the main text (main / [role=main], else body, with nav, header, footer, aside, form, menu, landmark roles and aria-hidden subtrees dropped) over word 3-shingles. Each distinct shingle votes once, so a repeated sentence template cannot out-vote a page's own text. Pages under 100 main-text words, redirects and bodyless pages get no hash. Token count is capped at 20,000 per page.
  • New bounded column PageFeatureRow.contentSimhash (16 hex chars): SQLite schema 41 -> 42 (additive ALTER TABLE page_features ADD COLUMN content_simhash TEXT), filled by extractPageFeatures on the streaming path. The legacy path calls the same pageContentSimhash. Rule cache prc-7 -> prc-8.
  • Clusters are pages within Hamming distance 5, by union-find. Unrelated hashes reach 5 bits with probability 4.5e-13 per pair. A name or date swap measures 0 to 6 bits. Pages that are exact copies are collapsed by content/duplicate-content's fingerprint, and a cluster needs at least two distinct texts, so exact copies are not double-reported. Canonicalised clusters, hreflang alternates, noindex, non-2xx and paginated URLs are excluded, the same as in duplicate-content.
  • Skips below 10 crawled pages. Warn per cluster. Fail when a cluster holds 10 or more distinct texts (doorway scale). Severity warning, weight 4.
  • Both paths feed one async builder. The legacy hashing loop and the pair loop yield to the event loop every 8 ms.

Design notes for review

  • Modal-norm guard (70% agreement) not applied. This is not an outlier rule. Pairs are judged against a fixed similarity threshold, so there is no modal value to agree on. The false-positive guards are the page floor, chrome stripping, the 100-word minimum, distinct-shingle voting and a threshold chosen for a negligible chance-pair rate.
  • Known limit: a 64-bit simhash catches small edits (a name, a date, a sentence). A rewritten paragraph out of five measures 11 to 20 bits and is not reported. The docs page says so.
  • Overlap with integrity/seo-doorway: that is a page rule for injected off-topic affiliate posts. A test runs it over a 12-page location-doorway cluster: it reports nothing, and near-duplicate reports one cluster. There is one finding per cluster.
  • Synthetic site: the first cut clustered 490 synthetic pages, because their shared sentence template dominated the votes. Distinct-shingle voting and the threshold of 5 fixed that. The rule passes there, and healthScore.overall is unmoved at 56.

Acceptance criteria

  • Small-edit pages (city, date, one sentence) are clustered with every member URL listed. Exact copies are left to duplicate-content: packages/rules/tests/near-duplicate.test.ts, the exact-duplicate tests also run duplicateContentRule.
  • Chrome-only sharing and pages under 100 words do not cluster, including a sentence-template filler fixture.
  • Legacy and streaming paths give deep-equal results on warn and fail fixtures (dual-path parity tests).
  • contentSimhash column added and populated in both paths: page-features-content-simhash.test.ts and the page-features-store.test.ts round-trip. Timer tests confirm a 1 ms interval ticks during the streaming rule run (4,000 hashes) and the legacy run (300 parsed pages). The 500-page canonical golden passes in 32 s.
  • seo-doorway overlap resolved by test, and explained in the docs page.
  • Pass, warn, fail and skipped are covered. The docs page docs/rules/content/near-duplicate.mdx is added. Content counts 28 -> 29 in the README, docs index, rules index and seo index. The constants comment reads 333 enabled rules.

Gates

  • make validate in docs: exit 0
  • typecheck: rules, audit-engine, crawler, core-contracts, utils clean
  • oxfmt clean on new files. oxlint reports only prefer-math-trunc on >>> 0, the same as existing files.
  • tests: rule, duplicate-content, voice-consistency, page-features-store and the new engine test 98 pass. Registry tests 803 pass, docs tests 9 pass, finding-messages and rule-cache-codec 30 pass, canonical golden 1 pass, crawler schema tests 63 pass.

Agent skill

No change needed: the skill does not list rules by name or count.

Not done

The real-site smoke test (AGENTS.md step 9) needs network access, which this environment does not have. It is filed as a follow-up.

@nc9
nc9 force-pushed the boat/near-duplicate-1369 branch from 8b166bc to 6510f1a Compare November 16, 2026 04:58
…early identical (repo#1369)

Signed-off-by: Nik Cubrilovic <[email protected]>
@nc9
nc9 force-pushed the boat/near-duplicate-1369 branch from 6510f1a to e3bde54 Compare November 17, 2026 01:49
@nc9

nc9 commented Nov 19, 2026

Copy link
Copy Markdown
Contributor Author

Landed in batch #2132 as 8366851.

nik

@nc9 nc9 closed this Nov 19, 2026
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.

1 participant