Repository navigation
test(audit-engine): give the detach memory tests a control they can survive CI with - #250
Merged
Merged
Conversation
…urvive CI with Tests only. `absorbing from a page-sized document does not retain the document` went red on a shared runner at 541,604 bytes against an expected 531,770 — the attached and detached arms landing on top of each other, which is runner noise rather than the fix regressing. The measurement had no control. It compared the two real arms directly, so the parse, the transient DOMs and the arena's growth were inside both numbers and the difference it asserted on was a few percent of each. Its sibling in detach-from-page.test.ts had the same shape, and when the arms collapsed it printed INCONCLUSIVE and PASSED — on every run since it was written. helpers/retention.ts now measures both, and four things changed: - `external`, not heapUsed. A string's characters live off the JS heap and a slice pins the BUFFER. On a 150-page fixture the attached arm's external was 287 MB against a control's 100 while the two heaps were 143 and 131, so heapUsed makes the signal a rounding error on the noise. - A retain-nothing arm, subtracted. Every arm parses the same pages and runs the same extraction; only what it keeps differs. - Multi-megabyte sources, node-poor so the DOM stays cheap and the buffer stays large. 24 pages of 3.8 MB put the attached arm 82 MB clear; 48 of 6 MB put it at 234, against a 150 MB margin. - An unusable run FAILS and says which number was wrong, instead of returning early. A green run that asserted nothing is worse than a red one. Measured over three consecutive local runs, both tests: control 0-1 MB, attached +234 and +275 MB, detached within 1 MB of zero. With the detach call site deleted the detached arm jumps to +243 MB and the assertion fails, so the test still catches what it was written for. Refs squirrelscan/repo#1860. Signed-off-by: Nik Cubrilovic <[email protected]>
nc9
force-pushed
the
fix/detach-memory-test-flake-1860
branch
from
September 7, 2026 19:17
8255ba2 to
fc2717d
Compare
nc9
added a commit
that referenced
this pull request
Sep 7, 2026
…ng their pages (#255) * fix(audit-engine): stop the container's cloud-prefetch payloads holding 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]> * perf(audit-engine): pay the payload detach per unique value, not per 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]> --------- Signed-off-by: Nik Cubrilovic <[email protected]> Co-authored-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.
Tests only. Fixes the flake that took #240 red on run 34139295533.
What failed and why
absorbing from a page-sized document does not retain the documentfailed with 541,604 bytes against an expected 531,770 — the attached and detached arms landing within 2% of each other on a shared runner. That is noise, not the fix regressing: it passed locally and on the pre-rebase run.The measurement had no control. It compared the two real arms directly, so the parse, the transient DOMs and the arena's growth were inside both numbers, and the difference it asserted on was a couple of percent of each. On a quiet machine that works; on a shared runner the two numbers touch.
Its sibling in
detach-from-page.test.tshad the same shape with a worse failure mode: when the arms collapsed it printed INCONCLUSIVE and passed. It had been doing that on every run since it was written, so the second memory gate in this area has been asserting nothing.The harness
tests/helpers/retention.ts, used by both:external, notheapUsed. A string's characters live in a backing store off the JS heap, and a slice pins the buffer rather than a heap object. Measured on a 150-page fixture, the attached arm'sexternalwas 287 MB against a control's 100 MB while the two heaps were 143 and 131. ReadingheapUsedmakes the signal a rounding error on the noise.Both fixtures build from per-source unique chunks. A corpus made with
.repeat()is nearly free to hold, because JSC ropes share backing storage, and the attached arm would look detached.Numbers
Three consecutive local runs, both tests, against a 150 MB margin and a 4x ratio:
The three numbers are printed on every run, pass or fail, so the next flake comes with its own diagnosis instead of leaving someone to re-derive it.
With the
detachFromPagecall site deleted, the detached arm jumps to +243 MB and the assertion fails, so the test still catches the thing it was written for.