Skip to content

feat(audit-engine): the rule cache and template fan-out compose #296 - #1803

Closed
nc9 wants to merge 1 commit into
mainfrom
r3/cache-fanout-296
Closed

nc9 wants to merge 1 commit into
mainfrom
r3/cache-fanout-296

Conversation

@nc9

@nc9 nc9 commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

Closes #296. Part of #637.

What

A cached page entry now records fan: { cluster, rep }: its fan-out cluster key and the page key of the representative whose template verdicts it holds. A candidate replay is re-checked in the loop (fanReplayable), where every earlier page has already resolved its cluster (a changed page by parsing, an unchanged one from its entry), so the representative is the first page of the cluster in crawl order exactly as in a fresh audit:

  • a representative-form entry replays only while its cluster has no representative yet; a replayed representative records its (unstamped) template verdicts into the fan-out so a member that must run fresh inherits them;
  • a member-form entry replays only while the cluster's representative has the same page key;
  • otherwise the page is parsed on demand and runs fresh, taking what a fresh audit would give it;
  • a representative that is not stored (timeout, no key) unidentifies its cluster so members never replay against it;
  • entries written without fan-out (every pre-existing row) replay only when fan-out is off, no format bump needed.

Acceptance

  • A run with a rule cache can also fan out: a run with a cache fans out template-scoped rules (fannedRuleRuns > 0 cold, warm replays all pages), replaces the old exclusivity test.
  • Fully-replayed audit byte-identical to fresh, including when the representative changes: changing a cluster's representative re-runs members that inherited its verdict (afterChange and fullyReplayed both equal a fresh audit; non-vacuous check that the change moved the report). Existing a fully-replayed audit matches a fresh one across a template cluster and parity tests pass.
  • [~] Cold phase: 600-page synthetic, streamPageRules, interleaved median of 4, one process (noisy): fan only 6656 ms, fan+cache 6866 ms (+3%, the cache's writes, which cannot be zero), old cache-only 7282 ms. So the composition is about 6% faster than before, and within noise-level of fan-only plus its own writes; it is not literally "no slower" than fan-only without a cache. Not measured on the 2,500-page estate.
  • Test fails when composition removed: with fanReplayable forced to true, the representative test and the toggle test fail (verified).

Gates

  • bun test tests/rule-cache-replay-golden.test.ts: 13 pass
  • fanout equivalence/parity goldens + rule-cache-redirect-row-1762 + plugin-rule-pack-1599: 85 pass
  • ignore-rule-cache-1262, ignore-template-fanout-1262, rule-cache-codec, template-fanout-gates-841, unread-page-fanout-1570: 42 pass
  • audit-engine and apps/cli tsgo clean; apps/cli lint and format:check clean; docs make validate: 62 pass

Docs (docs/cli/audit.mdx) and CHANGELOG Unreleased/Fixed updated. No rule meta text changed: the private rule catalog does not need regenerating. The agent skill needs no change.

Residual: a replayed representative's recorded verdict strips only a pageUrl equal to its own page (what the stamp sets).

@nc9

nc9 commented Nov 13, 2026

Copy link
Copy Markdown
Contributor Author

Landed in bundle #1805, rebase-merged to main.

nik

@nc9 nc9 closed this Nov 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Make the rule-result cache and template fan-out compose

1 participant