Repository navigation
fix(audit-engine): stop the container's cloud-prefetch payloads holding their pages - #255
Merged
Merged
Conversation
added 2 commits
September 8, 2026 05:42
…ng their pages #253 buildCloudPagePayloads keeps a 6 KB text excerpt per page, plus a title, a description and up to twenty headings. Every one is a slice of that page's html, and in JSC a retained slice pins the buffer it was cut from, so the payload list held the whole crawl as UTF-16 for the length of the prefetch. That is the page-count-scaled term the streamed pre-rules walk exists to remove: the walk drops each batch as soon as the collectors have absorbed it, and nothing else is keeping those pages alive. truncateUtf8Bytes is not a detach. It returns text.slice(0, maxBytes) unchanged whenever the slice already fits the byte budget, which is every all-ASCII page, so the excerpt came back still attached. Pinned as its own test so the next reader does not mistake it for one. Measured with the #250 retention harness on per-page-distinct 4 MB pages, 24 pages, `external` with a retain-nothing control subtracted: attached +186 MB detached +3 MB The blocklist urls and selectors and the gaps seeds get the same treatment. Those three are capped (1,500 / 500 / 50) so their worst case was bounded by the cap rather than by page count, but a capped list of 1,500 attached urls still pins up to 1,500 pages. Payloads are unchanged: same fields, same values, same order, asserted directly and covered by the CLI-vs-container prefetch parity test. The CLI's twin of this code was fixed in #252; this is the container side, which runs on every hosted audit. Signed-off-by: Nik Cubrilovic <[email protected]>
…occurrence #253 Review follow-up on the commit above. Three cheap wins, no behaviour change: - The blocklist url and selector sets cap UNIQUE values, but the clone was being paid per occurrence. A site that links the same forty hosts and reuses the same layout classes on every page has orders of magnitude more occurrences than uniques, so the set is now tested before the copy is made. The resulting set is identical either way — a duplicate never grew it. - The container's `cleanSeed` assembles its result character by character and returns `parts.join("")`, a fresh string that references no page, so detaching a seed there was pure cost. Dropped, with a note saying why the CLI's twin still needs one: it builds the same value with split/replace/trim, whose results CAN be slices. A real difference between the two files rather than a missed case. - The CLI's twin gets the same dedupe-before-clone, so the two stay in lockstep where they should be. 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.
Closes #253. The container-side twin of the retention fixed on the CLI side in #252.
What was wrong
buildCloudPagePayloadskeeps a 6 KB text excerpt per page, plus a title, a description and up to twenty headings. Every one of those is a slice of that page's HTML, and in JSC a retained slice pins the buffer it was cut from. So the payload list held the whole crawl as UTF-16 for the length of the prefetch.That is exactly the page-count-scaled term the streamed pre-rules walk exists to remove. The walk drops each batch as soon as the collectors have absorbed it, so nothing else is keeping those pages alive, and the payloads were quietly holding all of them.
truncateUtf8Bytesis not a detach, which is the part that makes this easy to miss. It returnstext.slice(0, maxBytes)unchanged whenever the slice already fits the byte budget, and for an all-ASCII page it always does. Only an overflowing multi-byte slice takes theTextEncoderround trip that would have detached it. There is now a test saying so, so the next reader does not take it for a detach.It shows only in
process.memoryUsage().external. Not inheapUsed, where it is a rounding error, and not in RSS, where the allocator absorbs it.The measurement
Using the retention harness from #250, on per-page-distinct 4 MB pages,
externalwith a retain-nothing control subtracted:About 7.8 MB held per page before, 0.13 MB after. The harness fails loudly rather than passing when the attached arm does not clear the control by its margin, so a run that did not reproduce the retention cannot report success.
Also detached
The blocklist URLs and selectors and the gaps seeds. Those three are capped at 1,500, 500 and 50, so their worst case was bounded by the cap rather than by page count. A capped list of 1,500 attached URLs still pins up to 1,500 pages, though, so they get the same treatment.
Not detached:
renderedPageUrls, whose entries arepage.urlread from a storage row rather than sliced out of HTML, and the Stage-0 metadata payloads, which are built from a bounded sample the collector is already retaining whole.Parity
This is a memory property, not a payload change. Same fields, same values, same order, asserted directly and covered by the existing CLI-versus-container prefetch parity test. The streaming pre-rules golden and the canonical-versus-streaming golden are green.
Review follow-up
A codex pass returned no correctness defects and three efficiency notes, all taken in the second commit:
cleanSeedassembles its result character by character and returnsparts.join(""), a fresh string referencing no page, so detaching a seed there was pure cost. Dropped. The CLI's twin still needs one, because it builds the same value with split/replace/trim whose results can be slices. That is a real difference between the two files, not a missed case, and it is commented as such.packages/audit-engine.