Repository navigation
perf(publish): bound the resolution signal and pageStatuses to a 192 KiB budget (repo#2658) - #641
Conversation
20f5bfe to
1a482a3
Compare
…KiB budget (repo#2658) Signed-off-by: Nik Cubrilovic <[email protected]>
…the whole body (repo#2658) [skip ci] Signed-off-by: Nik Cubrilovic <[email protected]>
a29e2eb to
3186bac
Compare
…e statuses, needs pages; failing sets in URL order (repo#2658) Signed-off-by: Nik Cubrilovic <[email protected]>
3186bac to
8b39fd6
Compare
|
Review of #641 (compact resolution signal, fixed byte budget). I read the full diff but did not run the tests. CI was still pending when I looked.
I found no security issues beyond the billing-claim point above. The docs addition is clear. |
…re-parse shape check (repo#2658) Signed-off-by: Nik Cubrilovic <[email protected]>
|
Review of #641. I read the CLI publish changes, the merge-core and merge-promise changes, the publish-cap changes and the tests. I did not read the new
|
…re it is parsed (repo#2658) Signed-off-by: Nik Cubrilovic <[email protected]>
|
Reviewed the decoder (
Positives:
No high or critical issues found. |
Signed-off-by: Nik Cubrilovic <[email protected]>
|
Review of #641 (compact resolution signal and the 192 KiB budget). I read the CLI changes, the new The design is sound. The decoder is carefully bounded: the inflate has an output cap, there is a shape pre-scan before Findings:
I have no critical or high findings. The medium |
Summary
Part of squirrelscan/repo#2658 (epic repo#2655). The resolution signal (crawled URLs plus failing-page hashes per check) and
pageStatuseswere the only publish fields that grew with pages after per-class capping: about 0.3 KB a page, over 1 MiB from about 2,800 pages. This puts both in a fixed 192 KiB budget. It also wires that budget into #640's capper, so the whole capped body fits 1 MiB whatever the crawl size.Compact signal (
resolutionSignalCompact, types in core-contractsresolution.ts): base64 of raw-deflated JSON. Crawled URLs sorted, failing / not-evaluated / removed sets as gap-coded indexes into them. It hashes exact URLs, so the crawled set has no 32-bit collision risk.Decoder (
decodeResolutionSignal,@squirrelscan/rules/resolution-decode, the API's side) turns it back into the legacyResolutionSignalthe merge reads. It refusesdatapast 192 KiB. It inflates withnode:zlibinflateRawSync(..., { maxOutputLength: 4 MiB }), under Workersnodejs_compat. BeforeJSON.parseit counts containers, nesting and separators outside strings, against what a valid payload can hold. Then it validates every field.Builder (
buildPublishResolution, rulesresolution.ts): fitspageStatuses(clipped to 32 KiB, 404/410 first) plus the signal intoRESOLUTION_PUBLISH_LIMITS.maxBytes, keys included.REPORT_CAPS.signalMaxBytes/pageStatusesMaxBytesnow alias it, so there is one number. Over budget it either drops the costliest keys (listed intruncated) or clips the crawled list (crawledComplete: false,crawledCount,removedCount), whichever keeps more page × key decisions. Failing sets are in URL order, so clipping does not depend on check order.Capper (audit-engine
publish-cap.ts):buildPublishResolutionwith rules, check names and pages in sorted order;buildPageStatusesandcanonicalSignalare gone;resolutionSignal/resolutionSignalCompacton the input is stripped, never published;maxBytes;PublishedReportTooLargeError(part: "body");pagespublishes no signal;removedPageUrls.The "needs repo#2658" caveats and the
TODO(repo#2658, repo#2657)gate are gone. The CLIslimForPublishTODO now says the capper's preconditions have landed.Merge (audit-engine
merge-core.ts,merge-promise.ts):pageStatusesclipped them.notCrawledThisRuncredits no carried page, andnotEvaluatedThisRunkeeps carries on unlisted pages.CLI
slimForPublishsends the compact shape. The legacybuildResolutionSignalstays as the reference.Docs:
reports.mdx"Size cap on large sites" covers the budget, what degrades, and where full detail lives (squirrel report --format json|llm).TODO(repo#2669)Sentry hook points, as comments only: the oversize error, hard-capdetailstamps, and the signal's over-budget path.Pairs with a private PR, after this merges:
resolutionSignalCompact, decodes it before the merge, deletes it before storage, keeps accepting the legacy shape, and clamps claimed counts to the plan page limit;buildPublishResolution;Deploy order: API first, then the CLI release. Until then, an old API strips the unknown field and merges without a signal (pre-#1185 behaviour).
Measurements
Signal plus
pageStatuses, real-shape fixture (anonymized 50-page surface report, 257 page check classes) extended to N pages. "slug" and "entropy" swap in realistic or random URLs of the fixture's 63-byte mean length.On the real fixture's per-page rows at 50 to 10,000 pages, the decoded compact signal equals the legacy signal as sets,
truncatedincluded. The 12 and 27 keys truncated at 5,000 and 10,000 pages come from the existingRESOLUTION_SIGNAL_LIMITScount caps. Build time: 50 to 150 ms at 2,800 pages, 2.4 s for the over-budget search at 10,000 slug pages on a quiet box.Decoder memory under workerd (the API runtime)
Bun tests cannot show this: Bun inflates a
DecompressionStreamlazily, workerd does not. Measured on local workerd 1.20261006.1 at the API'scompatibility_date(2024-12-30), withwrangler dev --localand RSS of that workerd process:DecompressionStream+ read cap){},x 1.3M under an unknown keyThe API schema also caps
dataat 192 KiB, so the 1.36 MB body never reaches the decoder in production.Known residuals (only when the byte budget clips the crawled list)
checkTallies, which no producer sends until the capper is wired (repo#2667). Off a clipped list a carried finding can duplicate a tally entry. A warning gains half credit that way, so a rule at pass ratio r gains about k(0.5 - r)/(N + k). In the opposite direction, crediting no carried page with synthetic passes deflates the score. The fix is to ship hashes of every crawled page (a few bytes each), filed as a sub-issue of repo#2655 that gates repo#2667.Verification
tsgo --noEmitin core-contracts, rules, audit-engine, apps/cli: clean.bun test(explicit files, sequential), all pass:resolution-compact,resolution,fold(112);publish-cap,capped-rescore,compact-resolution-merge,site-pages-contract-coverage,cloud-merge,item-locator-resolve,scan-truncated-carry,sampled-audited-pages,carried-provenance-merge,rate-limited-coverage,complete-store-parity,bounded-carried-merge,merge-session-pages,fingerprint-parity,merge-scoring(289);mixed-provenance-capped-2657,rule-catalog-2656(10);publish-size-bound,publish-slim,publish-degrade(19).New tests:
publish-cap.test.ts: the worst case asserts the whole body<= PUBLISHED_REPORT_MAX_BYTES - envelopeBytes; the 10,000-page light shape too; transport is the compact signal; no raw or input signal rides along; the transport share scales with a smaller ceiling; a report without pages publishes no signal; a page listed twice keeps its removal whatever the row order.capped-rescore.test.ts: off a clipped list, no carried page is credited with passes the tallies hold; a carry on a page the payload names stays scored. The capped score is never above the uncapped one in either.compact-resolution-merge.test.ts: billing floor and clamp, plus the carry-safety cases.Each guard was mutation-checked: reverting it fails its test.
oxfmt --check/oxlinton touched apps/cli files: clean.[email protected] check --strictin docs: passed.Codex review: earlier rounds on the signal and merge, plus two on the capper wiring. Every finding is fixed except the residuals above.
Acceptance criteria (repo#2658):
truncatedand never resolved: tests.squirrelscan agent skill: no change needed. The skill reads local
--format llmoutput, not the publish body.Checklist
Signed-off-byline (git commit -s).