Skip to content

fix(crawler): gate link discovery on cached page reuse - #559

Merged
nc9 merged 2 commits into
mainfrom
claude/pub-354-reuse-link-discovery
Oct 8, 2026
Merged

nc9 merged 2 commits into
mainfrom
claude/pub-354-reuse-link-discovery

Conversation

@nc9

@nc9 nc9 commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

What changed

reuseCachedPage enqueued every outlink of a reused page, ignoring disableLinkDiscovery. With incremental: true and disableLinkDiscovery: true, one reused homepage put the whole site back in the frontier.

The check is now one shared linkDiscoveryAllowed() in packages/crawler/src/core/crawler.ts, used by both the fetch path and the reuse path, so they cannot drift. It is read at call time because sitemapPendingCount changes as the crawl runs.

docs/crawl.mdx now says a reused page follows the same link rules as a fetched one.

Acceptance criteria

  • A crawl with disableLinkDiscovery: true does not enqueue outlinks from a reused cached page. Test: disableLinkDiscovery: a reused page does not enqueue its outlinks.
  • The sitemap fallback still holds. Test: sitemap fallback: with no crawlable sitemap URLs a reused page's links are discovered.
  • disableLinkDiscovery: false discovers links from reused pages as before. Test: negative control: disableLinkDiscovery false discovers a reused page's links.
  • A test covers the reuse path specifically. packages/crawler/tests/reuse-link-discovery-gate.test.ts runs a real two-pass incremental crawl where pass 2 makes zero fetches (asserted), so every page goes through reuseCachedPage. The first test fails without the fix.

Verification

  • bun test packages/crawler/tests/reuse-link-discovery-gate.test.ts: 3 pass (first test fails with the fix reverted)
  • bun test on cache-fresh-skips-delay, incremental-freshness, cache-stats, carried-seed-crawl: 34 pass
  • cd packages/crawler && bun run typecheck: clean
  • bun run lint, bun run format:check: clean
  • cd docs && make validate: all checks passed

Agent skill

No skill change needed. No CLI flag, output format or command changed; the skill links to the docs for crawl behaviour.

Risk

Quick audits that reuse cached pages now stay on the seed and sitemap URLs, which is what the mode documents.

Closes #354

reuseCachedPage enqueued every outlink of a reused page, ignoring
disableLinkDiscovery. Share one linkDiscoveryAllowed() check between the
fetch path and the reuse path.

Signed-off-by: Nik Cubrilovic <[email protected]>
@claude

claude Bot commented Oct 8, 2026

Copy link
Copy Markdown

Reviewed the diff. I found no blocking issues.

  • The new linkDiscoveryAllowed() helper is a straight extraction of the old fetch-path condition. Both the fetch path and reuseCachedPage now use it, so they can't drift apart. It is evaluated at call time, which is right because sitemapPendingCount changes during the crawl.
  • Gating both the parsedData and the HTML re-parse fallback in the reuse path is correct. Neither can leak links in quick mode.
  • The tests are good. They run a real two-pass incremental crawl and cover the gate, the sitemap fallback and a negative control. They also check that pages were reused rather than fetched, so they can't pass by accident.
  • The docs addition matches the behavior.

(nit) crawler.ts: the comment block describing linkDiscoveryAllowed sits under the "Reuse a cached page" header, though the helper is also used by the fetch path. Moving it above that header would read more clearly.

I haven't run the tests or checked CI.

@claude

claude Bot commented Oct 8, 2026

Copy link
Copy Markdown

Reviewed the diff. I found no issues.

  • Extracting linkDiscoveryAllowed() and using it in both the fetch path and reuseCachedPage removes the divergence behind Cached page reuse ignores disableLinkDiscovery #354. It reads sitemapPendingCount at call time, as the old inline check did.
  • The new tests run a real two-pass incremental crawl. They cover the gated case, the sitemap-empty fallback and a negative control. They also check that pages were reused rather than fetched, so they can't pass for the wrong reason.
  • The docs addition matches the new behaviour.

I did not run the test suite myself.

@nc9
nc9 merged commit 3b25035 into main Oct 8, 2026
15 checks passed
@nc9
nc9 deleted the claude/pub-354-reuse-link-discovery branch October 8, 2026 02:36
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.

Cached page reuse ignores disableLinkDiscovery

1 participant