Skip to content

Hold the gate's own state read until the late action is in the log - #75

Merged
max-sixty merged 2 commits into
mainfrom
fix/ci-33053132232
Aug 27, 2026
Merged

max-sixty merged 2 commits into
mainfrom
fix/ci-33053132232

Conversation

@leaf-agent

Copy link
Copy Markdown
Collaborator

Problem

ci on main is red at tests/test_render_projection.py::test_the_render_gate_reads_a_page_that_has_finished_arriving, which reports the drift widget's words drawn over the paragraph below it in both [light] and [print]. The test builds a window — the action reaches the log after the page's first read has answered, so the gate must see a log with the action in it, count one touched widget, and wait for the caught-up stamp before reading anything. That window used to close on the far side of page.goto(url, wait_until="networkidle"): the gate's navigation waited out the page's first poll and the append the test hangs off it, so by the time the gate read /api/state for itself the action was always in.

ad8bf50 moved the gate to wait_until="load", because a page holding a news stream open is never network-idle. Nothing orders the two reads now. The page stamps itself upgraded in the same breath as it starts its first read and never awaits it, so the gate is free to reach /api/state while that read is still in flight — it then counts an empty log, waits for nothing, and reads the page mid-move. Under CI's load that is what happened.

Solution

State the window on both sides in the test's own server, rather than resting on which request the machine happens to answer first. The action still goes in behind the page's first read (told from the gate's by the Referer a page fetch carries and an APIRequestContext does not); the gate's own read is now held until it has. The hold is bounded at 10s, far inside the gate's 30s deadline for a served document, so a runtime that stopped reading state at startup is named by the premise assertion instead of by a gate whose server appeared to stop answering.

The premise assertion also moves ahead of the gate's verdict: a verdict on a window that never opened says nothing, and reading it as an overlap failure is what made this failure look like a rendering fault.

The gate itself is unchanged. Its contract is the log as it stands at its own read, and it keeps that; only the test's arrangement rested on an ordering ad8bf50 removed.

Testing

Reproduction and runs

The failure is a load-shaped race, so it was reproduced by giving the page's first /api/state the load: a time.sleep(0.4) in the handler before super().do_GET() for that one request. On the old test that fails on the first try with exactly CI's four [light]/[print] overlap lines. The instrumented request log shows the mechanism directly — the gate's read arrives 21 ms after the page's, and 600 ms before the append:

STATE referer=True  landed=False  t=…82.787   # the page's first read
STATE referer=False landed=False  t=…82.808   # the gate's own read — log still empty
APPENDED                          t=…83.404

With the fix in place the same delay passes, and so does a 2s one, which is the difference between an arrangement and a margin.

  • tests/test_render_projection.py::test_the_render_gate_reads_a_page_that_has_finished_arriving — 5 consecutive runs, all green
  • tests/test_render_projection.py --run-nightly — 72 passed
  • tests/test_render_gate.py tests/test_render_startup.py --run-nightly — 107 passed
  • ruff check / ruff format --check at the pinned 0.16.1 — clean

Automated fix for failed run

The render gate used to reach /api/state behind a networkidle navigation,
which waited out the page's first poll and the append that rode on it. The
news stream leaves the network never idle, so the gate now navigates on
load and can reach /api/state while the page's first read is still in
flight — whereupon it counts an empty log, waits for nothing, and reads a
page 120px mid-move. That is what CI reported at run 33053132232.

The window this test constructs is now stated on both sides: the action
still goes in behind the page's first read, and the gate's own read is
held until it has. A 0.4s delay on the page's read reproduces the CI
failure exactly on the old test and passes on the new one at 2s, so the
ordering is an arrangement rather than a margin.

The premise assertion moves ahead of the gate's verdict, since a window
that never opened makes that verdict say nothing.

@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.

One observation on the hold's bound. The arrangement itself checks out: LeafHTTPServer subclasses ThreadingHTTPServer, so holding the gate's handler cannot starve the page's read that releases it; /api/news is a distinct path, so the held-open news stream never trips the /api/state predicate; and 10s sits inside SERVED_TIMEOUT_MS as claimed.

arrived.wait(10) discards its result, so the bound has two failure stories and only one of them is named. If the page's read never happens, landed stays empty and the premise assertion says exactly that — the case the comment above the wait describes. If the page's read merely lands after the bound expires, landed is populated, the premise assertion passes, and the gate — which by then read an empty log, found touched empty, skipped the lf-applied wait, and passed the MOVING wait because the move had not started — reports the drift widget's words over the paragraph below. That is the same four [light]/[print] overlap lines this PR set out to stop misreading as a rendering fault, reappearing under contention instead of under the ordering ad8bf50 removed. A single request stalling past 10s is within the contention envelope running-tend describes, so it is worth a name rather than a re-derivation.

Recording the wait's result costs two lines and turns that case into its own sentence. Suggestions inline.

Comment thread tests/test_render_projection.py Resolved
Comment thread tests/test_render_projection.py Resolved
Comment thread tests/test_render_projection.py Resolved
@max-sixty
max-sixty enabled auto-merge (squash) August 27, 2026 09:29
@max-sixty
max-sixty merged commit 44d1ac7 into main Aug 27, 2026
7 checks passed
@max-sixty
max-sixty deleted the fix/ci-33053132232 branch August 27, 2026 10:00
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