Repository navigation
Description
#295 made the per-page rule-result cache and template fan-out (#279) mutually exclusive: a run with a cache does not build a fan-out at all. This is the design that would let both run.
Why they do not compose today
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, then change the FIRST one — the cluster's representative. It is fresh and records its new verdict; the second page replays the verdict it inherited from the representative's PREVIOUS run, and every fully-replayed audit after that repeats the stale value. A fresh audit gives it the new one. Nothing about the second page changed, so nothing about its key can notice.
Two narrower fixes were tried and rejected. Letting a replayed page abstain from the fan-out changes which page is elected representative. Letting it record instead, keyed on its stored page_features.template_fp, closes that direction and leaves this one.
The shape of a fix
Cache the CLUSTER's verdict, not just the page's, against the identity of the page that produced it:
- a cluster entry keyed on (cluster key, run context, representative's page key)
- on a warm run, a cluster whose representative's page key is unchanged replays its verdicts into the fan-out without any page running them
- a representative whose key moved is fresh by definition, so it runs, records, and members take the new verdict — which is exactly what a fresh audit does
The hard part is that "the representative" is the first page of the cluster in crawl order, a whole-crawl property the streamed loop resolves as it goes, while the cache decides what to replay per batch. Cluster keys ARE available before parsing on a warm run (they are in the cached page_features), so the election can be resolved ahead of the loop.
What it is worth
Measured at 2,500 pages on the synthetic estate: enabling the cache costs the cold rules phase 6.9% (116 s to 124 s), which is fan-out's share plus the cache's writes. Cold wall time was unchanged. So this is worth roughly the fan-out half of that on first audits only; re-audits already replay everything and gain nothing from fan-out.
Related: #275 (the chrome-only cluster key can pair pages that differ in a declared rule's inputs). Turning fan-out off is currently the more accurate of the two answers, because every rule really runs on every page.
Acceptance Criteria
- A run with a rule cache can also fan out template-scoped rules
- A fully-replayed audit produces a byte-identical report to a fresh audit of the same content, including when the changed page is the one whose verdict others inherited
- The cold rules phase with the cache on is no slower than with fan-out on and the cache off
- The regression is covered by a test that fails when the composition is removed
Part of #637.
Activity
feat(audit-engine): the rule cache and template fan-out compose #296
nc9 commentedon Nov 15, 2026
AC3 measurement: cold rules phase, cache on vs fan-out on + cache off
Result: FAIL on the agreed bar. Median CPU, cache cold (B) 15.31 s vs cache off (A) 14.51 s: +5.5%, bar is +3% (B limit 14.95 s). Wall +7.1%. AC3 not met on this measurement.
d41e1fb9da398ac5761ae63a9c0c5a9164e283b3(contains 4279bfd / feat: batch 1113b: third-party docs, ci report address and MCP docs, seed verification, rule cache and fan-out #1805)wollongongservicecompany-com-auproject.db, crawl0b526b6d, 189 pages, all with stored HTML; 2 template clusters, 187 pages inherit a verdict (4,301 rule runs removed by fan-out in BOTH arms). Largest real local crawl that still has its HTML (larger ones such as gymshark 4,000 pages had theirs evicted from the content store).template-fanout-bench.ts --child, streamed page-rule pass only, one child process per run, fan-out ON in both arms. Interleaved ABAB, 9 runs per arm after one untimed warm-up. Scratch copy of the project.db and a scratch content store holding only this crawl's HTML. Every run undersandbox-execwith outbound network denied (curl verified failing under it), serialized through heavy.sh. Load average 2.4 to 3.5 throughout (8-core box).BENCH_RULE_CACHEunset (cache off). Arm B:BENCH_RULE_CACHE=cold: the CLI's own project.db store (createProjectRuleCacheStore+bindRuleCache, run-context hash computed inside the timer), withpage_rule_cachewiped before EVERY run, so every B run is a full miss: 189 fresh, 0 replayed, 189 rows written each time.Local toggle (uncommitted, measurement only)
Per run
Reading
nc9 commentedon Nov 15, 2026
AC3 stays open. The rerun with a permanent bench arm, a 1,000+ page corpus of our own sites and a paired-difference bar is tracked in #1971.
nc9 commentedon Nov 20, 2026
AC1, AC2 and AC4 are met on main by 4279bfd. I've ticked them. AC3 stays open until #1971 runs.
bun test packages/audit-engine/tests/rule-cache-replay-golden.test.ts, re-run today on main at f25906f: 13 pass, 0 fail.fanReplayableinpackages/audit-engine/src/streaming.ts.fanReplayablewithreturn true, so it no longer looks at clusters. Two tests then failed: "changing a cluster's representative re-runs members that inherited its verdict" and "an entry written without fan-out does not replay into a fan-out run". With the change reverted, all 13 pass.nik