Skip to content

fix(page): stop parsing a streaming document after Page.stopLoading - #2817

Merged
ldm0 merged 1 commit into
mainfrom
fix/stop-loading-streaming-parser
Nov 13, 2026
Merged

ldm0 merged 1 commit into
mainfrom
fix/stop-loading-streaming-parser

Conversation

@lanyue-llk

@lanyue-llk lanyue-llk commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

PR #2817 at a glance

**Track:** Trajectory Replay (Browser Eval). Replaces part of #759.

Part of #2765.
Replaces part of #759.

Problem

Page.stopLoading on a document that is still streaming set readyState to complete but left the streaming parser input open, so bytes that arrived later were still parsed and the DOM kept changing after the stop. Repro (issue case 2): /stream sends <html><body><p id=prefix>committed prefix</p>, waits 8 s, then <p id=tail>tail</p></body></html>; navigate, wait 2 s, Page.stopLoading, read document.body.innerHTML immediately and after 8 s.

Reproduce (steps from #2765, case 2)

/stream sends <html><body><p id=prefix>committed prefix</p> as a chunk, waits 8 s, then sends <p id=tail>tail</p></body></html>.

Navigate, wait 2 s, send Page.stopLoading, and evaluate document.body.innerHTML immediately and again after 8 s.

Expected (Chromium): both reads give <p id="prefix">committed prefix</p>, and frameStoppedLoading fires.

Actual: immediately after the stop the body is the prefix, but 8 s later it is <p id="prefix">committed prefix</p><p id="tail">tail</p>. No frameStoppedLoading is sent.

Change

  • moli-renderer-v8/src/runtime/page_vm/mod.rs: PageVm::document_loading_was_stopped() reports whether the current document's lifecycle was terminated by Page.stopLoading (the existing Stopped termination recorded by stop_document_lifecycle).
  • moli-renderer-v8/src/runtime/phase_one/streaming_residence.rs (PendingStreamingPhaseOneContinuation::resume): when the document was stopped, input that arrives afterwards is not parsed; the parser input is closed and the input source is dropped with the continuation, which cancels the rest of the body.
  • Test: stop_loading_stops_parsing_a_streaming_document (protocol-server CDP test): stream a prefix, stop, release the tail; the tail is never parsed and readyState stays complete.

Not covered here: after stopping a committed streaming document moli still sends no Page.frameStoppedLoading (case 2's second expectation), and subresource fetches are not cancelled on stop. Case 1 (provisional navigation) is #2800.

Verification

Before: debug build of origin/main f935014; after: debug build of this branch.

# before
after stop: /stream | complete | <p id="prefix">committed prefix</p>
after 8s:   complete | <p id="prefix">committed prefix</p><p id="tail">tail</p>
# after
after stop: /stream | complete | <p id="prefix">committed prefix</p>
after 8s:   complete | <p id="prefix">committed prefix</p>
  • cargo fmt --all: clean.
  • cargo clippy -p moli-renderer-v8 -p moli-protocol-server --all-targets --all-features -- -D warnings: passed.
  • cargo nextest run -p moli-protocol-server -E 'test(stop_loading)': passed (new test). Negative control: with the streaming_residence.rs change reverted, the new test fails (tail parsed).
  • cargo nextest run -p moli-renderer-v8 -E 'test(stream) | test(stop) | test(lifecycle)': 1296 passed.
  • Not run locally: workspace-wide clippy and the full workspace nextest; left to CI.

Cost

Debug builds, /usr/bin/time -l, median of 5 runs (repro: two interleaved rounds; shared host):

main this PR
issue repro over CDP (moli serve; ~10.5 s of fixed sleeps) 10.70 / 10.86 s, 98.9 / 92.4 MB max RSS 10.86 / 10.69 s, 92.6 / 98.5 MB
ordinary page, moli fetch of a local 46 KB article 0.080 s, 88.8 MB 0.080 s, 88.9 MB

The new check is one lifecycle-snapshot read when a parked streaming parser resumes; documents that are not stopped take the existing path unchanged, and nothing new is retained.

@lanyue-llk lanyue-llk left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Independent review of e50fc1e

No blocking findings

Checked against origin/main f98df6c. The PR is a single commit on main and does not include #2800's commits.

  • Correctness: streaming_residence.rs:94-103. When a parked main-document continuation resumes after Page.stopLoading, chunks that arrived after the stop are not enqueued. The input is closed once: input_finished = true, so the continuation is never re-parked as open_streaming, and the deferred-failure branch is excluded. The prefix that was already parsed stays in the DOM. readyState stays complete and no load event fires, because the existing stop_loading_without_load_event already sets load = Suppressed and clears the interactive/DCL/complete tokens. Chrome behaves the same here: stop-stream on headless Chrome gives complete | <p id="prefix">committed prefix</p> after 8 s, with no Page.loadEventFired. Stopping when no streaming continuation exists is a no-op. The flag is not sticky. It comes from the current document's lifecycle snapshot, and a cross-document commit installs a new lifecycle via start_cross_document (page_vm/mod.rs:1483), so the next navigation parses normally. Child-frame documents do not use this continuation.
  • Cost: one lifecycle-snapshot read per resume of a parked streaming parser. Documents that were not stopped take the existing path. The before/after numbers are plausible.
  • Test: stop_loading_stops_parsing_a_streaming_document releases the tail after the stop. Without the change the tail would be parsed, so the test fails as intended.
  • CI: Clippy, Format, Node, Python and Windows pass. Nextest, CDP smoke and the release builds are still pending.
  • Picture: pending.

Non-blocking notes, outside this PR's scope:

  1. Only input that arrives after the stop is discarded. Bytes that were buffered before the stop but not yet tokenized are still parsed when the parser resumes. For example, the stream contains <script src=slow.js></script><p>x</p> and the stop happens while slow.js is loading. That case belongs with the disclosed subresource-cancellation follow-up for #2765.
  2. The body says that dropping input "cancels the rest of the body". That happens only at the next wake (the next chunk or EOF). If the server sends nothing more, the connection stays open until then.

@github-actions

github-actions Bot commented Nov 12, 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.00%
Frontend differential ✅ 1,020/1,020 cases matched; 0 issues; 1 Chromium reference recoveries
Agent episodes ✅ 8/8 Moli episodes passed; 0 failures
Runtime/CDP contracts ✅ 26 contract cases; 0 failures
CDP smoke ✅ 116/116 groups passed; 1,714 scenarios
WebMainBench ✅ 545/545 completed; 0 unexpected failures
Release regression — ✅ HEAD/base failures 0/0; raw binary 0.00%

Package and image size

Metric Base HEAD Delta Delta %
Raw binary 154.20 MiB 154.20 MiB 0 B 0.00%
Stripped binary 106.63 MiB 106.63 MiB 0 B 0.00%
gzip binary 53.23 MiB 53.23 MiB −316 B −0.000566%
Rootfs 161.10 MiB 161.10 MiB 0 B 0.00%
gzip rootfs 62.32 MiB 62.32 MiB −737 B −0.001128%

Startup latency and PSS

Case Base p50 HEAD p50 Delta Base PSS HEAD PSS Delta
Serve ready 26.86 ms 26.93 ms +0.07 ms 4.63 MiB 4.27 MiB −367.00 KiB
CDP first page 50.21 ms 49.97 ms −0.24 ms 4.82 MiB 4.93 MiB +112.50 KiB
CDP warm page 11.89 ms 12.43 ms +0.54 ms 53.15 MiB 52.67 MiB −484.00 KiB
CLI about:blank 13.84 ms 12.92 ms −0.92 ms 4.82 MiB 3.32 MiB −1.50 MiB
CLI local JS 25.06 ms 26.59 ms +1.53 ms 3.53 MiB 3.83 MiB +303.50 KiB

Concurrency matrix

Concurrency Base p50 HEAD p50 Delta Base PSS HEAD PSS Delta HEAD failures Unstable B/H
1 24.25 ms 24.60 ms +0.35 ms 736.00 KiB 684.00 KiB −52.00 KiB 0 0/0
5 28.47 ms 28.87 ms +0.40 ms 12.80 MiB 12.22 MiB −596.50 KiB 0 0/0
10 27.69 ms 28.27 ms +0.58 ms 13.36 MiB 13.21 MiB −155.50 KiB 0 0/0
25 27.37 ms 28.38 ms +1.00 ms 22.69 MiB 15.66 MiB −7.03 MiB 0 0/0
100 28.51 ms 27.80 ms −0.71 ms 12.99 MiB 11.72 MiB −1.27 MiB 0 0/0
Frontend differential — ✅ 1,020/1,020 cases matched; 0 issues; 1 Chromium reference recoveries
Match DOM mismatch Diagnostic mismatch Moli error Reference error Infrastructure error Mismatched frames Duration
1,020 0 0 0 0 0 0 8m 26.40s

Recovered Chromium reference infrastructure failures

  • angular/collections/large-inventory — 1 failed attempt(s) before recovery · timed out waiting for Page.loadEventFired event after 92s
Agent episodes · Moli vs Chromium — ✅ 8/8 Moli episodes passed; 0 failures
Fast contract Episodes Passed Assertions Ready p50 Episode p50
Moli 8 8 47/47 28.62 ms 30.22 ms
Chromium 8 8 47/47 607.75 ms 129.32 ms
Operation p50 Chromium Moli Delta Delta %
navigate 43.09 ms 6.07 ms −37.02 ms −85.92%
observe 1.11 ms 1.26 ms +0.16 ms +14.01%
fill 7.80 ms 3.35 ms −4.45 ms −57.01%
click 12.17 ms 4.14 ms −8.03 ms −65.98%
Idle-resource episode Peak RSS Peak PSS Average CPU Peak CPU Peak processes Sampler
Moli 70.20 MiB 67.56 MiB 0.98% 24.07% 1 ✅
Chromium 1307.51 MiB 431.37 MiB 1.40% 22.01% 13 ⚠️ PSS partial
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 24.53 ms 25.73 ms 719.00 KiB
Long-lived CDP session 13 0 18.43 ms 19.27 ms —
CDP smoke — ✅ 116/116 groups passed; 1,714 scenarios

Workers: 4 · cumulative group time: 463.87 s · failed groups: 0

Slowest group Scenarios Duration Status
fetch-resource-dispatch 72 22.85 s ✅
fetch-resource-dispatch 72 22.52 s ✅
dom-input 62 22.21 s ✅
dom-input 62 22.08 s ✅
scrollbar-visibility 22 20.96 s ✅
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

Copy link
Copy Markdown

Spider Bench A/B

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

Public HEAD: 189 / 240 rows; 39 / 48 sites produced rows; 9 unexpected empty sites.

✅ Deterministic fixture contract is clean.

Common ancestor 071e553e5b20 → HEAD 722cea326c66; benchmark order: base-first; workflow: success.

Public 48-site run · informational

Metric Base HEAD Δ
Run status success success —
Extracted rows / contract 189 / 240 189 / 240 0 (0.00%)
Contract fill 78.75% 78.75% 0.00 pp (0.00%)
Sites with rows 39 / 48 39 / 48 0 (0.00%)
Sites meeting row contract 37 / 48 37 / 48 0 (0.00%)
Unexpected empty sites 9 9 0 (0.00%)
Partial-row sites 2 2 0 (0.00%)
Site outcomes extracted: 37; HTTP error + rows: 2; empty: 8; snapshot error + empty: 1 extracted: 38; HTTP error + rows: 1; empty: 8; snapshot error + empty: 1 —
Observed duration 54.37 s 51.43 s -2.94 s (-5.41%)
Estimated CPU 38.17 s 37.33 s -0.83 s (-2.19%)
Peak PSS 266.41 MiB 246.32 MiB -20.09 MiB (-7.54%)
Peak RSS 269.19 MiB 250.46 MiB -18.73 MiB (-6.96%)
Peak threads 30 30 0 (0.00%)
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 27 / 40 27 / 40 0
games 37 / 40 37 / 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.539, 3.041, 4.545, 6.047, 7.549, 9.05, 10.554, 12.055, 13.557, 15.058, 16.56, 18.063, 19.565, 20.567, 21.068, 22.57, 24.073, 25.574, 26.575, 27.577, 29.079, 30.581, 32.084, 33.586, 35.087, 36.591, 38.092, 39.594, 41.095, 42.597, 44.099, 45.6, 47.101, 48.603, 49.605, 50.105, 51.608, 53.108]
    y-axis "CPU percent" 0 --> 200
    line [5.99, 99.85, 91.82, 129.86, 109.95, 131.94, 107.73, 127.88, 13.97, 72, 2, 7.98, 2, 0, 3.99, 46, 93.93, 131.93, 103.84, 113.8, 135.96, 137.76, 113.65, 77.89, 5.99, 9.97, 0, 7.99, 0, 5.99, 2, 115.89, 7.99, 11.99, 163.87, 119.9, 131.79, 119.97]
Loading
xychart-beta
    title "Base memory: RSS then PSS"
    x-axis "Elapsed seconds" [0.037, 1.539, 3.041, 4.545, 6.047, 7.549, 9.05, 10.554, 12.055, 13.557, 15.058, 16.56, 18.063, 19.565, 20.567, 21.068, 22.57, 24.073, 25.574, 26.575, 27.577, 29.079, 30.581, 32.084, 33.586, 35.087, 36.591, 38.092, 39.594, 41.095, 42.597, 44.099, 45.6, 47.101, 48.603, 49.605, 50.105, 51.608, 53.108, 54.367]
    y-axis "Memory MiB" 0 --> 500
    line [13.69, 67.32, 123.72, 118.82, 155.16, 139.72, 150.21, 142.67, 140.25, 122, 129.63, 147.64, 120.21, 123.74, 122.26, 121.33, 126.95, 131.14, 147.91, 269.19, 180.43, 158.14, 163.26, 158.36, 146.82, 132.85, 141.21, 140.22, 140.21, 140.06, 140.04, 140.04, 137.3, 144.75, 128.35, 135.43, 153.77, 160.79, 154.46, 0]
    line [10.3, 63.88, 120.28, 115.28, 151.86, 136.14, 146.57, 139.05, 136.63, 118.39, 126.05, 144.02, 116.59, 120.12, 118.64, 117.71, 124.05, 127.87, 144.5, 266.41, 176.85, 154.57, 159.78, 154.74, 143.12, 129.12, 137.58, 136.58, 136.58, 136.43, 136.41, 136.41, 133.67, 141.11, 124.72, 131.93, 151.18, 157.17, 150.86, 0]
Loading

HEAD

xychart-beta
    title "HEAD CPU"
    x-axis "Elapsed seconds" [1.539, 2.541, 3.041, 4.043, 4.544, 5.545, 7.048, 8.55, 10.052, 11.554, 13.055, 14.557, 15.058, 15.559, 17.061, 18.564, 20.065, 21.567, 23.069, 24.57, 26.073, 27.075, 28.575, 30.077, 31.579, 33.079, 34.58, 36.082, 37.084, 38.586, 40.087, 41.587, 43.09, 44.593, 46.095, 47.097, 48.598, 50.1]
    y-axis "CPU percent" 0 --> 200
    line [83.92, 111.74, 45.98, 99.81, 131.61, 123.88, 113.76, 91.83, 41.96, 141.94, 2, 4, 0, 37.9, 71.81, 61.84, 39.98, 65.95, 129.86, 107.94, 119.74, 123.86, 105.88, 105.84, 79.89, 27.98, 8, 0, 0, 7.99, 0, 7.99, 119.71, 95.86, 11.99, 105.84, 157.78, 117.91]
Loading
xychart-beta
    title "HEAD memory: RSS then PSS"
    x-axis "Elapsed seconds" [0.037, 1.539, 2.541, 3.041, 4.043, 4.544, 5.545, 7.048, 8.55, 10.052, 11.554, 13.055, 14.557, 15.058, 15.559, 17.061, 18.564, 20.065, 21.567, 23.069, 24.57, 26.073, 27.075, 28.575, 30.077, 31.579, 33.079, 34.58, 36.082, 37.084, 38.586, 40.087, 41.587, 43.09, 44.593, 46.095, 47.097, 48.598, 50.1, 51.426]
    y-axis "Memory MiB" 0 --> 500
    line [13.73, 92.29, 112.54, 110.37, 127.62, 130.72, 145.77, 144, 125.02, 151.87, 134.85, 124.5, 124.32, 124.29, 132.15, 151.98, 128.82, 132.96, 155.57, 146.57, 250.46, 192.15, 139.52, 172.1, 161.09, 149.71, 139.44, 141.89, 140.79, 140.77, 140.45, 140.41, 140.4, 183.13, 157.41, 130.16, 149.76, 139.74, 157.25, 0]
    line [10.28, 88.65, 109.16, 106.75, 123.98, 127.22, 142.54, 140.4, 121.39, 148.24, 131.42, 120.85, 120.68, 120.64, 128.51, 148.33, 124.81, 129.32, 152, 142.92, 246.32, 188.85, 135.87, 168.49, 157.56, 146.13, 135.79, 138.25, 137.14, 137.13, 136.8, 136.77, 136.76, 178.21, 153.77, 126.5, 146.17, 136.17, 153.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.87 s 19.88 s +0.01 s (+0.05%)
Estimated CPU 0.45 s 0.48 s +0.03 s (+6.18%)
Peak PSS 69.64 MiB 69.65 MiB +0.01 MiB (+0.01%)
Peak RSS 73.06 MiB 73.06 MiB -0.00 MiB (-0.01%)
Peak threads 21 21 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

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 071e553e5b → HEAD 722cea326c; benchmark order: base-first; workflow: success.

Session resilience

Metric Base HEAD
Attempted / planned 200 / 200 200 / 200
Direct observable pass 196 / 200 199 / 200
Failures / recovered 4 / 4 1 / 1
Recovery failures 0 0
Lifecycle order violations 0 0
Network order violations 0 0
Wall time 539.7 s 498.4 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 264.5 MiB 258.4 MiB -6.0 MiB
Periodic peak PSS 260.8 MiB 257.0 MiB -3.8 MiB
RSS · first 10 avg 171.8 MiB 168.0 MiB -3.7 MiB
RSS · last 10 avg 201.2 MiB 206.6 MiB +5.4 MiB
RSS · last − first window +29.5 MiB +38.6 MiB +9.1 MiB
RSS · warm slope / 100 nav +7.4 MiB +2.9 MiB -4.5 MiB
PSS · first 10 avg 168.3 MiB 164.7 MiB -3.6 MiB
PSS · last 10 avg 197.8 MiB 202.9 MiB +5.1 MiB
PSS · last − first window +29.5 MiB +38.2 MiB +8.7 MiB
PSS · warm slope / 100 nav +7.2 MiB +3.0 MiB -4.2 MiB
Peak file descriptors 66 66 0
Peak threads 34 32 -2

HEAD memory by 50-navigation quarter

HEAD range Avg RSS Final RSS Peak RSS Avg PSS Final PSS Peak FD
1–50 186.1 MiB 169.5 MiB 222.7 MiB 182.7 MiB 166.0 MiB 58
51–100 194.7 MiB 207.8 MiB 230.7 MiB 191.4 MiB 204.4 MiB 58
101–150 189.3 MiB 172.9 MiB 230.2 MiB 186.0 MiB 169.7 MiB 56
151–200 197.2 MiB 211.0 MiB 245.3 MiB 193.9 MiB 207.8 MiB 57

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.

@lanyue-llk
lanyue-llk force-pushed the fix/stop-loading-streaming-parser branch from 722cea3 to 31d0de3 Compare November 13, 2026 12:13
@ldm0
ldm0 merged commit 58da945 into main Nov 13, 2026
6 of 10 checks passed
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.

2 participants