SIGN IN SIGN UP

perf+test: close out the deferred audit items

Tests for the previous round's machinery (highest-value item — none of it
had direct coverage):
- update-docc-gate.test.js: index gate 304-skip, first-sight, changed-etag,
  404 fallback, periodic + --full sweeps, crash-safe ETag commit, and
  index-tree seeding — against a local Bun.serve via APPLE_DOCS_API_BASE.
- update-flat-guard.test.js: mass-tombstone refusal, partial discovery,
  normal small-set deletion.
- tombstone-resurrection, index-body state machine (full-checkpoint resume,
  scan-start stamp, empty-body FTS cleanup), codepoint-stamp skip gate,
  minify stamp + orphan sweep in consolidate.test.js.

Request-path improvements:
- Conditional GET check-and-fetch (fetchDocPageIfChanged + adapter
  checkAndFetch): one request where HEAD+GET needed two; 304 costs the same
  as the old HEAD, a 200 carries the payload.
- Index-diff discovery: the gate now GETs the per-root index and seeds
  unknown same-root paths into crawl_state — authoritative new-page
  discovery instead of relying on modified parents to link them.
- crawlRoot: refill worker pool replaces per-500-page batch barriers (one
  slow page no longer convoys its root); stats once per 250 completions.
- fetchGitHubTree fails loudly on the API's truncated flag instead of
  returning a silent partial listing to discovery.

Write-path and storage:
- pages is now a crawl ledger on the persist path: content columns (title,
  role, abstract, platforms, declaration, min_*) stay documents-only —
  verified zero production readers of the pages copies — and converted_at
  folds into the upsert, cutting persist from 3 statements to 2 and one
  row-image per page.
- v30 migration: fts5vocab companion for the trigram index, partial index
  for role='sampleCode' discovery (was a 1.3s full scan per sync), drop
  unused idx_sections_kind.
- Orphan document_relationships sweep in consolidate (776 on the live
  corpus); integrity sampling via rowid probes instead of ORDER BY RANDOM.
- getRootById memoized per DocsDatabase (one lookup per persisted page).

Search:
- Fuzzy tier ORs only the ~8 rarest corpus-present query trigrams (DF from
  the new vocab table) instead of all ~18 — posting-list unions shrink by
  an order of magnitude with no recall loss at edit-distance ≤ 2.
- Snippet data + related counts + semantic row fetch routed through the
  reader pool (were main-connection calls serializing MCP requests).
- Resources phase starts right after discovery and overlaps the
  network-bound update phase; sync's finally awaits it before teardown.

Reporting: crawl 'Done' logs this-run counts (not lifetime totals);
update_log includes the update phase's mod/del/err counts; surviving
check-error paths logged with a sample; tombstone-counter resets only
issued when a streak exists (drops ~343k no-op UPDATEs per sweep).

Benchmarks now measure the product: search-bench runs the full tier
cascade over a 20k-doc synthetic corpus with body FTS (p50 0.2ms → 4ms of
real work measured), highlight-bench uses 500 unique snippets instead of
90% LRU hits. Baselines re-recorded; the recorded 'regression' is the
fixture change.
G
Gigi committed
d190afd6df9fa942102c3e6071dd984deafeeead
Parent: f8d2685