Repository navigation
feat(audit-engine): grouped stream producer, one line per distinct finding (repo#1883) - #1912
Merged
Merged
Conversation
nc9
force-pushed
the
boat/grouped-stream-findings-1883
branch
from
November 16, 2026 04:50
0e99c06 to
60e6a4c
Compare
nc9
marked this pull request as ready for review
November 16, 2026 06:02
…nding with its complete page list (repo#1883) Signed-off-by: Nik Cubrilovic <[email protected]>
…tream MemStore repo#1883 Signed-off-by: Nik Cubrilovic <[email protected]>
nc9
force-pushed
the
boat/grouped-stream-findings-1883
branch
from
November 16, 2026 06:12
60e6a4c to
ecf1b59
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.
Part of squirrelscan/repo#1883 (epic squirrelscan/repo#1880). This PR does not close it: the API side is a private follow-up (see below).
Summary
Adds a grouped chunked-publish producer next to
buildStreamFindings, inpackages/audit-engine/src/stream-findings.ts. It is exported from both.and./smart-audits.buildStreamFindingsandbuildSkippedPassCountsare unchanged, so the current wire contract and its private consumers keep working until the private switch-over.buildGroupedStreamFindings(ruleResults, now, { maxLineChars? })emits one line per distinct(ruleId, checkName, locator, fingerprint). Each line carries the complete affected-page list aspages: [normalizedUrl, payloadIndex][](sorted), plus a dedupedpayloadstable, because payloads differ per page (emission index, page-level aggregate, evidence). It filters exactly asbuildStreamFindingsdoes: unfold, skip site-scope and carried/unrendered checks, flatten per (rule, url), last write wins per primary key. The group key uses the literal status/message/value/expected, so a fingerprint collision cannot merge rows. Groups are built incrementally, so the per-page row array is never built.GROUPED_STREAM_MAX_LINE_CHARS(128 KiB, half the API's 256 KiB per-line ceiling) is split intopart/partslines. Each part carries only the payloads it references. No page is dropped, and a single oversized page gets its own part.expandGroupedStreamFinding(line)is the inverse. It returns the exact per-page rowsbuildStreamFindingswould have produced, so the API can rebuild thepage_findingsrows server-side with one shared function.summarizeGroupedStream(lines)returns{ lines, rows }.rowsis thepage_findingsrow count to expect. The finalize gate should comparecount(*)againstrows, notlines, so a dropped line or part fails closed.Acceptance criteria (squirrelscan/repo#1883)
One line per distinct
(ruleId, checkName, locator, fingerprint)with a complete page list: testsone line per distinct (rule, check, locator, fingerprint) when nothing splitsandexpand(grouped) equals buildStreamFindings on a mixed fixture.[~] Under 3,000 lines for drscholls. Shown only on a synthetic fixture sized to the prod measurement (401 pages, 28,733 rows), which gives 2,479 lines (test
drscholls-shaped: 401 pages, 28,733 rows collapse to 2,479 lines). A real drscholls run needs the private switch-over.[~] The API builds the same
page_findingsrows:expandGroupedStreamFindinground-trips to exactly thebuildStreamFindingsrows. It is tested on a mixed fixture, on the drscholls-shaped fixture, and with every group forced to split. The API ingest that calls it is private.[~] Finalize gate coherent and fails closed. Test
rows equals distinct PKs, and dropping any line leaves rows short. The API gate change itself is private.A group that goes over budget is split across lines with no page dropped: tests
a wide group splits into parts within budget, losing no page,each part carries only the payloads it references, re-indexed, anda single page over budget still gets its own part.[~] Peak RSS is lower on the container side. Run
bun scripts/bench-grouped-stream.ts --mode per-page|groupedin packages/audit-engine; each mode runs in its own process, and the figures are the second of two runs:Finalize RSS is on the private API and is not measured here.
Health score delta 0: test
grouped-materialized rows score identically to per-page rows, which runsrunCloudSmartAuditscomplete-store reconstruct andcalculateHealthScoreFromTallies.buildSkippedPassCountsis unchanged (testbuildSkippedPassCounts is unchanged by the new producer).Gates
bun test tests/grouped-stream-findings-1883.test.ts: 13 pass, 0 fail.bun test tests/complete-store-parity.test.ts tests/item-finding-identity.test.ts tests/fingerprint-parity-golden.test.ts: 59 pass, 0 fail.bun run typecheck(packages/audit-engine): clean.oxlinton the changed files: clean. Packages have no format script, so oxfmt was not run.Private follow-up
The worker-agent needs to stream
buildGroupedStreamFindings. The API chunk ingest needs to accept grouped lines and build them back withexpandGroupedStreamFinding. The finalize gate needs to compare againstrows. Then the gitlink gets bumped. That is tracked as a private follow-up.Agent skill
No change needed: this is internal publish plumbing, with no CLI or user-facing output change. No docs change either, for the same reason.