Skip to content

Page rows superseded before automatic retention shipped are never collected #289

Closed

Description

@nc9

Retiring a crawl keeps the page rows that are, at that moment, the freshest record of their url: that is what stops a retirement turning the next re-audit into a cold crawl. A later audit can crawl one of those urls again, which supersedes the kept row, and the crawl it belongs to is by then retired.

Automatic retention (#285) collects those, but only for the urls the audit that just ran actually wrote:

DELETE FROM pages WHERE rowid IN (
  SELECT p.rowid FROM pages p
  WHERE p.normalized_url IN (SELECT normalized_url FROM pages WHERE crawl_id = ?)
    AND EXISTS (... a newer row for this url ...)
    AND (SELECT retired_at FROM crawls c WHERE c.id = p.crawl_id) IS NOT NULL
)

That is deliberate. It keeps the pass proportional to the audit rather than to the project's history, and it is complete for everything that happens from #285 onwards, because a row can only become superseded by an audit crawling its url again, and that audit sweeps its own urls.

What it does not cover is supersessions that happened before #285 shipped. The only thing that retired a crawl before it was squirrel self disk --prune (#259), so the population is limited to users who ran that command in the days between the two, and the leak is at most one dead page row per url they have since re-crawled. Small, but it is the one case where the invariant "a retired crawl holds no superseded page rows" is not true, and anything reasoning from that invariant later would be wrong.

The obvious fix is the wrong one. Sweeping every retired crawl costs one index probe per audit the project has ever retired, on every audit, forever, which is the shape of cost #285 spent three attempts removing (see the benchmarks file). Options worth weighing: fold it into self disk --prune, which already rewrites the file and is explicitly user-triggered; or run it once per project behind a marker, so it is a one-time repair rather than a recurring pass.

Acceptance Criteria

  • Page rows belonging to a retired crawl that a newer row supersedes are removed even when the supersession predates automatic retention
  • A url whose only row belongs to a retired crawl still keeps that row, so an incremental re-audit still serves it from cache
  • The repair does not add per-audit work proportional to the number of crawls the project has retired, asserted through a query plan
  • A test covers a project in the pre-feat(cli): keep the last 3 audits of a project and retire the rest (#1912) #285 state: a crawl retired by self disk --prune, then a later audit that re-crawls one of the urls it kept

Follow-up from #285. Part of squirrelscan/repo#1912.

Activity

  1. added
    bug
    P3
    size: S
    on Sep 8, 2026
  2. nc9 commented on Oct 11, 2026

    @nc9
    ContributorAuthor

    Checked against current main (ad95fb2): STILL TRUE, but the leak is narrower than the title says.

    collectSupersededPages (packages/crawler/src/storage/sqlite.ts, from line 4602) is keyed on the urls the current crawl wrote. It deletes any row for those urls that has a newer row and belongs to a retired crawl. A row superseded before #285 is therefore collected the next time any audit crawls its url again. The doc comment at lines 4615 to 4619 says the same: "Rows superseded before this existed are collected the next time their url is crawled rather than swept eagerly".

    What actually leaks is a pre-#285 superseded row whose url is never crawled again, for example a page that has left the site or now falls outside the crawl scope. apps/cli/src/self/disk.ts counts retired crawls but has no superseded-row repair, so the options in the issue (fold it into self disk --prune, or a one-time pass behind a marker) still apply. The test in criterion 4 should use a url that is not re-crawled afterwards.

  3. added theissue type on Oct 28, 2026
  4. nc9 commented on Oct 30, 2026

    @nc9
    ContributorAuthor

    Verified against main after v0.0.145. Met: criteria 1, 2 and 4 (the repair removes superseded rows, keeps the only copy of a page, and the pre-retention state is reproduced in a test). Open: criterion 3 has no EXPLAIN QUERY PLAN assertion for the repair or its per-audit marker probe (cost per audit is bounded by a done-marker, a cursor, chunks and a time budget, covered by behaviour tests only). Leaving this open for that assertion.

    nik

  5. nc9 commented on Oct 31, 2026

    @nc9
    ContributorAuthor

    Shipped in v0.0.148 (982219cd 8cf6df9d), verified against main: every acceptance criterion is met. Release: https://github.com/squirrelscan/squirrelscan/releases/tag/v0.0.148

    nik

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3bugsize: S

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions