Skip to content

feat(scraper): delete stored pages the scrape options no longer admit on refresh - #645

Merged
arabold merged 1 commit into
mainfrom
feat/refresh-excluded-pages
Dec 5, 2026
Merged

arabold merged 1 commit into
mainfrom
feat/refresh-excluded-pages

Conversation

@arabold

@arabold arabold commented Dec 5, 2026

Copy link
Copy Markdown
Owner

Why

A refresh queues every stored page without running the filters a crawl applies to the links it finds. So a page the crawl would no longer admit stays in the index. For example, it now matches excludePatterns, it is hidden and includeHidden was turned off, or it sits behind a symlink and followSymlinks was turned off. Before this change, the symlink and hidden cases did worse than keep the page: the access policy threw while the page was fetched, which failed the refresh unless ignoreErrors was set.

This came up in the review of #467. There, deleting newly gitignored files on refresh has to pretend they answered 404, because the base strategy has no shared way to say "this page is now excluded".

What

  • BaseScraperStrategy.isExcluded(url, options, context): a new async, protected admission hook.

    • At enqueue, it runs on every discovered link that passed shouldProcessUrl.
    • At dequeue, it runs on refresh items (items with a pageId) before anything is fetched.
    • The base version applies the include and exclude patterns, including the default exclusions. It leaves scope out on purpose: scope is measured from the root after its redirects, and a refresh only learns that once the root has been fetched.
    • The URL the scrape started from is never judged, the same as in a normal scrape.
  • PageOutcome.Excluded: an excluded stored page is reported with this outcome and deleted: true. PipelineWorker deletes it through the existing removeDeletedPage / DocumentStore.deletePage path and logs the removal at info level. DocumentStore needs no change. Like a refresh 404, an exclusion does not count toward abortOnFailureRate.

  • LocalFileStrategy.isExcluded adds two rules for paths below the crawl root:

    • a path with a hidden segment is excluded unless includeHidden is on;
    • a path that passes through a symlink is excluded unless followSymlinks is on.

    These rules used to live in the directory listing and in isVisibleArchiveEntry. They moved into the hook, so a scrape and a refresh admit pages by the same rule. Members of an archive expanded under an internal root are judged from that root and skip the symlink check, which matches the access policy's bypass for them.

  • Docs: docs/concepts/refresh-architecture.md has a new Admission section and the updated outcome diagram. ARCHITECTURE.md lists the new outcome.

I deliberately did not add rules for the access-policy mode or allowedRoots. If someone disables file access or a configured root is unmounted, deleting the whole index on the next refresh would be far worse than failing the job, and failing the job is what happens today.

Tests

The E2E tests run through usePipelineHarness. Each one scrapes, changes the config, refreshes, and then checks storedUrls() and the outcome:

  • test/refresh-pipeline-e2e.test.ts: the stored excludePatterns change, and the newly excluded page is deleted without being requested.
  • test/local-file-refresh-e2e.test.ts: includeHidden is turned off, and both a hidden file and a file inside a hidden folder are deleted.
  • test/local-file-refresh-e2e.test.ts: followSymlinks is turned off, and both a symlinked file and a file under a symlinked folder are deleted, while the real file stays.

npm run lint, a cold npm run typecheck and npm test (after npm run build) all pass locally.

Moving #467 onto the hook

Once both PRs are merged, respectGitignore moves into LocalFileStrategy.isExcluded:

protected override async isExcluded(url, options, context) {
  if (await super.isExcluded(url, options, context)) return true;
  // ...hidden / symlink rules...
  if (this.gitignoreFilter) {
    const filePath = fileUrlToPathLoose(url);
    // archive members: test the physical archive path, as #467 does today
    const stats = await fs.lstat(filePath).catch(() => null);
    if (stats && (await this.isGitignored(filePath, stats))) return true;
  }
  return false;
}

gitignoredResult(), and the gitignore checks in processItem and in the directory listing, then go away. A gitignored stored page gets reported as Excluded instead of a fake NOT_FOUND. A gitignored path found mid-crawl is never queued, so it no longer counts as a processed item that produced nothing. I can do this as a follow-up commit after #467 merges.

Copilot AI balanced review requested due to automatic review settings December 5, 2026 18:31

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Changes recommended

Unresolved issues can delete valid pages during refresh, retain excluded GitHub files, and fail HTTP(S) archive scrapes with ENOTDIR errors.

3 open issues
What changed in this PR

This PR makes refresh delete stored pages that current scrape filters exclude, using a shared admission hook rather than simulated 404 responses.

Changes:

  • Adds an Excluded outcome and stored-page deletion handling.
  • Centralizes local hidden-file and symlink filtering.
  • Adds refresh regression tests and updates architecture documentation.
File Description
test/​refresh-pipeline-e2e.test.ts Tests exclusion without fetching.
test/​local-file-refresh-e2e.test.ts Tests hidden-file and symlink removal.
src/​scraper/​types.ts Defines the excluded outcome.
src/​scraper/​strategies/​LocalFileStrategy.ts Centralizes local admission rules.
src/​scraper/​strategies/​BaseScraperStrategy.ts Checks admission during discovery and refresh.
src/​pipeline/​PipelineWorker.ts Deletes and logs excluded pages.
docs/​concepts/​refresh-architecture.md Documents admission and deletion behavior.
ARCHITECTURE.md Updates the outcome list.

Review effort: Balanced

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Changes recommended

Critical issues remain: malformed percent escapes can abort entire GitHub scrapes, and redirected-root refreshes can delete the stored start page despite unchanged options.

2 open issues
3 resolved since last review

Review effort: Balanced

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Changes recommended

Two critical scraper issues remain: queued processing can delete the resolved root, and Markdown 404 fallback can discard a valid admission decision and delete a still-live page.

2 open issues
2 resolved since last review

Review effort: Balanced

@arabold
arabold force-pushed the feat/refresh-excluded-pages branch from 1c520b0 to d1aeb94 Compare December 5, 2026 20:23
@arabold
arabold requested a balanced review from Copilot December 5, 2026 20:23
@arabold
arabold added this pull request to stack #650 December 5, 2026 20:26

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Changes recommended

Unresolved redirect-identity and pattern-admission defects can delete valid start pages or retain excluded local and GitHub content during refresh.

4 open issues
2 resolved since last review

Review effort: Balanced

… on refresh

A refresh queued every stored page without running the filters a crawl
applies to discovered links, so pages the current options would not admit
stayed indexed. An async isExcluded admission hook on BaseScraperStrategy
now judges discovered links at enqueue and stored pages before they are
fetched, and an excluded stored page is reported as PageOutcome.Excluded
and deleted.

- The base hook applies include and exclude patterns. A stored page with a
  Markdown source is excluded only when neither URL is admitted, and the
  start page is never excluded, including where its URL redirected.
- A crawl judges redirect targets by the same rule, so a scrape and a
  refresh store the same pages.
- LocalFileStrategy excludes hidden paths and symlinks below the crawl root
  per includeHidden and followSymlinks, cached per crawl.
- GitHubScraperStrategy matches repository files by their repository path.
- An HTTP(S) root archive queues no file:// members.
@arabold
arabold force-pushed the feat/refresh-excluded-pages branch from d1aeb94 to 67581d8 Compare December 5, 2026 20:43
@arabold
arabold requested a balanced review from Copilot December 5, 2026 21:04

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Changes recommended

Refresh filtering still misdecodes literal-percent GitHub filenames and ignores local ancestor include patterns, causing valid pages to be deleted or excluded pages to be retained.

2 open issues
4 resolved since last review

Review effort: Balanced

@arabold
arabold merged commit c7fae55 into main Dec 5, 2026
6 checks passed
@arabold
arabold deleted the feat/refresh-excluded-pages branch December 5, 2026 21:35
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