Skip to content

Keep the render gate's request interception on for the page's whole life - #631

Merged
max-sixty merged 2 commits into
mainfrom
fix/issue-629
Sep 12, 2026
Merged

max-sixty merged 2 commits into
mainfrom
fix/issue-629

Conversation

@leaf-agent

@leaf-agent leaf-agent commented Sep 12, 2026 •

Copy link
Copy Markdown
Collaborator

The teardown of request interception lands inside the module burst

start_with_pre_upgrade_proof held the Leaf entry through page.route("**/leaf.js", hold_entry, times=1). Playwright removes a spent handler from the page's route list and, when that empties the list, sends setNetworkInterceptionPatterns([]) — which turns Chromium's Fetch domain off. A times=1 handler is spent when the held route resolves, so interception came down at exactly the moment held[0].continue_() delivered the entry and the module layer began asking for a hundred-odd files. Requests caught in that transition are lost: the document stays at readyState: "interactive", the load event never fires, and nothing is written to the console.

That accounts for both endings #629 records. A request the transition swallows leaves a module named in flight; one whose completion the driver loses leaves nothing in flight with the load event still pending.

Disabling interception really does act on requests already paused in the browser, which is the direct evidence for the mechanism: unrouting before releasing the entry makes Chromium continue the held route itself, and Playwright's own continue_() then fails with Route is already handled! on every attempt.

The hold outlives the entry, and the page keeps interception for its whole life

Two changes, because the first alone moves the transition rather than removing it.

Dropping times=1 keeps the route list non-empty across the load wait, so no interception update is sent while the page is loading its layer. The handler passes a second entry request through rather than leaving it standing, since a hold nothing releases would be a wait with no end.

That leaves page.unroute("**/leaf.js", hold_entry) in the finally, which is now the first real teardown the gate performs — before this branch it removed a handler Playwright had already expired, so it sent nothing. A loaded document is not an idle one: instrumenting that call on the corpus page, /api/state, /registry.json and /icon.svg are still open when it runs. /api/state is not load-blocking and is the read the runtime needs to reach upgraded, so losing it there is the gate's other silent ending — the widget layer never finished upgrading — and no console message explains why — rather than #629's. So each page the gate opens is armed on a pattern nothing ever asks for, and its route list never empties at all.

arm_interception in tests/render_harness.py already did this for the pages a test opens, for the other end of the same fact: a route registered on an unarmed page can let a request escape while Chromium is still arming. The gate opened its own pages and had no equivalent. The harness now takes the arm from the gate rather than declaring a second one.

Measurement

Interleaved, one attempt per arm in rotation on one idle four-core Linux box, driving start_with_pre_upgrade_proof against the served corpus page with a 10s load wait — the boundary that reproduces the failure without the rest of the gate around it:

current (times=1)             5 failed / 60
route held past the load      0 failed / 60
unroute() after the release   1 failed / 60

A separate interleaved pair established that interception is what is implicated at all: with no route registered, and so no interception on the page, 0 failed / 50 against 5 failed / 50 for the code as it stands.

The failures print what #629 describes, e.g. no load (readyState=interactive); asking=['/vendor/jsdiff.esm.js'] and no load (readyState=interactive); asking=nothing.

The unroute() arm is the issue's own next step — releasing and unrouting before the load wait. It helps, because it makes the teardown an awaited call rather than a floating task, but it does not remove it from the burst, so the failure survives. That it survives an awaited update is also why awaiting the one in the finally is not enough on its own, and why the arm is there.

Testing

Two tests state the orderings rather than sampling the race.

test_the_pre_upgrade_proof_holds_its_entry_route_past_the_load_event: one entry route registered with no times limit, and unroute after the load wait rather than before it. Against the source reverted it reads back [('**/leaf.js', {'times': 1})] and fails.

test_the_render_gate_arms_every_page_it_opens_against_an_empty_route_list: every page the gate opens is routed on the arm before any other route, and never unrouted from it. Against the arming reverted it reads back [('route', '**/leaf.js'), ('unroute', '**/leaf.js')] and fails.

  • uv run pytest --run-nightly -n2 tests/test_render_gate.py — 103 passed.
  • uv run pytest tests — the everyday suite passes apart from four cases this sandbox cannot run (read-only /tmp, umask, the IPv6 wildcard bind), none of them in this area.
  • uv run pytest --run-nightly -n0 "tests/test_render_gate.py::test_page_fixture_renders[corpus]" — 6 consecutive passes. On this box before the change the same selection failed 14 of 97 attempts at the scheme boundary, which is four attempts per corpus run.
  • uv run pre-commit run --files on the three files.

Closes #629 — automated triage

The pre-upgrade proof held the Leaf entry through a single-shot Playwright
route. Playwright drops a spent handler and turns the page's request
interception off with it, so interception went down at the moment the entry
was released -- the moment the module layer starts its burst -- and requests
caught in that transition were lost. The document then stopped at
interactive with no load event and no console entry.

The handler now stays registered across the load wait and passes a later
entry request through, so the one teardown happens on a document that has
already loaded.

Closes #629

@leaf-agent leaf-agent left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

The diagnosis holds — I read Playwright's own _on_route to confirm it: a will_expire handler is pulled out of page._routes before it is invoked, and the finally that follows fires an unawaited asyncio.create_task(_update_interception_patterns()) the moment the list empties. That is the floating teardown landing inside the burst, exactly as described. I also reproduced the test's discrimination: reverted to times=1 it reads back [('**/leaf.js', {'times': 1})] and fails. uv run pytest --run-nightly -n2 tests/test_render_gate.py is 102 passed here.

The finding is that the teardown is relocated rather than removed, and the docstring's reason for calling the new site safe does not hold. page.unroute("**/leaf.js", hold_entry) in the finally is now the first real teardown this function performs — before the change it removed a handler Playwright had already expired, so it sent nothing. It now empties the route list for real, and a loaded document is not an idle one. Instrumenting page.unroute on the corpus page, the requests open at the moment it runs are:

/api/state, /icon.svg, /registry.json

/api/state is the read the runtime needs to reach upgraded, and it is not load-blocking, so the load event fires with it still in flight. A request lost in this transition therefore does not reproduce #629's signature — it produces the gate's other silent ending, the widget layer never finished upgrading — and no console message explains why. The PR's own measurement is consistent with a smaller exposure rather than none: the unroute()-after-release arm still failed 1 in 60, and that arm is an awaited call, so awaiting the update is not what makes a transition safe.

The remedy is the one the PR body already identifies and then does not take. arm_interception in tests/render_harness.py registers NEVER_ASKED_FOR = "**/__leaf_arms_interception__" so a page's route list is never empty and no disable is ever sent; the gate's page, made by browser.new_page(viewport=..., color_scheme=...) in _render_scheme, has no equivalent. Arming it there keeps _routes non-empty through both the expiry and the unroute, which removes the class instead of moving it. I'll push that as an additive commit, leaving this PR's route lifetime intact.

Worth naming without acting on it: with the page armed, times=1's expiry toggles nothing, so the route-lifetime change and the pass-through branch in hold_entry would both become unnecessary. Whether to collapse back to the single-shot hold is a call about which mechanism the gate should rest on, and this PR is the one with the interleaved measurement behind it, so I've left it alone.

Separately, #630 rewrites the same statements in start_with_pre_upgrade_proof — the docstring and the page.route line — so whichever lands second needs a rebase rather than a merge.

Keeping the entry route registered past the load event moves the
interception teardown out of the module burst, but it does not remove it:
`page.unroute` in the `finally` is now the first real teardown the gate
performs — before this branch it removed a handler Playwright had already
expired, so it sent nothing. Measured on the corpus page, `/api/state`,
`/registry.json` and `/icon.svg` are still open at that call, and losing
the first is a page that never reaches `upgraded` with nothing on the
console to say why.

So the gate arms each page it opens on a pattern nothing asks for, the way
the suite's own harness already does, and its route list never empties at
all. The harness now takes that arm from the gate rather than declaring a
second one.
@leaf-agent leaf-agent changed the title Keep the render gate's entry route registered until the document loads Keep the render gate's request interception on for the page's whole life Sep 12, 2026
@max-sixty
max-sixty merged commit 61378ed into main Sep 12, 2026
4 checks passed
@max-sixty
max-sixty deleted the fix/issue-629 branch September 12, 2026 16:13
max-sixty pushed a commit that referenced this pull request Sep 12, 2026
… give it (#632)

## One window, two allocations


`test_published_workspaces_keep_their_allocation_under_site_context[live-progress]`
failed in the nightly run
([34678426457](https://github.com/max-sixty/leaf/actions/runs/34678426457))
reading `flow` where the published example is meant to hold its bounded
desk. It reproduces here at the size the test drives, and the cause is
not the site note's height on Linux fonts — it is that the same window
allocates two different ways depending on which window the reader came
from.

`fitRootReadingElement` decides posture by comparing the available box
against the minimum the root reports, and that minimum is a reading of
the root's own live layout. In flow the root stands in the reading
measure — 720px inside a 1200px window — while bounded would give it the
full 1152px. Furniture that wraps is taller in the narrow one, so a root
in flow reports a minimum for a layout the bounded posture would never
have. Measured on the published Live Progress page at 1200×900:

| Arrived from | Furniture read | Minimum height | Available | Posture |
| --- | --- | --- | --- | --- |
| a 1100-tall window | 200.3px at 1152 wide | 760.3 | 793 | `bounded` |
| loading at 900 | 245.2px at 720 wide | 805.2 | 793 | `flow` |

Flow is self-confirming: every reading taken from it is the flow reading
again, so the reader who lands there cannot resize out of it. The
available *width* in the same function is already computed as the box
bounded would allocate — `body` width less `main`'s padding, not the
measure column the root currently occupies — so the height term was the
one reading that still described the posture in force rather than the
one under decision.

## The reading is taken in the box under decision

`readMinimumAt` holds the root at that width while the minimum is read,
and restores it in the same task, so nothing paints between. That leaves
the whole subtree — a root's own furniture and any nested pane's — laid
out at the bounded width for the reading, rather than each `minimumSize`
implementation having to correct for its current posture.

It also holds the root's current height across the reading. Furniture
that grows shorter at the wider width shortens the document, and
Chromium clamps a scrolled reader's position to the page it measured
rather than the one it restores: without the height held, a reader
scrolled to the end of a flow page is moved 200px back up its page on
the next layout signal.

The added work is one forced layout per posture decision, on the pages
that carry a root workspace only; `choosePosture` already forced one
through `minimumSize`'s own `getComputedStyle` and box reads. The work
before presentation is unchanged, read from
`scripts/verify-site-local.sh` on this PR's [`test`
job](https://github.com/max-sixty/leaf/actions/runs/34688543416) against
[main's](https://github.com/max-sixty/leaf/actions/runs/34680715180):

| Route | Base, by presentation | This change |
| --- | --- | --- |
| `/` | 12 JS / 217 KiB, 16 code / 406 KiB, 23 total / 868 KiB |
identical |
| `/examples/triage-board/` | 11 JS / 191 KiB, 15 code / 380 KiB, 19
total / 383 KiB | 19 total / 384 KiB |
| `/examples/feature-gallery/versions/v1.html` | 30 JS / 384 KiB, 34
code / 572 KiB, 40 total / 720 KiB | identical |

No request count moves anywhere, and the one kilobyte is document bytes
rather than a resource. Elapsed times move in both directions between
the two runs and are diagnostic only.

## Verification

-
`tests/test_render_widgets.py::test_a_root_posture_is_the_window_it_stands_in_and_not_the_one_it_came_from`
walks a sweep of window heights down from a tall window and opens each
of them fresh, and holds the two routes to the same answer. Its fixture
wraps by geometry rather than by text — four fixed badges that stand on
one row in a bounded allocation and two in the reading measure — so the
divergence does not depend on a platform's font metrics, and a positive
control fails the test if they ever stop wrapping. Against the runtime
reverted it reports `{500: 'flow', 600: 'flow'}` where the walk down
reports `bounded`.
-
`tests/test_render_widgets.py::test_reading_a_root_minimum_leaves_the_reader_where_they_had_scrolled_to`
holds the clamp above. With the height pin removed it reads back 2603
where the reader left 2803.
- `uv run pytest tests/test_site.py --run-nightly` — 45 passed,
including the failing node.
- `uv run pytest tests/test_render_widgets.py --run-nightly` — 155
passed.
- `uv run pytest tests/test_render_gate.py --run-nightly` — 101 passed.
- `uv run pytest tests` — 1028 passed, with the four failures #628
documents as unrunnable in an agent sandbox (IPv6 wildcard, read-only
`/tmp` ×2, umask).
- `uv run pre-commit run --files …` — passed.
- `scripts/verify-site-local.sh` did not run: the sandbox has no access
to the Docker daemon Wrangler needs for the page container. CI's `test`
job runs it on this PR.

## The run's other failure is #631's

`test_page_fixture_renders[notification-playground]` failed in the same
run on `the runtime never injected its banner`. That is #629's startup
stall, and #631 is open with the diagnosis and fix — request
interception coming down inside the module burst. It reproduced here
once in one full `test_render_gate.py` run (on a different node and
viewport, `[dark] … at 1200x900`) and cleared on the next, which is the
rate #631 measures. Nothing in this change touches it.

---------

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.

ci-fix: the corpus render sweep fails on a load event that never fires

2 participants