Repository navigation
perf(audit-engine): replay an unchanged page's rule results instead of re-running them (#1990) - #295
Merged
Merged
Conversation
added 5 commits
September 8, 2026 20:56
…f re-running them #1990 A second audit of an unchanged site already fetched nothing and was not faster: parse, page rules, the page-time collectors and report reconstruction re-ran in full on every page whether or not that page changed. Crawl reuse is a bandwidth feature; this is the one that makes a re-audit cheap. A page now replays its stored rule results when every input its rules read is unchanged. It is never parsed and its rules never run. Site rules always run. At 2,500 pages, both arms on this build with SQUIRREL_RULE_CACHE=0 as the only difference: the warm rules phase falls from 131 s to 12 s and the warm run from 171 s to 44 s, with the report byte-identical to its cold counterpart across all 3,044,401 bytes. The cold cost is below what the box can resolve. The key covers the page's EXACT html bytes via a new pages.html_hash, not content_hash, which is whitespace-normalized so the incremental crawler can call a reformatted page unchanged; the rest of the page record the rules and extractPageFeatures read, including the three timings performance/ttfb reads; and a run context of the build version, the enabled page rules with their resolved options, and the SiteData entry fields page rules read. A run with threat intel enabled does not replay at all: IntelContext is two functions over feeds that refresh daily, and its configuration identity is not an identity of its verdicts. Template fan-out composes by abstention: a replayed page neither takes a cluster verdict nor becomes a representative. Signed-off-by: Nik Cubrilovic <[email protected]>
#1990 P1, and the interesting one: a replayed page has to RECORD into the template fan-out, not abstain from it. Abstention makes which page runs a template-scoped rule depend on what happens to be cached — on the audit after one page changes, the changed page is the only fresh one and keeps its own verdict, where a fresh audit would have the cluster's first page fan its verdict onto it. The next fully-replayed audit then disagrees with a fresh audit of identical content and persists the disagreement. A replayed page now records, keyed on the page_features.template_fp its own run stored, which reproduces the fresh audit's election exactly. Stored checks drop their own pageUrl stamp so what the fan-out caches stays page-identity-free, and the replay re-stamps as the fresh path does. Gated by a test that adds a viewport meta to one page of a cluster; the gate was mutation-checked and fails without the fix. P1: rules.ignore_applicability changes a gated rule from a skipped check to its real verdict without touching the rule list or any rule's options, so it is now part of the run context. P2, five: the current UTC year is in the run context, because content/stale-copyright reads it at execution and is the only page rule that reads a clock; pages.content_hash and pages.parsed_data joined the page key, the first because extractPageFeatures copies it verbatim and the second because buildSiteContext prefers it over the HTML; the codec keeps Dates and own __proto__ keys, both of which a plain-object walk drops; canonicalJson no longer merges NaN/Infinity/-Infinity or [] with new Array(1); and the warm lookup picks one row per key in SQL instead of decompressing every retained audit's copy, which was work that grew with history rather than with the crawl. Benchmarks re-measured on the fixed code, quiet box: the warm rules phase falls from 106 s to 13 s at 2,500 pages and the report is byte-identical to its cold counterpart. Signed-off-by: Nik Cubrilovic <[email protected]>
…exclusive #1990 The second review round showed the fan-out fix closed only one direction. A fanned verdict belongs to the page's CLUSTER, so no per-page key can capture what it depends on: cache two pages of one cluster, change the FIRST one, and the second replays the verdict it inherited from the representative's previous run while a fresh audit gives it the new one. Nothing about the second page changed, so nothing about its key can notice. Enabling the cache therefore turns fan-out off for that run. Cost, measured: the cold rules phase goes from 116 s to 124 s at 2,500 pages, 6.9%, and cold wall time is unchanged; every audit after the first takes the 89% the cache buys. It also makes the report the one every rule actually computed rather than one where some verdicts were inherited, which is #275's open question made visible. With nothing inheriting a verdict, the pageUrl stripping and record-on-replay the previous commit added are gone: a stored check is what its own page produced. Also from the second round: an invalid Date no longer decodes to the epoch, array holes and -0 no longer canonicalize onto their neighbours, and the year-boundary straddle is documented as bounded (the run stores under the old year's key, and the next audit misses every one of those rows rather than serving one). Gates: the composition test now compares like configurations, and a new one pins the exclusivity directly - with a cache supplied the fan-out does zero work, which an output diff cannot be relied on to show. Signed-off-by: Nik Cubrilovic <[email protected]>
…aying across a year rollover #1990 Third review pass, both reproduced. content/date-agreement resolves a bare schema date through Date.parse, which reads it in LOCAL time, so the same page yields a different year under UTC and under Australia/Sydney: the runtime time zone is now part of the run context. And a long audit can cross UTC New Year while it runs, where content/stale-copyright reads the clock itself and a page replayed after midnight would serve last year's verdict; rather than freeze a year the rule cannot be told about, replay stops for the rest of such a run and those pages are audited normally. Also drops a header comment still describing the fan-out composition design that was rejected two commits ago. Signed-off-by: Nik Cubrilovic <[email protected]>
…1990 Five audits of a 40-page project after rebasing onto automatic retention (#285): two crawls retired, cache rows under exactly the three that remain, and every audit after the first still replays every page. The carry-forward is what makes retiring the crawl an entry came from harmless. Signed-off-by: Nik Cubrilovic <[email protected]>
nc9
force-pushed
the
perf/1990-rule-result-cache
branch
from
September 8, 2026 10:58
cbfd593 to
beac093
Compare
…1990 The entropy detector cannot tell a digest from a credential, and the vectors for "" and "abc" are neither secret nor ours. The documented mitigation is the inline pragma; detect-secrets-hook passes locally with it. Signed-off-by: Nik Cubrilovic <[email protected]>
3 of 4 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A second audit of an unchanged site already fetches nothing. It was not faster, because parse, page rules, the page-time collectors and report reconstruction re-ran in full on every page whether or not that page changed. Crawl reuse is a bandwidth feature; this is the one that makes a re-audit cheap.
A page now replays its stored rule results when every input its rules read is unchanged. It is never parsed and its rules never run. Site-scope rules always run.
What it is worth
2,500 pages of the mixed synthetic estate, both arms on the SAME build with
SQUIRREL_RULE_CACHE=0as the only difference, one pinned origin per pair, fresh content store per pair, load average 2.4 to 4.1.The warm rules phase falls from 110 s to 12 s, against the 50% the issue asked for. All 2,500 pages replayed, and the cache-on cold and warm reports are byte-identical across all 3,039,997 bytes once
meta.timestampand the replay disclosure are removed.Full write-up in
benchmarks/2026-09-perf-program.md.NIK: this turns template fan-out (#279) off whenever the cache is on
They do not compose, and the reason is structural rather than fixable here. A fanned verdict belongs to the page's CLUSTER, so no per-page key can capture what it depends on: cache two pages of one cluster, change the FIRST one, and the second page replays the verdict it inherited from the representative's previous run while a fresh audit gives it the new one. Nothing about the second page changed, so nothing about its key can notice. Two designs that tried to keep both were written and rejected; the review reproduced the failure in each.
The trade, measured in the cold row above: the rules phase goes from 116 s to 124 s, 6.9%, with cold wall time unchanged. Every audit after the first takes the 89%. It also makes the report the one every rule actually computed rather than one where some verdicts were inherited: the cache-on cold report is 3,039,997 bytes against 3,043,863 with fan-out on, which is #275's open question about the chrome-only cluster key made visible.
If you would rather keep fan-out,
SQUIRREL_RULE_CACHE=0does that today and the alternative is the follow-up design (cache the cluster's verdict against its representative's identity). Say the word and I will file it.What makes it sound
The key covers every input a page rule reads:
content_hash, which is whitespace-NORMALIZED so the incremental crawler can call a reformatted page unchanged. Two pages differing only in whitespace share it and parse to different word counts, inline-script lengths and<pre>text, so keying on it would have replayed one page's verdicts onto another's markup — with every existing gate green, because no fixture contains that pair. A newpages.html_hashcarries the exact hash, and it costs nothing to produce: the content store is already addressed bysha256(bytes).extractPageFeaturesread, including the three response timings, becauseperformance/ttfbreads them. That is why replay pays off on a REUSED page and not on a re-fetched one, and the benchmark shows why it must: two independent crawls of the same estate disagree on 27 pages ofperformance/ttfb.@squirrelscan/ruleshas sat at 0.0.1 forever), the enabled page rules in order with their resolved options, the applicability escape hatch, the Stage-0 metadata, the prefetched cloud results, theSiteDataentry fields page rules read, the current UTC year and the runtime time zone.Gated out rather than approximated: a run with threat intel enabled does not replay at all.
IntelContextis two functions over feeds that refresh daily behind a memoized handle, so its configuration identity is not an identity of its verdicts.Review
Sixteen findings across three adversarial
codexpasses, all fixed. The third returned nothing above P2. Beyond the fan-out story:content/date-agreementresolves a bare schema date throughDate.parse, which reads it in LOCAL time, so the same page yields a different year underUTCand underAustralia/Sydney. The time zone is in the key.content/stale-copyrightreads the clock itself. Replay stops for the rest of such a run rather than freezing a year the rule cannot be told about.rules.ignore_applicabilitychanges a gated rule from askippedcheck to its real verdict without touching the rule list or any option.Dates (including invalid ones, which serialize tonull) and own__proto__keys; the canonical form no longer mergesNaN/Infinity/-Infinity,[]withnew Array(1), a hole withundefined, or-0with0.Gates
rule-cache-replay-golden.test.ts— cold, warm-populating and warm-replaying runs over one crawl; the full report must be byte-identical AND the replayed-page count must be right, because a cache that silently does nothing produces identical findings. Plus the template-cluster composition case, the exclusivity itself, and one invalidation case each for content (a whitespace-only edit), engine version, rule selection, rule options and applicability. The composition test was mutation-checked: it fails with the fix removed.page-rule-site-context.test.ts— the declaration falsifier. Runs the real page-rule pass withSiteDatabehind a recording proxy, down to individual script and resource entries, and fails if a rule reads a field the key does not cover.page-rule-cache-store.test.ts— the SQL half: gzip round-trip, carry-forward surviving retirement of the crawl it came from, retirement reclaiming the rows, chunked lookup, one payload per key across ten crawls, andhtml_hashnull without a content store and moving on a whitespace-only edit.rule-cache-codec.test.ts— SHA-256 vectors, canonical-form sensitivity, run-context ingredients, and the tagged codec.Surface
report.rulesCache—{ pagesReplayed, pagesEvaluated, disabledReason? }, in the JSONmetaand as<rules-cache/>in the LLM report. An agent cannot otherwise tell a replay from a fresh audit (fix(core-contracts): pin LINK_TARGET_SET_RULES to the link rules' emitted check names (repo#3022) #1981). LOCAL ONLY:slimForPublishstrips it, because it describes how this machine produced the report rather than the site.--refreshbypasses it, alongside the page cache.SQUIRREL_RULE_CACHE=0is the kill switch, mirroringSQUIRREL_TEMPLATE_FANOUT.SQUIRREL_RULE_CACHE_DEBUG=1prints a digest per run-context ingredient, which is how a cache that silently stops hitting gets diagnosed — it found one such defect during this work.docs/cli/audit.mdx.make validatepasses.Schema 28 adds
page_rule_cacheandpages.html_hash, both additive, both in the ALTER-columns guard, andpage_rule_cacheis retired with its crawl byretireCrawls. Every audit writes an entry for every page it scored, replayed pages included by SQL row copy rather than re-encoding, so pruning older audits never makes the next one cold.Rebased onto the automatic retention window (#285) that landed while this was in review, and verified against it: five audits of a 40-page project leave two crawls retired, cache rows under exactly the three that remain, and every audit after the first still replays every page. That is what the carry-forward is for. The benchmark table was taken just before retention landed; retention adds tens of milliseconds to an audit, against a 44-second warm run.
The cloud passes no store and is unchanged: it has no
project.dbto cache into, andhtml_hashis written only on the content-store path, so nothing is added to the crawl that #1862 made memory-critical.Closes squirrelscan/repo#1990.