Skip to content

Renderer test helpers: a fresh stage page in WebKit every 8 frames (#151) - #160

Merged
agorischek merged 3 commits into
mainfrom
fix/webkit-graph-hang-151
Nov 21, 2026
Merged

agorischek merged 3 commits into
mainfrom
fix/webkit-graph-hang-151

Conversation

@agorischek

@agorischek agorischek commented Nov 21, 2026 •

Copy link
Copy Markdown
Collaborator

What changed

Fixes #151. This is not a layout or routing loop: WebKit runs out of memory.

WebKit keeps every iframe a page has removed, with its document and script heap, until the page itself navigates. Each stage load that doesn't reuse its frame starts a new one. A spec that loads scenario after scenario in one page (diff.spec.ts:36, the arrowheads loop) therefore grows the WebProcess by about 5–20 MB per load. In WebKit that process also runs the sandboxed renderer frames. It grows until it thrashes in garbage collection or the system kills it. The result is a stage that reports ready, then a page whose event loop never runs again, then "Target page… closed".

openStage and checkScenario (in @githubnext/projections-renderer-testing) now count the frames a page attaches since its main frame last navigated. In WebKit they reload the stage page once that count reaches 8 (framesPerStagePage), which releases those frames. Chromium frees removed frames itself, so it's unchanged. checkScenario runs its whole suite inside the page, out of reach of that reload: one suite for graph/npm-express-5 attached 44 frames and grew the WebProcess by about 1.5 GB. So in WebKit it now runs the checks three at a time (each attaches 2–5 frames) and reloads before every batch that follows any frame. Init scripts survive the reload; in-page state from before the reload does not, and the README now says so.

How I found it (Linux, Playwright WebKit):

  • I looped all 28 graph scenarios × light/dark in one page with 2 workers. Both workers stalled in round 2. dmesg showed the OOM killer killing WPEWebProcess at 2.9 GB. On the stall, the surviving WebProcess main thread sat idle in poll() at 0% CPU, so no JS or layout loop was spinning.
  • Graph layout and routing loops (kit/src/layout/**, routing/*, fit and zoom) are all bounded. I found no pathological input.
  • WebProcess RSS grows linearly with loads for every renderer: database +15 MB/load, code-statistics +9, graph +18. It stays flat with reuse: true (same frame).
  • Raw iframe churn on the stage page, with no init and no renderer code running, isolates the cause. A renderer document parsed but never executed still grows RSS by 2.7 MB per frame. A 2 MB script-free text document grows it by 5 MB per frame. A tiny document barely grows it. Forcing GC pressure doesn't reclaim the memory; reloading the page does (577 → 482 MB).
  • In Chromium, a heap snapshot after 16 loads holds only the live documents.

Evidence

  • WebKit release-workflow × 40 loads in one page: before, about 20 MB/load, linear (956 MB at load 24). After, it plateaus around 670–800 MB.

  • The 28-scenario graph loop, 2 workers × 4 rounds (448 loads), WebKit, CI=1: before, both workers stalled or were OOM-killed in round 2. After, it passes in 8 min.

  • browser/diff.spec.ts + browser/arrowheads.spec.ts, --project=webkit-desktop, CI=1: 25 passed (and again after rebasing on Renderer test helpers: bound each stage request, and say what the stage last showed #153).

  • browser/checks.spec.ts, WebKit, CI=1: 26 passed. Memory after each check suite no longer accumulates (1085 → 993 → 954 MB across three scenarios).

  • Unit test (test/helpers.test.mjs): the frame count resets only on a main-frame navigation; WebKit at the limit gets a fresh page; Chromium never does.

  • npm run tools -- check --fast and check --affected pass.

  • Documentation that this change affects is updated, and generated reference
    pages are regenerated (npm run docs:generate).

  • Fixes include a regression test.

  • No credentials, private source or machine-specific paths are included.

)

WebKit keeps every iframe a page has removed, with its document and script
heap, until the page itself navigates. Each stage load that doesn't reuse its
frame starts a new one, so a spec that loads scenario after scenario in one
page (diff mode over every graph scenario, the arrowheads loop) grows the
web process, which also runs the sandboxed renderer frames, by 5-20 MB per
load until it thrashes collecting garbage or the system kills it: a stage
that reports ready, then a page whose event loop never runs again, then
"Target page... closed".

openStage and checkScenario now count the frames a page attaches since its
main frame navigated, and in WebKit reload the stage page once that reaches
8, which releases them.

Fixes #151

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The refresh budget is checked only before the entire check suite, allowing a single suite to exceed eight frames and leave long WebKit runs exposed to retained-frame memory growth.

1 open issue
What changed in this PR

Addresses the WebKit memory growth investigated in #151 by refreshing renderer stage pages after repeated frame creation, complementing #153’s request timeout diagnostics.

Changes:

  • Track frame attachments and reload WebKit stage pages when the eight-frame budget is reached between helper calls.
  • Add regression coverage for frame counting, navigation resets, and Chromium behavior.
  • Document reload-related state loss and clarify the timeout comment.
File Description
packages/​renderers/​testing/​test/​helpers.test.mjs Tests frame counting, reset behavior, and engine-specific refresh decisions.
packages/​renderers/​testing/​README.md Documents WebKit reloads and loss of in-page state.
packages/​renderers/​testing/​playwright/​index.ts Applies the refresh check during stage-page preparation.
packages/​renderers/​testing/​playwright/​frames.ts Adds per-page frame tracking and the WebKit refresh threshold.
packages/​renderers/​testing/​playwright/​bounded.ts Updates a comment to explain memory-related page hangs.

Review effort: Balanced

agorischek and others added 2 commits November 21, 2026 22:04
…age page

checkScenario ran the whole check suite in one request, starting its frames
inside the page where stagePage can't start it over: one suite for a large
graph (npm-express-5) attached 44 frames and grew WebKit's web process by
about 1.5 GB. In WebKit it now runs the checks three at a time (two to five
frames each), reloading the stage page before each batch that follows any
frame.

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
@agorischek
agorischek merged commit 0d572ec into main Nov 21, 2026
48 checks passed
@agorischek
agorischek deleted the fix/webkit-graph-hang-151 branch November 21, 2026 23:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

WebKit: the stage page stops responding after a large graph scenario loads (renderer harness)

2 participants