Repository navigation
fix(audit-engine): refuse producer-carried checks as this run's evidence (squirrelscan/repo#2063) - #326
Merged
Conversation
A published report is the UNION of the crawl and the producer's own finding store, with the replayed half tagged `provenance: "carried"`. The cloud merge read every check's `pageUrl` as a page crawled this run, so a machine whose local store still held an old audit turned it into cloud state: findings first seen at the publish instant on pages the crawl never opened, and 129 "audited pages" for a 16-page crawl. Two runs of the same site three minutes apart scored 50 and 88. - `runCloudSmartAudits` drops carried/unrendered checks from `crawledUrls`, `freshFindings`, the union's fresh side and the #1167 sample sets. The cloud's OWN carry is unaffected: it is replayed from the store with the date the cloud last saw it. Surfaced as `replayedChecksDropped`. - `foldOverflowChecks` keys groups on provenance as well as issue class. A mixed group folded to an aggregate with no provenance, which reads as evidence from this run, so a rule with enough carried pages to overflow the cap laundered every one of them. - `buildStreamFindings` / `buildSkippedPassCounts` apply the same exclusion on the complete-store path, and `buildResolutionSignal` stops spending its budget on pages the run never evaluated. Second half of the same bug: page identity was query-BLIND, so 384 `?id=N` pages collapsed into one stored URL carrying 362 copies of one rule's finding. Adds `normalizePageUrl` (query-preserving, everything else unchanged) and uses it for page identity in the merge, the streamed findings and the resolution hashes. `normalizeUrl` keeps its query-blind semantics for the comparisons that want them (sitemap matching, link-count buckets, cache keys). The merge accepts a resolution hash under either spelling, so an older publisher over-carries rather than resolving a finding that is still there. Closes #2063 Claude-Session: https://claude.ai/code/session_0174D96WamG9ZhJxRudpeniA Signed-off-by: Nik Cubrilovic <[email protected]>
… report Review follow-up to the #2063 fold change. `complete-store-fold` counted `(name, status)` classes and used that count as the re-fold's `maxChecks`, so a class that now splits into a carried and an unrendered aggregate was capped at one: the two merged, an occurrence went missing, and the survivor was then reconciled against a class key it no longer matched, which deleted its provenance and last-seen. Keys the accumulator, the cap and the reconciliation on the shared `foldGroupKey`. Also tie-breaks the fold's sort on that key. Provenance splits a class into up to three aggregates, which `(name, status)` no longer separates, leaving their order to rule execution order — nondeterministic (#114), so a repeat audit could emit a different byte sequence. Two existing tests asserted the old mixed-provenance behaviour and now assert the split; one fixture gains a `site_pages` row so the drop it exercises still happens. Documents the complete-store identity contract (producer and consumer must run one engine build) and why coverage counts evidenced pages rather than the raw crawl count; the residual sampling gap is #2067. Claude-Session: https://claude.ai/code/session_0174D96WamG9ZhJxRudpeniA Signed-off-by: Nik Cubrilovic <[email protected]>
…r seen #2063 ran for a month with nothing saying it was happening. The count of refused checks cannot say it either: an ordinary partial re-audit replays thousands of them for pages the cloud knows, and carries those from its own store as always. `replayedUnknownPages` counts the pages a producer's replayed checks named that this site has no record of — not crawled this run, not known from any earlier audit. That is the mechanism, not a proxy for it: 508 such pages against a 16-page crawl was the incident. The set is bounded by pages, built only in the sampled branch, and dropped once counted. Claude-Session: https://claude.ai/code/session_0174D96WamG9ZhJxRudpeniA Signed-off-by: Nik Cubrilovic <[email protected]>
nc9
force-pushed
the
fix/2063-carried-provenance-merge
branch
from
September 12, 2026 05:19
ead9f89 to
91487b5
Compare
Acceptance review found the sampled branch covered and the complete-store branch not. It copied the staged shell's checks into `freshResults` unchanged, and the shell is that path's report body: a producer's replayed check reached `freshForUnion` and the union, landing beside the cloud's own carry for the same page, with the producer's date, on a page the crawl never fetched. Reproduced in both the materialized and the streamed variant. Complete mode deliberately does not unfold — the shell's aggregates ARE its display surface — so a replay arrives there as a per-page check OR as a folded aggregate naming its pages. `isReplayedCheck` now matches both, using `unfoldAggregateCheck`'s own gate so the two branches agree on what an aggregate is. Genuine site-scope checks stay: the tally fold scores those verbatim. Every rule keeps its key even when all of its checks go, because the fold reads rule membership to decide which rules the shell already handled. The filtered shell is what both tally-fold entry points read now, rather than the raw input. Tests, each checked by removing the one line it protects: a genuinely truncated carried aggregate whose sample names a page the fresh aggregate clipped out (the shape that resolves a finding the crawl never re-examined), both complete-store variants asserting union contents, `unrendered` as check and as aggregate, and the two `stream-findings` guards. Claude-Session: https://claude.ai/code/session_0174D96WamG9ZhJxRudpeniA Signed-off-by: Nik Cubrilovic <[email protected]>
…pties Review nit on the previous commit: the complete-store tests asserted union contents but never the tallies, and every rule in them kept a check — so nothing failed when the emptied rules were dropped from the shell or when the folds were handed the raw input. A page rule whose every published check is a replay ends up with no checks and must still keep its KEY, because `foldShellRules` reads rule membership to give it the fresh-clean pass count for the pages the crawl found nothing on. Dropping it loses those passes out of the denominator, which is #918 in miniature. The new test asserts that tally directly and fails if the key goes. Also corrects two comments the review caught: dropping an emptied rule loses fresh-clean passes rather than double-counting, and the page-attribution gate reads the CHECK's shape rather than the rule's scope — an aggregate naming pages is a page replay whichever rule emitted it. Documents that the refused-check counter's unit differs by mode, since the sampled branch unfolds before it filters and complete mode never unfolds. Claude-Session: https://claude.ai/code/session_0174D96WamG9ZhJxRudpeniA Signed-off-by: Nik Cubrilovic <[email protected]>
nc9
added a commit
that referenced
this pull request
Sep 12, 2026
squirrelscan/repo#2072 recorded 258 checks in the incident report tagged `fresh` on 88 pages the crawl never fetched, in three rules, and no server can refuse a `fresh` label. The mechanism turned out to be the one #326 had already fixed, so this adds the test that proves it rather than a second fix. Every one of those checks carries `details.pagesTruncated`, which only `unfoldAggregateCheck` leaves on a per-page check — so they are the expansion of a sampled AGGREGATE that reached the server with no provenance. An aggregate loses its label when its fold group is mixed, and a rule emitting two checks per page overflows `maxChecksPerRule` as soon as the producer's local store is large: 16 crawled pages plus 481 replayed is 994 checks for one rule. The report stamps `pagesTruncated: 497` on those checks, exactly 16 + 481 for one check name, which is what identifies the path. The test drives the whole chain — producer fold, publish sample, server merge — because neither half alone catches it: the fold change is invisible without a merge asserting the pages, and the merge filter is invisible without a fold that labels what it produces. Reverting `foldGroupKey` to (name, status) fails it and nothing else. No behaviour change: the fix shipped in #326, whose CHANGELOG entry covers it. Closes squirrelscan/repo#2072 Claude-Session: https://claude.ai/code/session_0174D96WamG9ZhJxRudpeniA Signed-off-by: Nik Cubrilovic <[email protected]>
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.
Fixes the engine half of squirrelscan/repo#2063. The private half (the API's one-off repair for the affected site) is a separate PR on the monorepo.
What was wrong
A published cloud report is the UNION of the crawl the CLI just ran and the CLI's own local finding store, with the replayed half tagged
provenance: "carried".runCloudSmartAuditsread every published check'spageUrlas a page crawled this run, so a machine whose local store still held an old audit turned that audit into cloud state: findings stamped first-seen-today on pages the crawl never opened, and 129 "audited pages" for a 16-page crawl.Two runs of the same site, three minutes apart, identical config, scored 50 and 88.
The second half of the same bug: page identity in the store used
normalizeUrl, which strips the query string, so 384/tools/…/project?id=Npages collapsed into onepage_findingsURL carrying 362 copies of one rule's finding.What changed
Carried checks are not evidence.
runCloudSmartAuditsdrops checks taggedcarried/unrenderedfromcrawledUrls, fromfreshFindings, from the union's fresh side and from the #1167 sample sets. The cloud's OWN carry is untouched: it is replayed from the cloud store with the date the cloud last saw it. The count of refused checks is returned asreplayedChecksDroppedso an inflated publish is visible without re-reading the report out of R2.And it says when it happens. #2063 ran for a month with nothing reporting it, and the count of refused checks cannot report it either: an ordinary partial re-audit replays thousands of them for pages the cloud knows perfectly well.
replayedUnknownPagescounts the pages a producer named that this site has NO record of, which is the mechanism rather than a proxy for it. 508 such pages against a 16-page crawl was the incident. The API logs on that number.The fold keys on provenance.
foldOverflowChecksgrouped on(name, status)only, andfoldGroupcan keep a "carried" label only when every constituent carries it — so a mixed group folded to an aggregate with no provenance, which reads as evidence from this run. On a site big enough to overflowmaxChecksPerRule, exactly the rules with hundreds of stale carried pages are the ones that overflow. Groups are now homogeneous, the sort tie-breaks on the same key so a repeat audit stays byte-identical, andcomplete-store-foldcounts classes the same way.Complete-store mode too. The staged shell is that path's report body, and it flows into the union — so a replay in it would sit beside the cloud's own carry for the same page, with the producer's date, on a page the crawl never fetched. Complete mode deliberately does not unfold, so the filter there matches page checks AND folded aggregates by their
pages[], and the same filtered shell is what the tally fold reads. Genuine site-scope checks are kept: the fold scores those verbatim.Same exclusion on the other producers.
buildStreamFindingsandbuildSkippedPassCountsskip replayed checks (the complete-store path's version of the same laundering), andbuildResolutionSignalstops spending its budget on pages the run never evaluated.Query strings are part of a page's identity. New
normalizePageUrlin@squirrelscan/utils— identical tonormalizeUrl(lowercased scheme/host, preserved path case, no trailing slash, no fragment) except it keeps the query verbatim, parameter order included.I chose (a), a new function for the page-identity path, not (b), changing
normalizeUrl. I checked every caller:site-query.ts(incoming-link buckets),cloaking-probe.tsandadapter.ts(sitemap ↔ crawl matching), andapi/services/providers/dead-links.ts(external-URL cache key) all want the query-BLIND comparison, and the crawler and threat-intel packages have their own normalizers. Only the finding-store path was wrong, so only it moved:merge-promise.ts,stream-findings.tsandrules/resolution.ts.The trailing-slash collapse is deliberately unchanged, which keeps every existing
page_findingsrow keyed as it is today. Only pages with a query string re-key.Version skew. The resolution signal's URL hashes are computed by the publisher, so an older CLI hashes them query-blind.
merge-corenow accepts either spelling. Every consequence of the extra hash is a carry: a hit innotEvaluatedcarries, a hit infailingcarries, and a miss infailingis the only branch that resolves. The worst case is two query URLs sharing a path both carrying when one still fails.Acceptance criteria
runCloudSmartAuditsexcludesprovenance: "carried"checks fromcrawledUrlsandfreshFindings; a report whose only checks for page P are carried leaves P untouched, never persisted with first/last-seen = publish time —carried-provenance-merge.test.ts, "a 16-page crawl published with 400 carried pages audits 16 pages" asserts the store holds 2 rows, none on a carried URLcoverage.auditedPagesequals the pages the CLI actually crawled — same test, 16 fresh + 400 carried pages givesauditedPages: 16. See the note below on the residual sampling gaplastSeenAt, or are dropped, never re-stamped to now — they are dropped from the union, and the cloud's own carry keeps the cloud's date ("the cloud's OWN carry still works, with the date the cloud last saw it")normalized_url— "/p?id=1 and /p?id=2 are two findings, not one", plus a re-crawl test showing only the re-crawled one resolvesEvidence
Against
origin/mainthe original eight tests are 7 fail / 1 pass. The single pass is the trailing-slash case, which is a pure regression guard: reverting the normalizer preserves that behaviour by design. The older-publisher test does fail on main, because main never creates the query-specific store key in the first place.Each later test was checked the same way, by removing the one line it is meant to protect: the sample-set exclusion, the complete-store filter, and the two
stream-findingsguards each fail their own tests and nothing else.What this does NOT fix
Replaying the incident's stored report through the fixed engine drops 3,232 replayed checks and reports 401 pages the cloud has no record of, but still lands on 111 audited pages rather than 16. The residue is 258 checks the CLI tagged
freshon 88 pages it did not crawl, concentrated in exactly three rules (ax/token-weight87,perf/unminified-js86,perf/critical-request-chains85). Every one of those 88 URLs also appears CARRIED in the same report, from other rules, so the report contradicts itself.The server cannot refuse those: a
freshlabel is the producer's assertion that it observed the page, and there is nothing else to check it against. Filed as squirrelscan/repo#2072 with the evidence. It is a producer-side tagging gap, so the fix ships with a CLI release rather than a deploy.Codex review
Three findings, all addressed:
[P1] The complete-store report builder dropped a provenance group. Real, and mine:
complete-store-fold.tscounted(name, status)classes and used that count as the re-fold'smaxChecks, so a class splitting into a carried and an unrendered aggregate was capped at one, merged, and lost an occurrence — then reconciled against a key it no longer matched, deleting its provenance and last-seen. Fixed by keying the accumulator, the cap and the reconciliation on the sharedfoldGroupKey. Regression test added, plus two existing tests updated: they asserted the old mixed-provenance behaviour, which no longer exists.[P1] Mixed-version complete ingest could wrongly resolve a query-specific finding. Correct in principle, not fixed — documented as an identity contract at
merge-promise.ts. Complete mode is the one place absence authorises a resolve, and the fresh set is keyed by the container while the crawled set is keyed by the API. They come from the same module in the same release, so this is a deploy constraint: ship the container image and the API from one engine build. Triggering it needs an audit in flight across that deploy AND a prior new-engine publish for the same site; the damage is one early resolve that the next audit re-creates. A mechanism to detect the producer's normalisation would need the run's whole ingested URL set, which the page-at-a-time cursor exists to avoid materialising.[P2] Acceptance criterion 2 after publish sampling. Real and pre-existing, filed as squirrelscan/repo#2067 rather than fixed here. A page crawled clean whose every check was clipped from the docs(guides): drop the stale hosted MCP tool count #1167 sample is evidenced by nothing in the payload, so it is not counted as audited.
resolutionSignal.crawledUrlsholds the unsampled list but is deliberately kept out ofcrawledUrls— unioning it drops those pages fromcarriedPageUrlsand loses their synthetic pass from the denominator, moving the score. Fixing it properly needs a coverage page set that does not double as the scoring set, andknownPages/site_pageshave to move with it. Commented at the coverage return.Codex also noted the fold comparator ignored provenance, making equivalent groups' order input-dependent; the sort now tie-breaks on the full group key.
https://claude.ai/code/session_0174D96WamG9ZhJxRudpeniA