Repository navigation
perf(audit-engine): bound the merge's site-page work by the run #497 - #586
Conversation
With the untouched findings already an aggregate (#503), what still grew with the site was its page history. The merge session copied site_pages into a merged map, a merged array, an active set and a render-history set, runCloudSmartAudits built two more (carried pages, the sample's render history), and every page row was upserted on every publish. The session now indexes the prior pages once and keeps this run's changes beside them. Active and carried counts are corrected from the run's own pages, carried pages are a PageUrlSet view instead of a copy, sitePages/activePageUrls are built only when read (the CLI's computeMerge still gets both), and the cloud merge upserts only the rows this run changed. Every surface a caller reads is unchanged, and the rows a store ends up holding are the same. Measured with the new bench-untouched-carried.ts, base vs head alternating, min of 5: at 250,000 carried findings on 25,200 site pages vs none, CPU 2.95x -> 1.59x, wall 3.06x -> 1.72x, page rows upserted 25,200 -> 200, outputs hash identically. Signed-off-by: Nik Cubrilovic <[email protected]>
|
Reviewed the diff for #497 (merge-core, merge-promise, scoring, the new tests and the bench script). I found no blocking problems. I traced the new count arithmetic against the old copies:
Findings:
I did not run the tests or the benchmark. |
…r pages #497 Review round 1: document that runCloudSmartAudits hands upsertSitePages only the pages this run crawled, note why changedSitePages is taken once and what PageUrlSet.has answers for, and index the prior pages without copying them when no url repeats. Signed-off-by: Nik Cubrilovic <[email protected]>
|
Round 1, addressed in 6734839:
Tests, typecheck, lint, format and the secret scan are clean. The bench digests are unchanged ( |
…-store-merge-ctljjj Signed-off-by: Nik Cubrilovic <[email protected]>
|
Reviewed the diff (I didn't run the tests or the benchmark). The change looks sound overall. The new index and counts reproduce the old derivations, and the oracle-based tests are a good way to pin that.
|
State the contract on SmartAuditStore.upsertSitePages: a keyed insert or replace on (siteKey, normalizedUrl) that never deletes or resets a row it was not handed, so callers may pass only changed rows. A keyed-upsert reference store shows the publish's changed-rows write leaves the same rows as the previous write of every merged page, on six seeded fixtures with another site's rows alongside. Signed-off-by: Nik Cubrilovic <[email protected]>
|
Store contract for
On the merged head:
Not merging. |
|
Re the review of a13d9cf (the first push):
|
|
Review of #586 (carried-page copies in the merge session). I found nothing that should block the merge.
Tests: |
|
Re the review of 6020063:
No code change from this round. |
|
Status: done from my side. Every check on 6020063 is green (15 of 15). There were two bot review rounds:
Criterion 3 is met on the engine side (1.59x CPU, 1.72x wall). Its hosted re-measure is for after merge. I'm not merging this. |
|
Review of #586: avoiding the per-publish copies of the site's page history in the merge session. I read the diff and the SQLite store's
|
|
Re the latest review (no code change):
|
|
Review of #586 (diff only; I did not run the tests or the bench). The session refactor looks correct. I traced the following and they hold:
Findings:
|
|
Re the review of d8fd939 (no code change; each point is already covered):
|
…-store-merge-ctljjj Signed-off-by: Nik Cubrilovic <[email protected]>
|
Review of #586. I read the full diff and traced The index-plus-overlay approach looks correct. These all match the old derivations:
The oracle-based test (
No correctness blockers found. |
…act #497 The cloud merge hands upsertSitePages only the rows a run changed, which is safe only for a keyed upsert. Nothing enforced that. - tests/helpers/site-pages-contract.ts: the shared cases. A second upsert of a different row keeps the first, upserting an existing key replaces that row only, and rows absent from a call (an empty call included) are never deleted or changed. - Every in-repo implementation runs it: the eight test stores, the bench store (now scripts/bench-store.ts) and SQLiteStorage from the crawler tests. - Two stores violated it and are fixed: rate-limited-coverage's EmptyStore and the bench store both dropped every upserted page. - tests/site-pages-contract-coverage.test.ts scans packages and apps for implementations and fails for one that does not run the contract. Signed-off-by: Nik Cubrilovic <[email protected]>
…e-ctljjj' into claude/bound-complete-store-merge-ctljjj Signed-off-by: Nik Cubrilovic <[email protected]>
|
The
Not merging; it's yours to land. |
|
Re the review posted at 15:13: it reviewed the head before 1f3fbf0, and the review of the current head is still running.
|
|
Review of #586 (diff read; I did not run the tests, and CI was still pending when I looked). The approach is sound. The prior pages are indexed once,
|
|
Re the review of the current head (no code change):
|
|
Reviewed the engine diff (merge-core, merge-promise, scoring, bench scripts). I could not run the tests, and CI was still pending when I looked.
The index/dedup logic (first position, last row wins) looks correct, and the parity and contract tests are the right coverage. |
|
Re the review at 15:41 (no code change): CI is green on 01b8246, 15 of 15.
|
|
On the (medium): the hosting-side store was checked and implements upsertSitePages as a keyed insert-or-update (insert with on-conflict-update on the site and normalized url), never a snapshot replace, and the contract is now documented and enforced for every in-repo store by site-pages-contract-coverage.test.ts. The behaviour change goes in the release notes. |
Refs #497
Summary
Criteria 1 and 2 landed in #503. This PR goes after criterion 3, the 2x bound, on the engine side.
With the untouched findings already handed over as an aggregate, the findings no longer grew the merge's cost. The site's page history did:
createMergeSessioncopiedsite_pagesinto a merged map, a merged array, an active set and a render-history set;runCloudSmartAuditsbuilt two more (carriedPageUrlsthrough apriorStatemap, and the sample's render history);upsertSitePageson every publish, changed or not.At 25,200 site pages, each of those Maps or Sets costs 5 to 8 ms on a cold isolate.
What changed:
merge-core.ts. The session indexes the prior pages once (indexPriorPages: first position, last row, the same as oneMap.setper row) and keeps this run's crawled and removed pages in a run-sized map beside them.activePageCountand the carried count are the prior counts, corrected from the run's own pages.isActivePage,everRenderedandcarriedPageUrlsread the index.sitePagesandactivePageUrlsare built only when read. The CLI'scomputeMergestill gets both, unchanged.changedSitePages: the rows this run wrote.scoring.ts. NewPageUrlSet: size,has, and iteration in order. ASet<string>satisfies it. The streaming merge passes a view over the prior pages instead of a copy.carriedPageUrlsinMergedScoringInputandCompleteStoreTallyInputtakes it.merge-promise.ts.changedSitePages(less the removed pages, as before). Every other row is a prior page exactly asgetSitePagesreturned it, so the rows a store ends up holding are the same.upsertSitePages, with the same end state.scripts/bench-untouched-carried.ts. New harness: one complete-store publish with the untouched split, 0 vs N carried findings.benchmarks/2026-09-perf-program.md. Record of the measurement.Acceptance criteria
Complete-store merge accepts untouched carried pages as an aggregate plus a bounded sample, and folds only touched pages row by row. Landed in perf(audit-engine): take untouched carried pages as a store aggregate #497 #503 (
completeStore.untouchedCarried), unchanged here.Parity suite: the row fold and the touched/aggregate split are byte-identical (tallies, score, coverage, union rule results) on mixed fixtures, including over-cap and advisory rules. Landed in perf(audit-engine): take untouched carried pages as a store aggregate #497 #503. Still green on this head:
tests/complete-store-parity.test.ts, 34 pass (block (e) compares serialized tallies, score, coverage, union, persisted count and the store's rows).CPU and round trips of a publish on a site with 250k carried open findings within 2x of the same publish on a site with none.
Engine evidence: one
runCloudSmartAuditspublish (complete-store, untouched split, in-memory store, the store's aggregate computed before the clock starts).origin/mainatccf9c1f) and head run the same script, one arm per process, alternating base/head and 0/250k, minimum of five. 4 vCPU Xeon 2.1 GHz, Bun 1.4.2.Behaviour is byte-identical
Same-commit A/B: every arm hashes the tallies, score, coverage, persisted count and serialized union. Base and head hash identically (
806b03e2a37a7a4dat 0,866f6c47e809d687at 250k,e5f066f67202f421at 250k/100 per page).New
tests/merge-session-pages.test.ts(13 tests) pins every new answer to the pre-change derivations, copied into the test as the oracle. It runs on 12 seeded fixtures with and without the unsampled signal, built with repeated urls, pages an older audit saw removed, overlapping crawled/removed sets and signal-only crawled pages. It covers:sitePages,activePageUrls,activePageCount,isActivePage,everRendered;carriedPageUrls(size, order,has);changedSitePagesover the prior rows giving the same rows as writing every page.A publish test checks that 5,000 known pages with 20 crawled upserts exactly those 20 and leaves every other row untouched.
Mutation-checked: each of six mutations fails at least one test: the removed-page carried correction dropped; the crawled/removed overlap subtracted twice; the active correction dropped; the repeat-url pass skipped; every page upserted;
everRenderedread as active.Verification
bun test(audit-engine, run in batches of 5 files or fewer):complete-store-parity,cloud-merge,bounded-carried-merge,carried-provenance-merge,sampled-audited-pages: 100 pass;rate-limited-coverage,item-locator-resolve,fingerprint-parity,scan-truncated-carry,merge-scoring: 54 pass;advisory-scoring,output-caps-score-parity,item-finding-identity,golden-baseline,streaming-scoring-golden: 33 pass;merge-session-pages: 13 pass.bun test(apps/cli),tests/audit/smart-audits.test.tsandtests/scoring.test.ts: 50 pass.tsgo --noEmit(packages/audit-engine): clean.bun run format:checkandbun run lint(root): clean. The twooxlintwarnings incomplete-store-fold.tswere already there.detect-secrets-hook --baseline .secrets.baselineon the changed files: clean.cd packages/audit-engine && bun run scripts/bench-untouched-carried.ts --carried=0, then--carried=250000, alternating.Agent skill
No change needed. Nothing user-facing or CLI-facing changes. This is the cloud publish merge's internal cost, and the CLI's local merge output is identical. No docs change for the same reason.
Changelog
Checklist
Signed-off-byline (git commit -s).Generated by Claude Code