Skip to content

Arm request interception only on the pages a test routes - #3937

Merged
max-sixty merged 3 commits into
mainfrom
lazy-interception-arm
Oct 25, 2026
Merged

max-sixty merged 3 commits into
mainfrom
lazy-interception-arm

Conversation

@max-sixty

Copy link
Copy Markdown
Owner

Every page the suite made armed request interception before it navigated (arm_interception in readable), so that a route a test adds later catches the next request (#231). While a page has any route, Playwright enables Fetch on * and turns Chromium's HTTP cache off (_updateProtocolRequestInterceptionForSession in the driver), so every request the page makes waits for a round trip through the driver. Most pages are never routed.

A page the suite makes now arms itself when something first routes it or its context, ahead of that route:

  • Before navigation, nothing is in flight, so the arm is registered as before. held_events and primed keep holding the first navigation's requests.
  • After navigation, the arm proves interception is on before the test's route is added. The page fetches /favicon.ico?lf-interception-armed=N, which the arm answers with 204, and the page fetches again until one is caught. A probe that escapes reaches the page server's quiet favicon.ico, so it leaves nothing in the console.
  • A page made in a context that has a route arms as it is made. unroute_all takes the arm with it, so the next route arms again.

The arm stays for the page's life, as before, so the route list never empties under requests in flight.

Unrouted pages now run with Chromium's HTTP cache on, as a user's browser does. The page server marks revision resources immutable and everything else no-cache, so a reload revalidates against the server rather than reusing stale state.

Where an opening's time goes

Measured on one plain test page (SETTLED_PAGE) on an M-series Mac, -n0, median of 9 openings at load averages 7–9 (October 25 2026):

Phase Wall
serve: page loan from the pool, page stamp ~55 ms (Python)
New context and page, readable's init scripts ~40 ms
goto to load (document 9 ms, DOMContentLoaded 98 ms, 48 requests, 2.9 MB) ~95 ms
load to wait_until_ready returning (upgraded at 170 ms, presented at 178 ms) ~110 ms
one_frame after readiness ~18 ms

The renderer's main thread was busy 117 ms of that (script 31 ms, style 21 ms, layout 5 ms) with no shift watch installed, and 137 ms with it.

CPU per opening across every process, 20 openings per round, five interleaved rounds, load averages 11–14, median:

Process Base This change
Chrome renderer 250 ms 250 ms
Chrome browser process 72 ms 53 ms
Chrome network and GPU processes 43 ms 35 ms
Playwright driver 40 ms 36 ms
Test process (page server threads and Playwright client) 169 ms 171 ms
Total 573 ms 546 ms

Every round was lower with this change (base 544–599 ms, this change 518–592 ms).

Whole files

tests/browser/test_render_options.py, test_render_reactions.py, widgets/test_tabs.py, navigation/test_panes.py and test_render_floating_panel.py (300 tests, -n 3), three interleaved rounds, CPU from /usr/bin/time over the whole process tree:

CPU Wall
Base 366.4, 366.6, 375.9 s 106.2, 105.6, 108.0 s
This change 357.7, 350.9, 356.9 s 104.9, 102.7, 104.4 s

That is 2.6% less CPU and 1.7% less wall time (load averages 11–20). CI's runner is CPU-bound with three workers on four cores, so the saving there should track the CPU column; main's next push run will show it.

Coverage

  • The route-heavy files pass on this change: test_render_outbox.py, drafts/test_sending.py, drafts/test_shared_drafts.py, startup/test_freshness.py, startup/test_readiness.py, startup/test_hosting.py, startup/test_modules.py, widgets/test_tabs.py, projection/test_thread_replies.py, test_render_application_boundary.py (234 tests), and test_render_gate.py, startup/test_versions.py, projection/test_live_versions.py, drafts/test_revisions.py, widgets/test_playgrounds.py, test_render_commands.py, test_render_pages.py, smoke/test_smoke.py, test_widget_quality.py (279 tests and 31 subtests).
  • A route that misses its request fails its test, since every held route is followed by a wait for the held request (holding) that times out. The race Arm request interception when a test page is made #231 found therefore couldn't pass a test vacuously; it made it flaky.
  • I couldn't reproduce that race with Playwright 1.63. A route registered after navigation, followed at once by a fetch, caught it in 80 of 80 runs with no arm at all, including 60 under --cpu-throttle 8 at -n 3. The probe keeps the guarantee either way, and costs about 5 ms on a page that routes.
  • Bug-back for the probe: with ARM_PROBE changed to a pattern the probe never matches, a late page.route raises request interception never caught a probe at the deadline, and the escaped probes leave the browser fixture clean.
  • test_another_key_or_a_scroll_away_puts_the_shown_gesture_back_to_showing (test_render_outbox.py) times out intermittently at -n 3 on main too (two failures in four runs of the file on the merge base), so a failure there is inherited.

This was written by Claude Code on behalf of max-sixty

@max-sixty
max-sixty merged commit 6a48ab3 into main Oct 25, 2026
3 checks passed
@max-sixty
max-sixty deleted the lazy-interception-arm branch October 25, 2026 15:16
leaf-agent added a commit that referenced this pull request Oct 25, 2026
The offline export checks now distinguish captured `blob:` resource
loads from requests outside the exported file, matching the existing
historical CSS export check. The runtime already builds these URLs from
resource bodies embedded in the export; loading them does not contact a
host.

[#3937](#3937) removed
unconditional request interception from unrouted test pages. That
exposed the blob requests to Playwright's request listener, so two
export tests in [run
40207154799](https://github.com/max-sixty/leaf/actions/runs/40207154799)
reported local resources as external. This preserves that change's
intent and the export's offline behavior.

Both claimed tests failed on current main with the run's blob URL
diagnostics and pass after this change. As a causal control, adding an
unrelated no-op route made the original assertions pass too. The
preceding run 40204656921's junit records both passing.

Co-authored-by: leaf-agent <[email protected]>
leaf-agent added a commit that referenced this pull request Oct 27, 2026
The offline playground export test counted embedded `blob:` resource
loads as requests outside the exported file. Classify them as local
alongside `data:` resources, matching the other export checks corrected
in #3974. Requests to external hosts still fail the assertion; the three
playgrounds still exercise their offline controls and disabled
submission.

#3937 removed unconditional request interception from unrouted test
pages, exposing these loads to the request listener. This preserves that
change's intent and changes no exported behavior.

All three parametrized cases fail on current main with the reported blob
diagnostics and pass with this correction (`uv run pytest
tests/journeys/test_render_export.py::test_playground_examples_keep_their_offline_interaction_mode
-q -n0`: 3 passed). The preceding scheduled run 40186470627 records
these cases passing; run 40311120380 records the reported failures on
Linux and macOS.

Closes #4242 — automated triage

Co-authored-by: leaf-agent <[email protected]>
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