Skip to content

fix(crawler): one transition table for crawl and frontier status, checked in the write - #1671

Merged
nc9 merged 2 commits into
mainfrom
fix/frontier-guards-1659
Nov 10, 2026
Merged

nc9 merged 2 commits into
mainfrom
fix/frontier-guards-1659

Conversation

@nc9

@nc9 nc9 commented Nov 10, 2026

Copy link
Copy Markdown
Contributor

Closes #1659

What

crawls.status and frontier.status were last-writer-wins. stop() could write paused over a crawl that had already completed, and a late worker could rewrite a frontier URL that was already finished or that --resume had re-queued.

Both now have a transition table in one place, next to the types in core-contracts (CRAWL_STATUS_TRANSITIONS, FRONTIER_STATUS_TRANSITIONS, canTransitionCrawl, canTransitionFrontier, documented there and in docs/configuration/storage.mdx under "Crawl status"). SQLiteStorage.updateCrawl and updateFrontierStatus check the table in the same statement as the write: the allowed-from list is a bound parameter, so the statement text (and the prepared-statement cache the code already worries about) is unchanged. A write the table refuses changes nothing, the other columns it carried included; it never throws and never aborts the crawl. onIgnoredTransition on the storage reports each refusal (the crawler package has no logger, so this is the debug hook and the test seam).

Crawl edges: running from anywhere; paused from running; completed and stopped from running or paused; crawled from those plus completed/stopped; analyzed from those plus crawled; failed from running or paused. Frontier: fetching from pending; done, failed, skipped only from fetching; pending from fetching (resetStaleFetching).

Acceptance criteria

  • Transitions are listed in one table and storage writes check it.
  • stop() after a terminal status leaves it unchanged: a real crawler test (crawl to completed, then stop(), still completed), plus the storage edges.
  • A frontier entry moves to done/failed/skipped only from fetching, and resetStaleFetching still re-queues only fetching entries.
  • An illegal transition does not throw or abort the crawl.
  • Existing crawler and resume tests pass unchanged.

Characterization first

packages/crawler/tests/status-transitions-1659.test.ts was written and run against the unguarded storage before the guard: its 20 legal-edge tests (every edge the crawler and the CLI use: resume, backstop cut, re-crawl, re-analysis, the frontier pop and finish, resetStaleFetching) were green and its 16 illegal-edge tests red. After the guard all 38 pass. packages/core-contracts/tests/status-transitions-1659.test.ts is the full table, edge by edge (49 crawl pairs, 25 frontier pairs).

Also run, by explicit path, unchanged: full-crawl-harness, crawler-stop-hard-cap, abandoned-crawls, retire-crawls, hot-statements-cached, crawl-lease, crawl-liveness, frontier-exists-cached, unstored-frontier-1396, page-map-701, the CLI stop-interrupted-crawl, retention, streaming-frontier and crawl-loop-concurrency tests, two audit-engine goldens, and the audit-stdout and include-pages e2e. tsgo in packages/crawler and packages/core-contracts, root lint, make validate.

Notes

  • No JSON report field is added, so JSON_REPORT_SCHEMA_VERSION is untouched.
  • Every writer I found (crawler.ts start, resume, restart, stop(), completion; the CLI's crawled and analyzed; the synthetic-site writer) uses an allowed edge.
  • Out of scope, as in the issue: folding status, report_status and the lease into one derived phase.
  • The squirrelscan agent skill needs no change.

@nc9

nc9 commented Nov 10, 2026

Copy link
Copy Markdown
Contributor Author

Note from the private #3874 review (cloud crawl end): the private cloud runtime writes stopped on a hard stop or an unverified end. The crawler's own stop path writes stopped too, which is legal from running, paused and stopped. The one edge this table refuses is completed to stopped: if the crawler finished and wrote completed just before the cloud decision lands as stopped, that write is ignored (and reported through onIgnoredTransition). Narrow race on a rare path, and ignoring it leaves the crawl completed, which is the truthful state. No change needed here, just confirming it is intended before the gitlink bump.

nik

@nc9
nc9 force-pushed the fix/frontier-guards-1659 branch from e9e876a to f27bae3 Compare November 10, 2026 09:24
@nc9
nc9 marked this pull request as ready for review November 10, 2026 09:24
@nc9
nc9 force-pushed the fix/frontier-guards-1659 branch from f27bae3 to 96f57a1 Compare November 10, 2026 10:12
@nc9
nc9 merged commit 97ad536 into main Nov 10, 2026
16 checks passed
@nc9
nc9 deleted the fix/frontier-guards-1659 branch November 10, 2026 10:31
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.

crawler: crawl and frontier status writes have no from-state guard (stop() can write paused over completed)

1 participant