Repository navigation
fix(page): cancel provisional navigation on Page.stopLoading - #2800
lanyue-llk wants to merge 3 commits into
Conversation
lanyue-llk
left a comment
There was a problem hiding this comment.
Independent review of f067cec
Changes needed (1)
- The stopped document request never gets
Network.loadingFailed. The new stop path ismoli-protocol/src/domains/page/termination.rs:201-212. It cancels throughclear_pending_document_navigation_for_owner_if_loader_matches, and the cancelled background navigation then resolves throughPreparedRendererNavigationResult::superseded→PreparedNavigationFailureCleanup::superseded(domains/page/navigation_cleanup.rs:21-41). That path only callspush_superseded_navigation_result, soPage.navigategetsnet::ERR_ABORTEDbut no network terminal event is sent.- Chrome 157, same repro with
Network.enable:Network.loadingFailed {requestId: <slow loaderId>, type: "Document", errorText: "net::ERR_ABORTED", canceled: true}, thenframeStoppedLoading. - moli: the existing superseded path already behaves this way on v1.1.23 when
/slowis superseded by a secondPage.navigate. The client seesrequestWillBeSent(LID-2)and then nothing else for that request. - Effect: after a stop, the
/slowrequest stays in flight in Puppeteer's and Playwright's network managers. There is norequestfailed, and Playwrightnetworkidlewaits never settle. - Smallest fix: in the superseded failure cleanup, emit the failed-progress events the way
superseded_intercepted_navigation_eventsalready does (network::failed_navigation_progress_gate(conn, &state, NET_ERR_ABORTED_ERROR_TEXT)drained until body-finished) instead of the bare result. Then add an assertion forNetwork.loadingFailedwithcanceled: truetostop_loading_aborts_a_provisional_navigation(cdp_dynamic_page.rs:4767) withNetwork.enable.
- Chrome 157, same repro with
Checked, no issue:
- The cancelled loader is the pending one:
page_slot.rs:1203current_document_loader_idprefers the uncommitted request. - The committed
/homepage and its workers stay.close_dedicated_workers_outside_navigation_page(.., None)spares the current residence. - The change is target-local because it is owner-scoped.
- Stop with no navigation in flight is unchanged: no slot match, so no extra
frameStoppedLoading, which matches Chrome. - A later navigation starts a fresh request. Fetch-paused stop is untouched.
- The new test would hang or fail without the fix, because
Page.navigateid 3 never resolves. - CI: Nextest, Clippy, Format, Node and Python harness tests and Windows storage pass. CDP smoke and the release builds are still queued.
Scope vs #2765: this PR fixes case 1 (provisional navigation, including the ERR_ABORTED result and no late commit), except for the missing loadingFailed above. It leaves case 2 open (stopping a streaming document keeps parsing the tail; renderer main_document_lifecycle_body.rs). It also leaves the addendum open: moli commits at response headers when the body is held (HTTP 500 or XML), so a stop in that window still lands on the new URL, and the XML case crashes (#2796). The body correctly says "Part of #2765" rather than "Closes".
Picture: pending.
lanyue-llk
left a comment
There was a problem hiding this comment.
Independent review of 3414dbd (round 2)
No blocking findings
The round-1 finding is fixed. PreparedNavigationFailureCleanup::superseded (moli-protocol/src/domains/page/navigation_cleanup.rs:36-47) now drains failed_navigation_progress_gate(.., NET_ERR_ABORTED) before the Page.navigate result. This is the same construction superseded_intercepted_navigation_events uses (navigation.rs:1104). The stopped request now ends with loadingFailed {Document, net::ERR_ABORTED, canceled: true}, and the new test asserts that against the announced /slow requestId. The fixture's 30 s sleep means the test would time out if the event only arrived when the response settled.
Plain supersede: no double or stale loadingFailed.
superseded()is reached only fromPreparedRendererNavigationResult::prepare_with_output/prepare_materialized(renderer_navigation.rs:433,465) and fromprepare_failed_navigation_cleanup(navigation_cleanup.rs:78). Each of these runs once per navigation, when its outcome is not current. On every one of these paths the outcome's own progress gate is dropped undrained (failureis discarded and the Loaded/ResponseCommitReady gate is never published). So noresponseReceived/loadingFinished/loadingFailedfor that request was sent earlier.- Fetch-paused navigations that a new navigation retires go through
take_superseded_intercepted_document_navigations(navigation.rs:2756). They are removed frompending_fetch_navigations, so they never resolve throughsuperseded(). Paused navigations that resolve on their own resolve asDocumentNavigationOutcome::Superseded→prepare_superseded_fetch_navigation(fetch/document_navigation.rs:125), not asOther. These paths are disjoint, so the request gets one terminal event. - A navigation whose native commit was already accepted still goes through
publish_superseded(navigation_commit.rs:96). That path is unchanged: metadata only, noloadingFailed. - The event is gated on Network listeners and
state.request_id, so it is not sent when Network is disabled.
Event order (disclosed difference). Chrome 157 orders stop as loadingFailed, then frameStoppedLoading. For plain supersede, Chrome also sends loadingFailed(old) before requestWillBeSent(new); moli sends it after. Neither common client depends on either order (checked in puppeteer-core 25.17.0 and playwright-core 1.65.0 from npm):
- Puppeteer:
FrameManager#onFrameStoppedLoadingonly addsDOMContentLoaded/loadto the frame's lifecycle set.LifecycleWatcher#onRequestFailedonly resolvesnavigationResponseReceivedwhen the id matches the latest navigation request. Completion still needs a loaderId change, which a stop never produces in either browser. - Playwright (Chromium):
crPagedoes not subscribe toPage.frameStoppedLoadingat all.crNetworkManager._onLoadingFailed→frames.requestFailedaborts the pending document only whenpendingDocument().request === request. With moli's supersede order,requestWillBeSent(new)has already replaced the pending document, so the old failure only emitsrequestfailed. With Chrome's order, it aborts the old pending document first. The end state is the same either way, andpage.gotorejects from thePage.navigateerrorText in both cases. - Matching Chrome's stop order is not cheap. It would mean either moving
frameStoppedLoadinginto the async superseded cleanup with a "stopped" marker on the navigation state, or emittingloadingFailedeagerly inPage.stopLoadingand then de-duplicating the later one. Either adds state for no client-visible gain. Leaving it as disclosed is right. Optionally, the body's supersede sentence ("as Chromium does") could say the event is the same and the order differs.
Other checks: the cost claims are plausible (the only new work is on paths that are already abandoning a navigation). The test covers the fix. CI at 3414dbd: Nextest, Clippy, Format, Node/Python harness tests and Windows storage pass; CDP smoke and the release builds are still pending. The body says Part of #2765, which is correct because case 2 and the commit-timing addendum stay open. The picture is still a <!-- picture --> placeholder.
CI Regression ReportSource CI run · source state at render:
Release regression — ✅ HEAD/base failures 0/0; raw binary +0.002536%Package and image size
Startup latency and PSS
Concurrency matrix
Frontend differential — ✅ 1,020/1,020 cases matched; 0 issues
Agent episodes · Moli vs Chromium — ✅ 8/8 Moli episodes passed; 0 failures
Runtime and CDP session contracts — ✅ 26 contract cases; 0 failures
CDP smoke — ❌ 126/128 groups passed; 2,202 scenariosWorkers: 4 · cumulative group time: 520.58 s · failed groups: 2
Failed groups
WebMainBench · 545 pages — ✅ 545/545 completed; 0 unexpected failures
Frozen HTML · Linux · Diagnostics: All artifact fields are parsed by the trusted default-branch renderer; missing or invalid inputs remain visible as unavailable. |
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 Public 48-site run · informational
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 timelinesThese 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. Basexychart-beta
title "Base CPU"
x-axis "Elapsed seconds" [1.335, 2.837, 4.839, 7.342, 9.343, 11.847, 13.849, 16.353, 18.356, 20.859, 22.861, 25.365, 27.369, 29.871, 31.875, 34.376, 36.376, 38.88, 40.884, 43.385, 45.387, 47.886, 49.888, 52.391, 54.391, 56.893, 58.896, 61.398, 62.9, 63.4, 65.903, 67.904, 70.408, 72.409, 74.914, 76.917, 77.418, 79.42]
y-axis "CPU percent" 0 --> 200
line [0, 0, 2, 92.04, 101.85, 137.85, 129.91, 137.64, 111.71, 25.98, 21.98, 2, 0, 5.99, 6, 0, 0, 5.99, 6, 0, 0, 6, 6.01, 129.8, 2, 54.01, 21.99, 129.87, 102.01, 127.82, 111.96, 81.92, 87.93, 77.95, 0, 107.67, 171.93, 71.95]
xychart-beta
title "Base memory: RSS then PSS"
x-axis "Elapsed seconds" [0.334, 1.335, 2.837, 4.839, 7.342, 9.343, 11.847, 13.849, 16.353, 18.356, 20.859, 22.861, 25.365, 27.369, 29.871, 31.875, 34.376, 36.376, 38.88, 40.884, 43.385, 45.387, 47.886, 49.888, 52.391, 54.391, 56.893, 58.896, 61.398, 62.9, 63.4, 65.903, 67.904, 70.408, 72.409, 74.914, 76.917, 77.418, 79.42, 81.141]
y-axis "Memory MiB" 0 --> 500
line [14.15, 58.88, 59.12, 59.13, 121.35, 119.86, 132.23, 136.55, 148.04, 142.59, 143.35, 121.17, 123.04, 121.86, 121.8, 121.8, 121.8, 121.8, 121.93, 122.45, 122.5, 123.03, 123.5, 123.97, 139.38, 117.45, 131.56, 144.17, 157.67, 207.72, 181.81, 169.74, 146.34, 166.29, 151.04, 127.85, 159.11, 156.07, 136.55, 0]
line [11.22, 55.85, 56.08, 56.09, 118.31, 116.89, 129.46, 133.51, 146.15, 139.54, 140.31, 118.13, 119.89, 118.68, 118.78, 118.78, 118.78, 118.78, 118.91, 119.41, 119.46, 119.98, 120.46, 121.58, 136.29, 114.42, 128.65, 141.13, 154.65, 204.73, 178.74, 166.24, 143.28, 163.27, 148.02, 124.8, 156.82, 152.91, 133.68, 0]
HEADxychart-beta
title "HEAD CPU"
x-axis "Elapsed seconds" [1.537, 3.039, 4.541, 5.042, 6.043, 6.544, 8.047, 9.549, 11.052, 12.553, 14.555, 16.058, 17.56, 19.06, 20.561, 22.062, 24.065, 25.567, 27.07, 28.571, 30.074, 31.577, 33.579, 35.081, 36.584, 38.086, 39.588, 41.088, 43.091, 44.593, 46.095, 46.596, 47.597, 49.099, 50.601, 52.605, 54.107, 55.609]
y-axis "CPU percent" 0 --> 200
line [113.92, 127.83, 87.84, 155.65, 131.88, 125.69, 123.76, 123.91, 83.79, 129.98, 0, 5.99, 17.97, 6, 0, 6, 3.99, 133.74, 43.9, 43.98, 53.89, 85.8, 137.91, 109.86, 115.79, 111.93, 111.87, 39.97, 97.83, 39.9, 123.79, 103.72, 121.84, 7.99, 37.88, 129.75, 77.92, 113.8]
xychart-beta
title "HEAD memory: RSS then PSS"
x-axis "Elapsed seconds" [0.035, 1.537, 3.039, 4.541, 5.042, 6.043, 6.544, 8.047, 9.549, 11.052, 12.553, 14.555, 16.058, 17.56, 19.06, 20.561, 22.062, 24.065, 25.567, 27.07, 28.571, 30.074, 31.577, 33.579, 35.081, 36.584, 38.086, 39.588, 41.088, 43.091, 44.593, 46.095, 46.596, 47.597, 49.099, 50.601, 52.605, 54.107, 55.609, 56.886]
y-axis "Memory MiB" 0 --> 500
line [14.22, 92.95, 121.64, 118.24, 146.89, 147.67, 132.43, 142.26, 149.41, 137.54, 152.58, 117.3, 116.61, 121.85, 118.7, 118.78, 119.72, 120.8, 144.5, 118.21, 125.51, 124.09, 154.1, 143.46, 182.97, 198.42, 151.79, 154.61, 138.98, 143.8, 144.2, 236.25, 243.62, 227.85, 157.43, 139.18, 162.36, 144.23, 163.34, 0]
line [11.26, 89.77, 118.46, 115.42, 143.84, 144.21, 129.12, 139.08, 146.26, 134.37, 149.65, 114.1, 113.41, 118.68, 115.53, 115.6, 116.55, 117.62, 141.32, 115.03, 122.33, 120.89, 150.97, 140.3, 179.89, 195.25, 148.59, 151.5, 135.86, 140.69, 141.09, 232.28, 240.52, 224.75, 154.32, 136.68, 159.28, 141.26, 160.26, 0]
Deterministic fixture · required contractThe fixture exercises 15 routes: 8 are expected to emit rows and 7 intentionally exercise empty, loading, or timeout behavior.
Full HTML, JSON, CSV, logs, and page snapshots: workflow run and full 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. |
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 Common ancestor Session resilience
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
HEAD memory by 50-navigation quarter
Raw reports and per-navigation boundary samples: workflow run and full Public-site timing and memory are observational. Use the A/B deltas and trend shape as evidence, not as a deterministic performance threshold. |
d0ae75d to
69842e7
Compare
69842e7 to
5dd642f
Compare
5dd642f to
2e916b2
Compare

**Track:** Trajectory Replay (Browser Eval). Replaces part of #759.Part of #2765.
Replaces part of #759.
Problem
Page.stopLoadingduring a provisional navigation did not cancel it: the pendingPage.navigatenever resolved, the slow response later committed, and the page moved to the URL the client had stopped. Chromium resolvesPage.navigatewitherrorText: "net::ERR_ABORTED", firesPage.frameStoppedLoading, and keeps the current document. Repro (issue case 1):Page.navigate /home; sendPage.navigate /slow(8 s response) without awaiting; after 1 sPage.stopLoading; readlocation.href + " | " + document.body.innerHTML.Reproduce (steps from #2765, case 1)
The server's
/homereturns<p id=home>home page</p>. Its/slowwaits 8 s and then returns<p id=slow>slow page</p>.Page.navigate /home, then wait 1 s.Page.navigate /slowwithout awaiting it.Page.stopLoading.location.href + " | " + document.body.innerHTMLafter 10 s.Expected (Chromium):
Page.navigateresolves witherrorText: "net::ERR_ABORTED",frameStoppedLoadingfires, and the page stays/home | <p id="home">home page</p>.Actual:
stopLoadingreturns{}andPage.navigatestays pending. Then/slowcommits: a secondframeNavigated(/slow) andloadEventFiredarrive, and the page becomes/slow | <p id="slow">slow page</p>.Change
moli-protocol/src/domains/page/termination.rs(PreparedPageStopLoading::prepare) only stopped the loaded document's lifecycle and Fetch-paused work. It now also cancels the target's uncommitted document navigation through the existingclear_pending_document_navigation_for_owner_if_loader_matches(which usescancel_pending_document_navigation), and emitsPage.frameStoppedLoadingfor the frame whoseframeStartedLoadingwas already sent. The superseded-navigation path that already exists then resolvesPage.navigatewithnet::ERR_ABORTED. Fetch-paused navigations keep their existing stop handling (Navigation stopped) unchanged.moli-protocol/src/domains/page/navigation_cleanup.rs(PreparedNavigationFailureCleanup::superseded): the abandoned request now ends withNetwork.loadingFailed {type: "Document", errorText: "net::ERR_ABORTED", canceled: true}, built through the existingfailed_navigation_progress_gateexactly assuperseded_intercepted_navigation_eventsalready does for intercepted navigations. Without it the request stayed in flight for Puppeteer/Playwright network-idle tracking. This also fixes the plain supersede case: a secondPage.navigateduring a pending one now reportsloadingFailed(ERR_ABORTED, canceled) for the first request, as Chromium does (on main it was never terminated).Test:
stop_loading_aborts_a_provisional_navigation(protocol-server CDP test, withNetwork.enable): navigate, start a 30 s navigation, stop; expectserrorText: net::ERR_ABORTED,frameStoppedLoading,Network.loadingFailedfor the stopped request (Document,net::ERR_ABORTED,canceled: true), noframeNavigated, andlocation.pathname == "/home".Known difference: on stop, moli sends
frameStoppedLoading(with thestopLoadingreply) before the request'sloadingFailed(when the cancelled fetch settles); Chromium sendsloadingFailedfirst. Both events arrive within the same turn of the client.Not in this PR: case 2 of #2765 (stopping a streaming document keeps parsing; renderer crate) and the commit-timing addendum (headers-received-but-body-held responses commit before stop can abort them). Those need separate changes.
Verification
Before: released v1.1.23 (same code path as
origin/main); after: debug build of this branch.Plain supersede (
Page.navigate /slow, thenPage.navigate /body1after 1 s), main vs this PR:cargo fmt --all: clean.cargo clippy -p moli-protocol -p moli-protocol-server --all-targets --all-features -- -D warnings: passed.cargo nextest run -p moli-protocol -E 'test(stop_loading) | test(stoploading) | test(stop_lifecycle)': 10 passed (existing Fetch-paused stop contracts unchanged).cargo nextest run -p moli-protocol-server -E 'test(stop_loading)': 1 passed (new test).cargo nextest run -p moli-protocol -p moli-protocol-server -E 'test(supersed) | test(stop_loading) | test(navigat)': 761 passed.Cost
Debug builds of
origin/main(f935014) and this branch,/usr/bin/time -l, median of 5 runs:moli serve, script has ~10.5 s of fixed sleeps)moli fetchof a local 46 KB articleThe repro gets faster because the stopped
/slowresponse is no longer fetched, committed and evaluated. The new work runs only insidePage.stopLoading, and only when the target has an uncommitted navigation (one slot lookup otherwise); navigation, loading and fetch paths are unchanged. The addedloadingFailedis built only for a navigation that is already being abandoned, and only when a Network listener is enabled.