Repository navigation
Description
The cloud's complete-store merge (runCloudSmartAudits with completeStore.openPages) reads and folds every open finding the site has, one row at a time, on every publish. Its cost therefore grows with the site's whole finding history instead of with the run. One big historical audit makes every later publish for that site expensive.
The hosting side has since stopped rewriting carried rows that the merge leaves unchanged, which was the larger half. The read and the fold are still O(open findings). Measured on a seeded local Postgres with 2,000 fresh findings: a site holding 250,000 carried open findings costs about 1,000 cursor round trips and roughly 25x the CPU of a site holding none, and every one of those rows changes nothing in the score from one publish to the next.
Why the API cannot bound it alone
For each carried row, these are computed inside the engine:
- the per-rule
IssueTallycontribution: fail units per (check, page) capped atISSUE_PENALTY_ITEM_CAP, plusdetails.additionaland the warn keys (addChecksToTally); carriedDirtyPagesByRule, whichcleanCarriedPassessubtracts fromcarriedPageUrls.size;- the carried and unrendered counts (
coverage); - the report's carried sample: the first 25 checks per rule in primary-key order, the first check of every later class, and per class the occurrences, members, pages,
pagesTruncatedfloor, newestlastSeenAt, and whether every member is carried or every member is unrendered (retainCarried,collapseCarriedReport,reconcileCarriedAggregate).
If a caller leaves the untouched pages out of openPages, the fold counts them as clean carried pages, and both the score and the report sample change. No input exists for supplying those numbers.
Proposed change
Let the complete-store mode take the UNTOUCHED carried pages as an aggregate instead of as rows. A page is untouched when it is not crawled this run, not removed, and has no fresh row. On such a page the merge's decision for every prior is "carry", so its contribution depends only on the stored rows, the rule meta and the site's render history.
- Touched pages still stream as rows. That covers crawled pages, removed pages and pages with fresh rows, which keeps the merge's resolve/stale/carry decisions and the one-call-per-page fold invariant exactly as they are.
- Score: an aggregate per rule. The caller supplies, per page-scope rule, the
IssueTallydelta of the untouched pages (computed per (check, page) bucket with the same unit/cap/additional rules), the number of untouched pages with a finding for the rule (added tocarriedDirtyPagesByRule), and the carried/unrendered counts. On the API side this is oneGROUP BYoverpage_findings, so the store does a single scan instead of a JS row walk. - Report: a bounded sample read. The caller supplies the first
CARRIED_REPORT_SAMPLE_PER_RULEuntouched rows per rule in primary-key order, plus the first row of each later class, interleaved with the touched pages' carried checks in the same orderretainCarriedsees them today. It also supplies the per-class counts the stamps need (occurrences, members, pages,pagesTruncatedfloor, newestlastSeenAt, all-carried / all-unrendered). - Parity tests. Extend
complete-store-parity.test.ts: on fixtures with fresh, carried, resolved, stale, reappearing and unrendered findings, folding everything as rows (today) and the touched/aggregate split must give byte-identical tallies, scores, coverage andunionRuleResults. Include a rule over the sample cap, a class first seen after the budget is spent, and an advisory (severity: "info") rule.
Touched files: packages/audit-engine/src/merge-promise.ts (new input, driving the touched stream and the aggregate) and packages/audit-engine/src/complete-store-fold.ts (accepting tally deltas, dirty-page counts and a pre-ordered sample alongside foldPage). merge-core.ts should not need changes.
The open risk is the SQL twin of addChecksToTally and carriedFindingToCheck (payload items length, details.additional, the m/v/e stash). It has to read the payload exactly as the JS does (non-numbers ignored, floors, a non-array items), or the score drifts. The parity suite has to run it against real Postgres, not only against the JS fold.
Private tracker: the hosting-side half is in place (unchanged rewrites skipped); this is the remaining read-side bound.
Acceptance Criteria
- Complete-store merge accepts untouched carried pages as an aggregate plus a bounded sample, and folds only touched pages row by row
- Parity suite: row fold vs touched/aggregate split byte-identical (tallies, score, coverage, union rule results) on mixed fixtures, including over-cap and advisory rules
- 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
Activity
perf(audit-engine): take untouched carried pages as a store aggregate #…
perf(audit-engine): take untouched carried pages as a store aggregate #…
nc9 commentedon Oct 7, 2026
Current state (2026-10-07): criteria 1-2 are done.
completeStore.untouchedCarried(aggregate plus bounded sample) with the parity block in tests/complete-store-parity.test.ts.Remaining: criterion 3 is close but not met. The hosting PR measured a 250k-carried publish (2k fresh) against a 0-carried publish:
The excess is the larger report rendered at 250k.
nc9 commentedon Oct 7, 2026
Triage 2026-10-07: the criteria heading is renamed to the exact
## Acceptance Criteria, and the existing list is kept as is. Suggested updates to fold in, from a read of the thread and current main:completeStore.untouchedCarried) and folds only touched pages row by rowpackages/audit-engine/tests/complete-store-parity.test.tsshows the row fold and the touched/aggregate split produce byte-identical tallies, score, coverage andunionRuleResultson mixed fixtures, including a rule over the sample cap, a class first seen after the budget is spent and an advisory (severity: "info") ruleNote: Criteria 1-2 are done on main (
completeStore.untouchedCarriedplus parity tests); only the 2x CPU bound remains, last measured at 2.8x whole-handler and about 2.3x for the merge, so it stays open on the performance criterion alone. The body already uses a lowercase## Acceptance criteriaheading that needs renaming.docs(audit-engine): state upsertSitePages delta semantics, reuse prio…
test(audit-engine): pin upsertSitePages as a keyed upsert #497
nc9 commentedon Oct 8, 2026
Status: #586 is ready for review and green on 6020063. All 15 checks pass, including the engine golden tests, the CLI tests and the bot review.
It goes after criterion 3 on the engine side. With the findings already an aggregate (#503), what still grew with the site was its page history: the merge made several copies of
site_pagesand upserted every page row on each publish. Now the merge indexes the prior pages once, takes its counts from the run's own pages, and upserts only the rows the run changed.upsertSitePagesis documented as a keyed upsert, and a reference-store test pins it.Measured on one complete-store publish with 2,000 fresh findings, 0 vs 250,000 carried, base and head alternating, minimum of five:
Before, a publish wrote 25,200 site-page rows at 250,000 carried findings. The outputs hash identically before and after.
Remaining for criterion 3: re-run the hosted publish on seeded Postgres (2,000 fresh, 250k vs 0 carried) once #586 merges, and post the numbers here.
test(audit-engine): run every upsertSitePages store through one contr…
perf(audit-engine): bound the merge's site-page work by the run #497 (#…
nc9 commentedon Oct 10, 2026
Ticked 1 and 2:
completeStore.untouchedCarried(#503, v0.0.105) with parity block (e) incomplete-store-parity.test.ts, which covers the over-cap, late-class and advisory cases. #586 (v0.0.107) brought the engine-side merge to 1.59x CPU at 250k carried. Left: criterion 3, the hosted publish re-measured on seeded Postgres (2,000 fresh, 250k vs 0 carried). Resized to S, since only that measurement remains.nc9 commentedon Oct 26, 2026
Criterion 3 measured on current main (hosted publish finalize against a seeded local Postgres,
finalize-memory-scaleharness, 2,000 fresh findings, carried backlog in thesteadystate, untouched-page aggregate on, two runs each, engine at v0.0.136):So the handler's CPU is 1.8x to 2.3x (mean 2.0x) and its round trips 1.09x, against the criterion's "within 2x": met on round trips, at the line on CPU. The remaining growth is the database read, not the engine: the aggregate query still scans the site's open findings (82x the heap tuples, 25x to 35x the wall time), which is a hosting-side cost (the GROUP BY twin in
apps/api/src/lib/untouched-carried.ts), not the merge. Whether that residual needs its own issue (index or incremental per-site aggregate) is a call for the maintainers; I have not ticked criterion 3.nc9 commentedon Oct 26, 2026
The residual (the hosted aggregate query scan, 82x heap tuples and 4 to 7 s wall at 250,000 carried) is tracked privately as squirrelscan/repo#3507. Criterion 3 stays open until that lands or is restated.
nc9 commentedon Oct 30, 2026
Checked against main (23a34c1, v0.0.144). Criteria 1 and 2 hold on main. Criterion 3 stays open: the maintainer's measurement shows round trips at 1.09x and CPU at about 2.0x, but wall time at 25 to 35x and 82x heap tuples; the residual hosting query is tracked privately (repo#3507).
nik
nc9 commentedon Nov 15, 2026
No engine work is left: criteria 1 and 2 are done on main (untouched-carried fold from #503, plus the parity suite block (e)). Criterion 3 (CPU and round trips within 2x at 250k carried) measured 1.09x round trips and about 2.0x CPU on the hosted publish. The remaining cost is the hosted aggregate query, which is tracked on the hosting side, not in this repo. This stays open until that lands and the measurement is re-run; labelled blocked so agents skip it.
nc9 commentedon Nov 16, 2026
Publish measurements from the cloud side (finalize-memory-scale harness, Postgres 17, 2,000 fresh findings, two runs per case):
Round trips are within 2x (1.07x). Process CPU is about 2.1–2.9x and wall about 18–24x: the remaining cost is one aggregate query that scans every open finding. Leaving this open until that query is optimised; the fix is tracked privately.