Skip to content

fix(crawler,cli): interrupted report builds are recovered; superseded rows of retired crawls collected once #288 #289 - #1363

Closed
nc9 wants to merge 2 commits into
mainfrom
fix/retention-289-288
Closed

nc9 wants to merge 2 commits into
mainfrom
fix/retention-289-288

Conversation

@nc9

@nc9 nc9 commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #288
Fixes #289

#288: an audit killed while building its report (reworked after review: conservative, never delete when in doubt)

SQLiteStorage.listInterruptedReports() lists a building crawl only when ALL hold: its build began more than 6 hours ago (new crawls.building_at, stamped by setReportStatus(..., "building"), migration 40; a crawl from before that waits 7 days on its last page write), a LATER audit of the project completed with a report, and its owner is not live (isLeaseLive: a heartbeat under 5 min, or an owner pid alive on this host however old the heartbeat, so a laptop asleep over a weekend is live; another host with a stale heartbeat cannot be probed, so only the 6 h build clock covers it). retainRecentAudits retires one only when at least keep openable audits are newer than it, so the candidate ordering stays the authority on the window: a crawl squirrel analyze rebuilt (it leaves building on purpose, #955) and that sits inside the window is never retired. retireCrawlsDetailed re-checks the predicate inside its transaction. self disk --prune plans around a still-building crawl (listed under skipped as building, not counted, not retired) and reports how many audits the transaction held back.

#289: rows superseded before automatic retention

Migration 39 only creates a marker table. repairSupersededPagesOnce() walks the retired crawls' rows by rowid in transactions of 500 rows (a legacy inline-html db measured about 3 s of write lock per 5,000 rows, so the chunk is small) with a cursor stored beside the marker (a row that stays is examined once, not once per chunk), stops after a 2 s budget per call (at least one chunk), and writes the marker only when a pass finds nothing left to examine and runs from retainRecentAudits and runProjectPrune, never from init(), so no command that merely opens project databases (self disk) pays for it and no writer waits on one long transaction. A url whose only row is in a retired crawl keeps it. The CHANGELOG notes that a removed row was the db's only pointer to that page's stored HTML (corpus users).

Tests

packages/crawler/tests/retention-289-288.test.ts (14): init does not delete; repair removes superseded rows once, keeps only copies, is chunked and resumable (partial run leaves no marker); building_at is stamped and untouched by analyze's keepBuilding; 7 h building is listed, 1 h is not whatever its pages' age, legacy NULL waits a week; owner pid alive with a 3-day-old heartbeat is live; fresh other-host heartbeat live, stale one only after the clock; newer-than-every-finished never listed; in-transaction re-check; query plan scans no pages or frontier. apps/cli/tests/audit/retention.test.ts: killed audit recovered with 3 newer audits, an analyze-rebuilt audit inside the window is not retired, a just-started build is left alone. tests/self/disk-prune.test.ts: the plan skips a building crawl.

Gates: tsgo in crawler and apps/cli, apps/cli lint and format, crawler liveness, abandoned, url-index, lease and migration tests, retention and disk-prune tests, make validate. Schema version is now 40 (39 marker table, 40 building_at). Schema 39 collides with draft #1205: whoever merges second renumbers. Skill: no change needed. CHANGELOG under Unreleased / Fixed.

Re-review follow-ups: rowid cursor + per-call 2 s budget (tests: many only-copy rows cost chunks not chunks squared; budget 0 does one chunk per call and later calls finish); the pid-reuse limit of isLeaseLive is documented in code (space only, never data). Rebased on main (schema 38 there; 39 and 40 here).

Chunk round: default chunk 500 (was 5,000); retention-289-288 now has 17 tests (new: default chunk is 500).

…ely; superseded rows of retired crawls collected once, in budgeted cursor chunks #288 #289

Signed-off-by: Nik Cubrilovic <[email protected]>
@nc9
nc9 force-pushed the fix/retention-289-288 branch from d9035d0 to 1e622aa Compare October 30, 2026 19:34
@nc9

nc9 commented Oct 30, 2026

Copy link
Copy Markdown
Contributor Author

Landed in v0.0.145 as d24f4d27 e4d6c671 via #1377. Release: https://github.com/squirrelscan/squirrelscan/releases/tag/v0.0.145. Closing this original.

nik

@nc9 nc9 closed this Oct 30, 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

1 participant