Repository navigation
fix(audit-engine): item findings carry their own message, not the page's count - #228
Merged
Merged
Conversation
4 tasks done
nc9
force-pushed
the
fix/1881-item-level-message
branch
from
September 7, 2026 08:28
df0b1ef to
4d1b6aa
Compare
3 of 4 tasks
nc9
force-pushed
the
fix/1881-item-level-message
branch
3 times, most recently
from
September 7, 2026 09:29
e74bd65 to
7f17008
Compare
…e's count
`findingFingerprint` hashes [status, message, value, expected] and is
deliberately URL-free so `finding_defs` (site_key, fingerprint) can hold one
row per distinct defect. `flattenChecks` defeated that: it copied the parent
check's PAGE-LEVEL message/value/expected onto every item row, and a page-scope
check's message is a count of that page's items. One Shopify CDN script missing
SRI on 401 pages stored 25 messages ("26 cross-origin resources without
Subresource Integrity" on one page, "24 ..." on another) and 25 fingerprints
for one defect.
The damage ran both ways. On the measured site, item rows hold 4,036 distinct
(rule, check, locator) defects but only 561 distinct fingerprints, because the
hash keyed on the page's count rather than on the defect - so one dictionary row
stood in for many unrelated locators.
An item row's message is now the page-invariant part of its check's message
plus the item id:
cross-origin resources without Subresource Integrity: https://cdn.../globo.js
`pageInvariantCheckText` drops a leading count and replaces any remaining digit
run with N, matching what the report's own grouping already shows for a merged
group. The id gets first claim on the store's message clamp, so a long URL is
never truncated away by a long prefix. `value`/`expected` were page-level
aggregates too and are dropped from the row. `item.label` deliberately does NOT
feed the message: several rules stamp per-page numbers into it
(content/keyword-stuffing emits `"everyday" (2.3%)`), which would re-create the
same split.
Nothing downstream changes text or score. The parent check's page-level trio is
stashed in the item payload as m/v/e, and both readers that rebuild a
CheckResult from storage - `carriedFindingToCheck` and `reconstructRuleChecks` -
restore it verbatim, so the replayed union check still groups as one. `m` is the
sole restore marker: a pre-#1881 row has none and falls back to its own columns,
a whole-check row never writes one, and an empty-id item is caught even though
it lands in a locator-"" group. The marker is scanned across the whole group,
because the stash is budgeted per item.
That budget only ever removes the STASH, never `items`/`details`/`pages`: the
chunk ingest drops an over-cap payload whole and `details.additional` feeds the
scorer's density penalty, so letting the stash tip a near-cap payload over the
line would inflate the health score (#1179 class). It does not trim detail to
fit either, because this same payload feeds the CLI's local SQLite store, which
has no cap - shrinking for transport belongs at the transport boundary. An
over-cap payload is therefore byte-identical to what it was pre-#1881.
Whole-check findings (locator "") are untouched.
Measured across the whole production corpus, 296 sites and 545,822 item rows:
distinct (site, rule, check, locator, status) is 91,944 and adding the new
message takes it to 91,966, so the text costs 22 tuples, 0.024%. All 22 are
named in public #231 (two rules alternating singular/plural, one interpolating
a product name). On the measured site, item-row inflation over the locator key
falls from 59.9% to 0.8% and whole-check rows are unchanged at 519.
No compare_audits churn, contrary to the issue's prediction: `flattenReport`
fingerprints the R2 report payload's checks, never the stored column, and report
checks are unchanged because carried checks restore the page-level message.
`computeMerge` matches priors by (url, rule, check, locator), not by
fingerprint, so first-seen dates are preserved. `finding_defs` grows from ~23k
to ~102k rows, which is the dictionary becoming correct rather than bloat, and
superseded rows are removed by the existing `sweepOrphanFindingDefs` cron.
Blocks #1880.
Signed-off-by: Nik Cubrilovic <[email protected]>
nc9
force-pushed
the
fix/1881-item-level-message
branch
from
September 7, 2026 09:30
7f17008 to
eb21d97
Compare
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.
The defect
findingFingerprinthashes[status, message, value, expected]and is deliberately URL-free, sofinding_defs(site_key,fingerprint) can hold one row per distinct defect.flattenChecksdefeated that: it copied the parent check's page-level message/value/expected onto every item row, and a page-scope check's message is a count of that page's items.One Shopify CDN script missing SRI on all 401 pages of a real audit stored 25 different messages, "26 cross-origin resources without Subresource Integrity" on one page and "24 ..." on another, and therefore 25 fingerprints for one defect.
The damage ran in both directions, which the issue did not anticipate. On the measured site, item rows carry 4,036 distinct
(rule, check, locator)defects but only 561 distinct fingerprints, because the hash keyed on the page's item count rather than on the defect. Onefinding_defsrow was standing in for many unrelated locators. So the dictionary was not merely bloated, it was wrong.The fix
An item row's message is now the page-invariant part of its check's message, plus the item id:
pageInvariantCheckTextdrops a leading count and replaces any remaining digit run withN. That placeholder is not invented here: the report's own grouping already renders exactly that for a merged group whose members differ only in digits (packages/report/src/grouping.ts), so the two surfaces read alike.valueandexpectedwere page-level aggregates for the same reason and are dropped from item rows.item.labeldeliberately does not feed the message. Several rules stamp per-page numbers into the label,content/keyword-stuffingemits"everyday" (2.3%), so a label-bearing message re-creates the same split. The label is not lost; it rides in the payload'sitems[0], which every reader that rebuilds aCheckResultreplays.Nothing downstream changes text or score. The parent check's page-level trio is stashed in the item payload as
m/v/e, and both readers that rebuild aCheckResultfrom storage restore it verbatim:carriedFindingToCheck(scoring.ts), so a replayed carried check renders the page-level message. Report grouping keys on the message, so reading the item's own text there would split one carried aggregate into one group per item.reconstructRuleChecks(reconstruct.ts), so the complete-store round-trip stays lossless.mis the sole restore marker. A pre-#1881 row has none and falls back to its own columns; a whole-check row never writes one, so payload presence alone cannot misfire; an empty-id item is caught even though it lands in a locator-""group. The marker is scanned across the whole group, not justgroup[0], because the stash is budgeted per item.Payload budget. The stash is added only when the serialized payload still fits
maxFindingPayload. The chunk ingest drops an over-cap payload whole anddetails.additionalfeeds the scorer's density penalty, so letting the stash tip a near-cap payload over the line would move the health score, the #1179 class. The stash is display detail, so it is the part that yields.The budget never trims
items/details/pagesto make room. This same payload feeds the CLI's local SQLite store, which persists it with no cap at all, so dropping detail here to work around a transport limit would destroy data the local path would have kept. Shrinking an already-over-cap payload for transport belongs at the transport boundary, and the paired private PR adds exactly that retry there. An over-cap payload is therefore byte-identical to what it was before this change.Whole-check findings (locator
"") are untouched.Which surfaces show this message to a person
Traced every reader of
page_findings.message/finding_defs.messagethat does not first pass throughcarriedFindingToCheckorreconstructRuleChecks.report-detail.tsx)topIssuesis built server-side from the R2 report payload (routes/v1/websites.ts), then@squirrelscan/reportgroupingissue-sync.tswrites title/description/recommendation from rule metadata, never from a finding messageget_issueextractRuleOccurrencesover the report payload (run-report.ts)list_issuespackages/issues/src/prompts.ts)messageread; its input schema has no message fieldaudit-digest.tstakes its title fromflattenReport, which reads the report payloadcompare_auditsaudit-diff/resolve.tsselects onlynormalizedUrl, ruleId, checkName, locator, statefrompage_findings, no messagepackages/report)CheckResultsGET /v1/{reports,websites}/…/findings(findings-read.ts)The one raw reader is
serveFindings, and it is dark:REPORTS_FINDINGS_API_ENABLEDis"false"inwrangler.tomlandwrangler.dg.toml,requireFindingsApi404s, and nothing in the monorepo calls it, not the dashboard, the API client, the cloud client or the CLI. It returns JSON, never a rendered string. So no human or agent sees this column today, and when that flag is flipped it will read as a sentence rather than a bare URL, which is why the message is not just the id.Measurements
Page-invariance, whole production corpus: 296 sites, 545,822 item rows.
All 22 are named and filed as #231:
security/sriandcontent/meta-in-bodyalternate singular and plural wording, andschema/rating-scopeinterpolates the product name into its message. That is empirical rather than a proof, and #229 is the gate that would catch a future rule reintroducing it.Collapse on the measured site (drscholls, 52,526 rows):
Item-row inflation over the locator key falls from 59.9% to 0.8%. Whole-check rows are unchanged, as the third acceptance criterion requires. Site-wide the tuple lands 12.5% above the locator floor; the entire residual is the 43 whole-check groups this PR must leave alone, so that is the floor for #1881 and #1882/#1885 own the rest.
The fingerprint count for item rows rises from 561 to 4,069. That is the correct direction: 4,036 distinct defects previously shared 561 hashes.
Canonical 500-page golden fixture: item-row inflation is 0.0% before and after. The fixture's item locators are page-unique, so it never exhibited the count split and cannot demonstrate the fix, which is why the numbers above come from production.
Gates
No golden files exist to regenerate; every "golden" in
packages/audit-engine/testsis a self-referential parity gate over an in-process synthetic fixture. All 18 files matched bytest:goldenpass, as docomplete-store-parity,merge-scoring,fingerprint-parityand the two CLI suites that exerciseflattenChecks. Health score is unchanged at 49 on the canonical fixture.Worth naming for a future issue, filed as #229: the engine golden snapshot compares only
(ruleId, checkName, status, pageUrl), so a change to a finding's message text passes every golden gate while re-fingerprinting every stored finding. That is why the numbers above come from measurement rather than from the gates.One-time effect: smaller than the issue assumed
The issue predicted that every item-row fingerprint changing would surface those findings as new or worsened in
compare_audits. Traced, that does not happen, and no mitigation is needed.compare_auditsnever reads a stored fingerprint.flattenReport(audit-diff/identity.ts) computes its own fingerprints from the R2 report payload'sruleResults[].checks[].message, andaudit-diff/resolve.tsselects onlynormalizedUrl, ruleId, checkName, locator, statefrompage_findings. Report checks are unchanged by this PR: fresh checks come from rule execution, and carried checks come fromcarriedFindingToCheck, which restores the page-level message from the stash. So both sides of a diff read exactly what they read before.computeMergematches a prior finding byfindingKey= (url, rule, check, locator) and simply stores the new fingerprint, preservingfirstSeenAt. Nothing is re-created, so no finding reads as newly discovered and no first-seen date resets.issue-sync.tswrites title, description and recommendation from rule metadata, never from a finding message or fingerprint.What does change is
finding_defs, and in the intended direction. Projected over the current corpus it goes from 22,981 rows to about 102,499. That is not bloat: on the measured site, 4,036 distinct defects were sharing 561 fingerprints, so the dictionary was under-counting defects by 7x. Superseded rows become orphans as each site is re-audited and are removed by the existingsweepOrphanFindingDefscron, which anti-joinsfinding_defsagainstpage_findingson (site_key, fingerprint). Self-healing, no backfill and no migration.Follow-up in the private repo
clampFindingPayloadin the API's chunk ingest rebuilds the payload from a key allowlist (items,pages,details,i) and would silently dropm/v/eon the chunked-publish path. squirrelscan/repo#1890 adds the clamped pass-throughs and lands before the gitlink bump.Blocks squirrelscan/repo#1880.