Repository navigation
Hold a departing document's faults until it stays, as Firefox aborts its loads at beforeunload - #3280
Merged
Merged
Conversation
Firefox aborts a document's in-flight requests as soon as an uncanceled `beforeunload` lets a navigation start, and keeps the document running until the destination answers. The lifetime that gates fault reports ended only at `pageswap` or `pagehide`, so a navigation away in Firefox during startup or a state read reported the aborted loads as page faults. A probe in stock Firefox 158 and Playwright's Firefox posted "read failed: The operation was aborted" (state body cut off) and "page failed to start: error loading dynamically imported module" (widget module cut off) to the page's log as `error` events, which the agent then hears. Chrome 155 keeps the old document's loads until it commits, so it reported nothing. Behaviour that changed: - prepaint.js: an uncanceled `beforeunload` now ends the lifetime too. The user's next input reopens it, for a navigation that leaves the document in place (a link answered with a download). A canceled `beforeunload` still ends nothing, and `pageshow` still reopens it. The header's earlier "beforeunload cannot end this lifetime" record is rewritten. - A sample child no longer tells its host it departed on a persisted `pagehide`, and no longer stops watching its own intersection then. A frame's own navigation never enters the page cache, so a persisted pagehide is the containing page's, which brings child and port back together. With `no-store` lifted by a proxy, real Chrome restored a page whose sample host then waited forever for a next document. Checked and found harmless: Chrome navigation away during registry load, state headers and state body; removing a loading sample in Chrome and Firefox (the child's `pagehide` lands before its aborted fetches reject). No served Leaf page enters Chrome's or Firefox's back/forward cache today, because documents and API answers carry `no-store`; TODO.md now asks whether that should change. Tests: a Firefox browser test holds a widget module, navigates away and asserts no startup fault, console error or error event (fails on the old lifetime). The runtime lifetime test covers uncanceled and canceled `beforeunload` and the reopening input. A sample test hands the child a cached round trip's events and asserts the host stays presented and the child's visibility still follows scrolling (fails without either child fix). Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…ng a canceled beforeunload Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…nd bound them Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
# Conflicts: # skills/leaf/kernel/kernel.json
# Conflicts: # skills/leaf/kernel/kernel.json
# Conflicts: # skills/leaf/kernel/kernel.json
leaf-agent
approved these changes
Oct 20, 2026
leaf-agent
added a commit
that referenced
this pull request
Oct 24, 2026
The Firefox departure test now accepts the browser's intermittent loopback bounce-tracker notice while still requiring the aborted module-load warning and rejecting other console problems. The [failed main run](https://github.com/max-sixty/leaf/actions/runs/40129051834) reached the intended startup and log assertions, then failed because that additional privacy notice was present in the collected console findings. The test continues to protect the behavior introduced by #3280: a departing page does not report its aborted widget load as a startup fault or log error. This changes only the test's classification of a browser-generated notice; the page runtime and its error handling are unchanged. Verified with `uv run pytest -q -n0 tests/browser/startup/test_readiness.py::test_a_firefox_departure_reports_none_of_the_loads_it_aborts` (passed). The main run's diagnostic supplies the warning-present case; the local focused run exercised the warning-absent case. Co-authored-by: leaf-agent <[email protected]>
leaf-agent
added a commit
that referenced
this pull request
Nov 1, 2026
Iframe removal can reject a sample's pending registry fetch before `pagehide` or `window.closed` marks its document as departed. The shared fault lifetime then reports that cancellation as a startup failure. Fault reports now read the lifetime in the next task, after native removal finishes. Each queued report retains its departure generation so a page-cache return cannot revive a canceled report. This preserves #3280's intent: genuine faults still reach the agent, while a departing document's canceled work does not. Sample retirement still destroys the old realm before releasing its capability. No error-message filtering or sample-specific exception suppression is added. Validation: all three reported sample paths failed on the original code and pass with the correction, including the deliberate startup exception's original name and stack. Twelve focused browser cases pass across sample reset/retirement, reload, Chromium/WebKit native departure, canceled departure, startup faults and Firefox departure. All 737 runtime tests and the browser build pass. The lifetime regression also fails against the original prepaint and passes with the fix; it covers rejection before pagehide and queued cancellation across a page-cache return. The canceled-navigation test now waits for both the native exception and Leaf's deferred report. Closes #4906 — automated triage Co-authored-by: leaf-agent <[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.
Firefox aborts a document's in-flight requests as soon as a
beforeunloadlets a navigation start, and keeps the old document running until the destination answers. The lifetime that gates fault reports (lfDocumentLifetime, prepaint.js) ended only atpageswaporpagehide, so navigating away in Firefox during startup or a state read reported the aborted loads as page faults. Stock Firefox 158 and Playwright's Firefox posted "read failed: The operation was aborted" (state body cut off) and "page failed to start: error loading dynamically imported module" (widget module cut off) to the page's log aserrorevents, which the agent then hears. Chrome 155 keeps the old document's loads until it commits, so it reported nothing.This resolves the TODO item "Verify cancellation when a browser document departs" and replaces it with the decision it leaves (below).
Behaviour that changed
beforeunload, a fault report waits instead of running, because neither engine says whether the navigation will replace the document: a leave prompt the user stays at, or a link answered with a download or a 204, leaves it in place with its aborted requests failed for good.pageswaporpagehidedrops what waited. The user's next press, key or edit reports it. A wheel turn and the document's own firstpageshowreport nothing; a persistedpageshowreopens the lifetime after the page cache restores the document. Only the first report of each fault waits, so a read that keeps failing adds nothing. The header's earlier record, "beforeunload is cancelable and therefore cannot end this lifetime", is rewritten: a canceledbeforeunloadonly asks for a prompt, and the user may still leave.whenActive(fault, report)rather than anactiveflag, and its four consumers report through it: prepaint's startup fault intake, leaf.js's startup catch, layer-client'sreportPageError(which still marks a reason reported at once, soreportCarrieddedupes as before), and bootstrap's sample error port.pagehideno longer tells the host the child departed, and no longer stops the child watching its own intersection. A frame's own navigation never enters the page cache, so a persistedpagehidebelongs to the containing page, which brings child and port back together. Withno-storelifted by a proxy, real Chrome restored a page whose sample host then waited forever for a next document.Checked and found harmless
Chrome navigation away during registry load, state headers and state body; removing a loading sample in Chrome and Firefox, where the child's
pagehidelands before its aborted fetches reject. In every case the page reloaded on Back, caught up with the log and recorded gestures.notes/browser-support.mdrecords the findings.Left to decide
No served Leaf page enters Chrome's or Firefox's back/forward cache today: documents and API answers carry
Cache-Control: no-store, and Firefox also refuses a page holding a sample. TODO.md now asks whether instant Back is worth liftingno-store.Tests
test_a_firefox_departure_reports_none_of_the_loads_it_abortsholds a widget module in Firefox, navigates away and asserts no startup fault, console error or error event. It fails on the old lifetime.pageshow, being reported at the next key once however often it repeated, a startup failure queued after many reports, and dropping atpageswap/pagehide.test_a_page_cache_round_trip_keeps_the_sample_connectedhands the child a cached round trip's events and asserts the host stays presented and the child's visibility still follows scrolling. It fails without either child fix.