Skip to content

keep_audits never retires crawls from killed audits, project.db grows without bound #941

Closed

Description

@deniskern

Summary

[storage] keep_audits never retires crawls whose audit process was killed before the analyze step (status crawled, or running for older ones). On a host where audits are occasionally killed (watchdog, OOM, deploy), these abandoned crawls pile up forever, and project.db grows until the next audit becomes slow enough to be killed again.

Repro (v0.0.117, macOS)

# squirrel.toml
[project]
name = "oh-repro-retire"
url = "https://shopware.dev.one-dot.io"
[storage]
keep_audits = 1
[crawler]
max_pages = 15
  1. Run squirrel audit https://shopware.dev.one-dot.io -C surface -f json -o out.json --no-publish --debug three times and kill -9 each one as soon as the log prints step 1.5+2: pre-rules walk.
  2. Run the same audit once more to completion (✓ Audited 15 pages).
  3. Inspect ~/.squirrel/projects/oh-repro-retire/project.db:
{"id":"7021c515","status":"crawled","retired":0,"pages":15}
{"id":"8fe2e74a","status":"crawled","retired":0,"pages":15}
{"id":"cd60f577","status":"crawled","retired":0,"pages":15}
{"id":"cef2165e","status":"analyzed","retired":0,"pages":15}

squirrel self disk --prune --keep 1 --project oh-repro-retire --dry-run lists exactly those 3 as retirable, so the manual path knows about them; the automatic keep_audits retirement after a successful audit does not.

Actual (production)

One project with a 15,000-URL sitemap: 36 crawls in project.db (keep_audits = 3), 22,887 pages rows, 1,057,882 sitemap_urls rows, 2.3 GB. The silent pre-rules phase of a 104-page audit then took longer than our 5-minute no-output watchdog, which killed it and added yet another orphaned crawl. Other projects: 5.5 GB, 2.2 GB, 1.5 GB.

Expected

The keep_audits retirement at the end of a successful audit also retires older crawls that never reached analyzed (or at least those older than the newest kept audit), the same set self disk --prune finds.

Nice to have

A progress line during the pre-rules walk (it can run for minutes without any stdout in non-TTY mode), so supervisors can tell a slow phase from a hang.

Tested: 0.0.117 (repro), 0.0.115–0.0.117 (production).

Acceptance Criteria

  • After a successful audit with [storage] keep_audits = N, crawls left in running, paused, stopped or crawled that are older than the newest finished audit of the project and have had no activity (no page fetched) for 30+ minutes are retired too: killed crawls become eligible 30 minutes after their last activity, so the next audit or prune after that wait retires them (the issue's repro, with the 30-minute wait, ends with 1 non-retired renderable audit plus the 3 killed ones retired, not 4 live rows)
  • The newest crawl, and any non-finished crawl newer than the newest finished audit, is never retired by the automatic pass (it may be a live or resumable audit)
  • Orphaned crawls no longer count toward the keep_audits window and never take a slot from a finished audit
  • squirrel self disk --prune --keep N --project <p> --yes on a project containing killed-audit crawls retires them and the old finished audits, and exits 0 instead of throwing Refusing to retire ... not finished
  • --prune across many projects continues past a project that fails (locked db, unreadable, low disk for VACUUM), prints a per-project line with the reason, prints a final summary (retired / skipped / failed counts, bytes reclaimed), and exits non-zero only when at least one project failed
  • --prune --dry-run lists abandoned crawls separately from finished audits, with each crawl's status and age, and deletes nothing
  • A crawl that looks live (non-finished and newer than the newest finished audit) is skipped with a stated reason in --prune output, not an abort
  • squirrel audit resume (--resume) of a running/paused/stopped crawl still works for the newest crawl of a base URL, and squirrel crawl then squirrel analyze on the newest crawled crawl still works
  • Existing project databases need no manual step: the fix works on a project.db written by v0.0.115 to v0.0.117, and any schema change is an additive migration
  • The six stuck projects' scenario (36 crawls, 1M sitemap_urls rows) reclaims the file size after one --prune --keep 3, verified by a fixture or measured run
  • Tests cover: abandoned-crawl selection, retention retiring orphans, prune continuing after a per-project failure, exit codes, dry-run output, and the resume/analyze exclusions
  • User-facing docs for self disk and [storage] keep_audits describe abandoned crawls and the new prune summary/exit codes (make validate passes), and the CHANGELOG has an entry

Activity

  1. deniskern commented on Oct 19, 2026

    @deniskern
    Author

    Follow-up: the manual path does not help either. On the production project, squirrel self disk --prune --keep 3 --project <p> --yes (v0.0.117) aborts the whole prune:

    StorageError: Storage error during write: Error: Refusing to retire 12 crawl(s) that are not finished: 0276e70a-…, 07dcd7ef-…, …
    

    The "not finished" crawls are the ones whose audit process was killed days ago (status crawled/running, no process alive). So once a project has a single killed audit, neither keep_audits nor self disk --prune can ever reclaim it; 6 of our 73 projects are in that state. Expected: crawls with no live owner (or older than the newest finished audit) count as abandoned and are retirable, or prune skips them and retires the rest instead of aborting.

  2. added
    bug
    P1
    performance
    size: M
    on Oct 20, 2026
  3. nc9 commented on Oct 20, 2026

    @nc9
    Contributor

    Hey Denis, thanks again for the detailed report. This is fixed on main and ships in the next release (0.0.119). Crawls from killed audits are now retired by keep_audits and by self disk --prune once they've been idle for 30 minutes, so after upgrading the next audit or prune reclaims your stuck projects. Prune also carries on past a project it can't handle, and tells you what it skipped and why. One thing to know: stopped and paused crawls (the ones --resume continues) are kept for 7 days. The pre-rules progress line is a fair ask and we'll track it separately. And your og:image report on hreflang alternates is next in our queue.

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

    P1bugperformancesize: M

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions