Skip to content

fix(window): materialize lazy surfaces on retained detached globals - #1783

Open
ldm0 wants to merge 5 commits into
mainfrom
fix/detached-window-lazy-surfaces-20261021
Open

ldm0 wants to merge 5 commits into
mainfrom
fix/detached-window-lazy-surfaces-20261021

Conversation

@ldm0

@ldm0 ldm0 commented Oct 20, 2026 •

Copy link
Copy Markdown
Member

Retained detached iframe globals could return undefined on the first read of a lazy Window surface. Materialize those surfaces in the retained Realm, preserving SameObject identity and prototypes; keep captured fallbacks for non-lazy properties.

Bind child CustomElementRegistry state to the specific Document, so removing/reinserting an iframe or navigating it cannot make an old registry access the new Document's definitions. Preserve retained definitions and promises through V8 references without rooting retired Realms, and stop definitions when constructor getters retire their Realm.

Regression coverage includes all eight lazy surfaces, borrowed getters and navigation access checks, registry isolation, and Realm/native-host collection.

Rebased the complete five-commit implementation onto main 0197ba5e1b2fbb51373485c314124611ab2b3ee1, adapting the renamed PageScriptHost API. Range-diff confirms the first four patches are unchanged; the last only needs current API names and context.

Checks passed before the final mechanical rebase (base f645d859a36e5a4ab37c29e9083ffdf32039309b):

  • cargo fmt --all
  • cargo clippy --workspace --all-targets --all-features -- -D warnings
  • cargo nextest run --no-fail-fast: 23,403 passed, 20 skipped.

Head: 3c946d191ee0c9d60471e8506416b553cce019f8. The final rebase changed no retained patches (all range-diff entries match). Remote CI is triggered by this push.

@github-actions

github-actions Bot commented Oct 21, 2026 •

Copy link
Copy Markdown

CI Regression Report

Source CI run · source state at render: in_progress · artifacts: 6/6

Check Status Signal
Release regression ✅ HEAD/base failures 0/0; raw binary +0.002973%
Frontend differential ✅ 1,020/1,020 cases matched; 0 issues
Agent episodes ❌ 8/8 Moli episodes passed; 1 failures
Runtime/CDP contracts ✅ 26 contract cases; 0 failures
CDP smoke ❌ 118/122 groups passed; 2,028 scenarios
WebMainBench ✅ 545/545 completed; 0 unexpected failures
Release regression — ✅ HEAD/base failures 0/0; raw binary +0.002973%

Package and image size

Metric Base HEAD Delta Delta %
Raw binary 154.75 MiB 154.75 MiB +4.71 KiB +0.002973%
Stripped binary 107.12 MiB 107.12 MiB +4.00 KiB +0.003647%
gzip binary 53.51 MiB 53.51 MiB +984 B +0.001754%
Rootfs 161.65 MiB 161.66 MiB +10.00 KiB +0.006041%
gzip rootfs 62.62 MiB 62.62 MiB +2.83 KiB +0.004417%

Startup latency and PSS

Case Base p50 HEAD p50 Delta Base PSS HEAD PSS Delta
Serve ready 26.87 ms 28.07 ms +1.21 ms 5.37 MiB 6.47 MiB +1.10 MiB
CDP first page 49.58 ms 64.24 ms +14.66 ms 5.41 MiB 7.28 MiB +1.87 MiB
CDP warm page 11.26 ms 17.85 ms +6.58 ms 53.68 MiB 53.82 MiB +141.50 KiB
CLI about:blank 14.49 ms 20.18 ms +5.70 ms 3.27 MiB 5.63 MiB +2.36 MiB
CLI local JS 27.41 ms 26.11 ms −1.30 ms 4.55 MiB 4.14 MiB −414.50 KiB

Concurrency matrix

Concurrency Base p50 HEAD p50 Delta Base PSS HEAD PSS Delta HEAD failures Unstable B/H
1 24.88 ms 24.03 ms −0.85 ms 863.00 KiB 1.19 MiB +357.00 KiB 0 0/0
5 29.80 ms 28.56 ms −1.24 ms 12.03 MiB 12.13 MiB +107.00 KiB 0 0/0
10 28.74 ms 28.23 ms −0.50 ms 14.43 MiB 13.04 MiB −1.39 MiB 0 0/0
25 29.22 ms 27.29 ms −1.94 ms 29.60 MiB 16.86 MiB −12.73 MiB 0 0/0
100 28.95 ms 27.73 ms −1.21 ms 12.03 MiB 14.93 MiB +2.90 MiB 0 0/0
Frontend differential — ✅ 1,020/1,020 cases matched; 0 issues
Match DOM mismatch Diagnostic mismatch Moli error Reference error Infrastructure error Mismatched frames Duration
1,020 0 0 0 0 0 0 6m 44.29s
Agent episodes · Moli vs Chromium — ❌ 8/8 Moli episodes passed; 1 failures
Fast contract Episodes Passed Assertions Ready p50 Episode p50
Moli 8 8 47/47 28.46 ms 29.65 ms
Chromium 8 8 47/47 336.67 ms 83.25 ms
Operation p50 Chromium Moli Delta Delta %
navigate 44.11 ms 5.48 ms −38.63 ms −87.58%
observe 0.98 ms 0.91 ms −0.06 ms −6.62%
fill 3.57 ms 3.60 ms +0.03 ms +0.82%
click 5.41 ms 4.10 ms −1.30 ms −24.11%
Idle-resource episode Peak RSS Peak PSS Average CPU Peak CPU Peak processes Sampler
Moli 71.59 MiB 69.09 MiB 0.97% 14.13% 1 ✅
Chromium 1303.35 MiB 421.24 MiB 0.74% 29.92% 13 ⚠️ PSS partial

First failing episodes

  • click-same-document — resource / chrome-cdp
Runtime and CDP session contracts — ✅ 26 contract cases; 0 failures
Suite Cases Failures Median case p50 Median case p95 Median peak PSS p50
Synthetic fetch 13 0 30.82 ms 38.43 ms 881.00 KiB
Long-lived CDP session 13 0 18.88 ms 19.33 ms —
CDP smoke — ❌ 118/122 groups passed; 2,028 scenarios

Workers: 4 · cumulative group time: 617.51 s · failed groups: 4

Slowest group Scenarios Duration Status
dom-input 64 30.12 s ✅
dom-input 64 29.56 s ✅
scrollbar-visibility 22 27.58 s ✅
scrollbar-visibility 22 27.08 s ✅
fetch-resource-dispatch 72 26.73 s ✅

Failed groups

  • core — failed · Traceback (most recent call last): File "/__w/moli/moli/moli-cdp-smoke/moli_cdp_smoke/runner.py", line 824, in _run_worker await run_smoke(endpoint, fixtu
  • core — failed · Traceback (most recent call last): File "/__w/moli/moli/moli-cdp-smoke/moli_cdp_smoke/runner.py", line 824, in _run_worker await run_smoke(endpoint, fixtu
  • network — failed · Traceback (most recent call last): File "/__w/moli/moli/moli-cdp-smoke/moli_cdp_smoke/assertions.py", line 65, in wait_until await asyncio.sleep(interval_
  • network — failed · Traceback (most recent call last): File "/__w/moli/moli/moli-cdp-smoke/moli_cdp_smoke/assertions.py", line 65, in wait_until await asyncio.sleep(interval_
WebMainBench · 545 pages — ✅ 545/545 completed; 0 unexpected failures
Completed Successful Expected DNS failure Unexpected failures Panics Crashes Timeouts Empty output
545/545 544 1 0 0 0 0 0

Frozen HTML · Linux · --wait done · 45 seconds per page · no retries. Content quality is evaluated separately.

Diagnostics: webmainbench-results — every page's Markdown, stderr, and exit status. Source run and artifacts

All artifact fields are parsed by the trusted default-branch renderer; missing or invalid inputs remain visible as unavailable.

@github-actions

github-actions Bot commented Oct 21, 2026 •

Copy link
Copy Markdown

Spider Bench A/B

✅ All benchmark browser service runs completed; results are informational.

Public HEAD: 184 / 240 rows; 38 / 48 sites produced rows; 10 unexpected empty sites.

✅ Deterministic fixture contract is clean.

Common ancestor 0197ba5e1b2f → HEAD 3c946d191ee0; benchmark order: head-first; workflow: success.

Public 48-site run · informational

Metric Base HEAD Δ
Run status success success —
Extracted rows / contract 189 / 240 184 / 240 -5 (-2.65%)
Contract fill 78.75% 76.67% -2.08 pp (-2.64%)
Sites with rows 39 / 48 38 / 48 -1 (-2.56%)
Sites meeting row contract 37 / 48 36 / 48 -1 (-2.70%)
Unexpected empty sites 9 10 +1 (+11.11%)
Partial-row sites 2 2 0 (0.00%)
Site outcomes extracted: 38; HTTP error + rows: 1; empty: 7; HTTP error + empty: 1; snapshot error + empty: 1 extracted: 36; HTTP error + rows: 2; empty: 8; HTTP error + empty: 1; snapshot error + empty: 1 —
Observed duration 50.32 s 53.63 s +3.31 s (+6.57%)
Estimated CPU 42.42 s 41.53 s -0.89 s (-2.10%)
Peak PSS 265.20 MiB 244.81 MiB -20.39 MiB (-7.69%)
Peak RSS 268.65 MiB 247.99 MiB -20.66 MiB (-7.69%)
Peak threads 33 32 -1 (-3.03%)
Mismatched sites 0 0 0
Timeout with items 0 0 0
Category rows Base HEAD Δ
news 35 / 40 35 / 40 0
stocks 20 / 40 20 / 40 0
tech 35 / 40 35 / 40 0
sports 32 / 40 27 / 40 -5
games 32 / 40 32 / 40 0
life 35 / 40 35 / 40 0

Public-site content, timing, and memory are noisy. This single A/B run reports evidence only; site outcome counts explain missing rows without treating them as a deterministic regression.

CPU and memory timelines

These are bounded 40-point views of the same complete process-tree samples used by the HTML report. CPU uses 100% per occupied logical core; memory lines are RSS first and PSS second when complete PSS samples are available.

Base

xychart-beta
    title "Base CPU"
    x-axis "Elapsed seconds" [1.536, 2.537, 3.037, 4.038, 5.542, 7.044, 8.546, 10.049, 11.05, 12.552, 14.053, 15.557, 17.058, 18.06, 19.561, 21.063, 22.565, 24.068, 25.57, 26.571, 28.073, 29.574, 31.141, 31.642, 32.644, 33.645, 34.646, 35.146, 36.648, 38.15, 39.652, 40.653, 42.156, 43.657, 45.158, 46.661, 47.661, 49.163]
    y-axis "CPU percent" 0 --> 200
    line [125.91, 130.02, 97.99, 119.79, 129.39, 137.9, 75.95, 95.75, 127.98, 39.9, 79.91, 55.86, 35.97, 61.82, 119.92, 103.78, 105.93, 47.94, 129.87, 115.89, 113.92, 21.98, 47.94, 147.79, 109.89, 93.96, 2, 19.98, 23.96, 57.93, 25.96, 23.97, 29.92, 19.97, 137.78, 145.77, 31.95, 131.86]
Loading
xychart-beta
    title "Base memory: RSS then PSS"
    x-axis "Elapsed seconds" [0.035, 1.536, 2.537, 3.037, 4.038, 5.542, 7.044, 8.546, 10.049, 11.05, 12.552, 14.053, 15.557, 17.058, 18.06, 19.561, 21.063, 22.565, 24.068, 25.57, 26.571, 28.073, 29.574, 31.141, 31.642, 32.644, 33.645, 34.646, 35.146, 36.648, 38.15, 39.652, 40.653, 42.156, 43.657, 45.158, 46.661, 47.661, 49.163, 50.323]
    y-axis "Memory MiB" 0 --> 500
    line [14.11, 101.8, 114.71, 131.88, 143.07, 137.15, 147.82, 122.66, 142.22, 139.12, 142.5, 145.06, 131.7, 141.01, 146.21, 157.8, 268.65, 205.74, 135.88, 155.63, 148.73, 151.54, 134.51, 161.08, 195.66, 234.43, 225.71, 224.82, 225.5, 230.44, 235.37, 231.66, 231.82, 241.32, 148.21, 165.26, 143.68, 133.88, 169.81, 0]
    line [11.06, 98.77, 111.52, 128.64, 139.85, 133.96, 144.55, 119.4, 138.85, 135.73, 139.2, 141.68, 128.32, 138.04, 142.58, 156.72, 265.2, 202.43, 132.47, 152.23, 145.32, 148.11, 131.07, 158.87, 191.75, 230.82, 222.54, 221.61, 222.45, 227.21, 232.31, 228.43, 228.6, 238.03, 145, 162.09, 140.42, 130.7, 166.85, 0]
Loading

HEAD

xychart-beta
    title "HEAD CPU"
    x-axis "Elapsed seconds" [1.543, 3.044, 4.545, 6.047, 7.551, 9.054, 10.556, 12.058, 13.559, 15.061, 16.063, 16.563, 18.064, 18.565, 19.566, 21.069, 22.571, 24.074, 25.576, 27.079, 28.58, 30.082, 31.583, 33.084, 34.585, 36.087, 36.588, 37.588, 39.09, 40.591, 42.092, 43.594, 45.095, 46.597, 48.099, 49.6, 51.102, 52.603]
    y-axis "CPU percent" 0 --> 200
    line [51.97, 99.92, 83.95, 131.73, 91.79, 129.7, 143.74, 29.98, 57.99, 21.96, 0, 7.98, 80.09, 155.69, 49.96, 39.93, 79.9, 115.7, 121.78, 129.75, 72.03, 57.91, 97.91, 109.88, 55.96, 119.93, 103.89, 64.02, 53.96, 0, 55.94, 2, 23.98, 57.84, 11.99, 111.9, 97.92, 151.83]
Loading
xychart-beta
    title "HEAD memory: RSS then PSS"
    x-axis "Elapsed seconds" [0.041, 1.543, 3.044, 4.545, 6.047, 7.551, 9.054, 10.556, 12.058, 13.559, 15.061, 16.063, 16.563, 18.064, 18.565, 19.566, 21.069, 22.571, 24.074, 25.576, 27.079, 28.58, 30.082, 31.583, 33.084, 34.585, 36.087, 36.588, 37.588, 39.09, 40.591, 42.092, 43.594, 45.095, 46.597, 48.099, 49.6, 51.102, 52.603, 53.631]
    y-axis "Memory MiB" 0 --> 500
    line [13.78, 97.74, 113.18, 133.39, 152.48, 124.38, 154.96, 136.1, 140.5, 117.42, 122.5, 121.09, 119.64, 137.86, 138.29, 119.3, 124.88, 142.64, 205.01, 178.53, 195.14, 147.01, 144.93, 137.55, 132.1, 146.14, 244.14, 247.99, 229.61, 228.24, 233.02, 234.04, 232.61, 232.74, 155.79, 132.26, 162.16, 131.79, 162.22, 0]
    line [10.86, 94.61, 110.08, 130.1, 149.63, 121.21, 151.68, 132.93, 137.3, 114.2, 119.28, 117.87, 116.42, 134.79, 135.06, 116.08, 121.7, 139.44, 201.81, 175.32, 192.11, 143.83, 141.92, 134.37, 128.92, 142.96, 241.06, 244.81, 226.5, 226.31, 229.84, 230.86, 229.43, 229.56, 152.45, 128.87, 158.68, 128.38, 158.93, 0]
Loading

Deterministic fixture · required contract

The fixture exercises 15 routes: 8 are expected to emit rows and 7 intentionally exercise empty, loading, or timeout behavior.

Metric Base HEAD Δ
Run status success success —
Extracted rows / contract 40 / 40 40 / 40 0 (0.00%)
Contract fill 100.00% 100.00% 0.00 pp (0.00%)
Sites with rows 8 / 15 8 / 15 0 (0.00%)
Sites meeting row contract 15 / 15 15 / 15 0 (0.00%)
Unexpected empty sites 0 0 0
Partial-row sites 0 0 0
Site outcomes extracted: 7; HTTP error + rows: 1; empty: 3; timeout + empty: 4 extracted: 7; HTTP error + rows: 1; empty: 3; timeout + empty: 4 —
Observed duration 19.88 s 19.91 s +0.03 s (+0.14%)
Estimated CPU 0.46 s 0.45 s -0.01 s (-1.95%)
Peak PSS 72.21 MiB 71.59 MiB -0.62 MiB (-0.85%)
Peak RSS 75.31 MiB 75.06 MiB -0.25 MiB (-0.33%)
Peak threads 22 22 0 (0.00%)
Mismatched sites 0 0 0
Timeout with items 0 0 0

Full HTML, JSON, CSV, logs, and page snapshots: workflow run and full spider-bench-results artifact.

The public-web A/B is informational. The exact HEAD fixture contract runs as a separate required CI check; timing and public-site content deltas remain non-blocking.

@github-actions

github-actions Bot commented Oct 21, 2026 •

Copy link
Copy Markdown

Sequential Navigation Soak A/B

✅ HEAD completed the 200-navigation resilience and memory observation.

One browser process, one target, and one CDP session navigate CSDN → SegmentFault → Huaban → example.com repeatedly. This run issued 200 Page.navigate commands per binary.

Common ancestor 0197ba5e1b → HEAD 3c946d191e; benchmark order: head-first; workflow: success.

Session resilience

Metric Base HEAD
Attempted / planned 200 / 200 200 / 200
Direct observable pass 199 / 200 198 / 200
Failures / recovered 1 / 1 2 / 2
Recovery failures 0 0
Lifecycle order violations 0 0
Network order violations 0 0
Wall time 461.6 s 476.7 s

A public-page failure is reported separately from an unrecoverable session. The soak requires all navigation attempts, zero failed recovery, zero lifecycle/network ordering violations, and complete resource evidence.

Process-tree memory

Metric Base HEAD Δ
Boundary samples 200 200 0
Boundary RSS samples 200 200 0
Boundary PSS samples 200 200 0
Periodic peak RSS 238.7 MiB 250.5 MiB +11.7 MiB
Periodic peak PSS 234.9 MiB 247.4 MiB +12.5 MiB
RSS · first 10 avg 171.4 MiB 179.1 MiB +7.7 MiB
RSS · last 10 avg 187.8 MiB 185.7 MiB -2.1 MiB
RSS · last − first window +16.5 MiB +6.6 MiB -9.9 MiB
RSS · warm slope / 100 nav +8.0 MiB +5.7 MiB -2.3 MiB
PSS · first 10 avg 168.9 MiB 176.0 MiB +7.2 MiB
PSS · last 10 avg 184.7 MiB 183.4 MiB -1.3 MiB
PSS · last − first window +15.9 MiB +7.4 MiB -8.5 MiB
PSS · warm slope / 100 nav +7.6 MiB +6.3 MiB -1.3 MiB
Peak file descriptors 75 74 -1
Peak threads 34 34 0

HEAD memory by 50-navigation quarter

HEAD range Avg RSS Final RSS Peak RSS Avg PSS Final PSS Peak FD
1–50 181.4 MiB 158.0 MiB 225.0 MiB 178.2 MiB 154.9 MiB 67
51–100 182.3 MiB 131.5 MiB 222.2 MiB 178.5 MiB 127.4 MiB 66
101–150 184.7 MiB 161.1 MiB 225.8 MiB 181.3 MiB 158.2 MiB 66
151–200 186.6 MiB 171.7 MiB 230.8 MiB 184.1 MiB 169.5 MiB 66

Raw reports and per-navigation boundary samples: workflow run and full sequential-navigation-soak-results artifact.

Public-site timing and memory are observational. Use the A/B deltas and trend shape as evidence, not as a deterministic performance threshold.

@ldm0
ldm0 force-pushed the fix/detached-window-lazy-surfaces-20261021 branch 4 times, most recently from 2eb2e7b to b24ebd5 Compare October 28, 2026 19:51
@ldm0
ldm0 force-pushed the fix/detached-window-lazy-surfaces-20261021 branch from b24ebd5 to f501ac7 Compare November 14, 2026 17:44
ldm0 added 5 commits November 15, 2026 02:12
A retained child's original SameObject getter captured undefined when
its lazy surface had never been read. Returning that snapshot after retirement
made Window.screen disappear when an iframe was removed before its first read.

Use captured objects when present, and let the exact retained native global
materialize an untouched surface in its original Realm. Retain receiver and
cross-origin authorization. Cover cold Screen reads, identity and zero geometry.

Fixes: 9f11881 (PR #1651)

Validate this independent patch on main ce0781f:
- cargo fmt --all
- cargo clippy --workspace --all-targets --all-features -- -D warnings
- cargo nextest run --no-fail-fast
     Summary [ 380.812s] 20434 tests run: 20434 passed, 18 skipped

Original-commit: f202f5d
Validate the defining Window realm after constructor getters run. Cover all cold detached Window surfaces, stale getters across navigation, receiver and origin checks, and realm/host release. Compare the Performance seed directly in V8 to avoid JSON float parsing noise.
Keep retained definitions and pending whenDefined promises on the registry JS object, so replacing a child Document cannot redirect old registry operations to its replacement or keep retired realms rooted from the native host. Capture registry identity from the committed Document owner before adapter maps are updated, and cover reinsertion, navigation, borrowed queries and GC.
@ldm0
ldm0 force-pushed the fix/detached-window-lazy-surfaces-20261021 branch from f501ac7 to 3c946d1 Compare November 14, 2026 18:13
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.

1 participant