Skip to content

Wait for the frame that publishes the document's width after a resize - #167

Merged
max-sixty merged 2 commits into
mainfrom
fix/ci-33360981578
Aug 31, 2026
Merged

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

Conversation

@leaf-agent

@leaf-agent leaf-agent commented Aug 31, 2026 •

Copy link
Copy Markdown
Collaborator

Problem

The nightly test job failed on run 33360981578 (7f58225) with two failures.

test_the_public_catalog_is_a_visual_index_of_full_page_routes failed on the preview digest, and that one is already fixed: #164 landed the refreshed manifest right after 7f58225, the test passes at main's head, and the nightly run on 77a8681 was green.

test_a_specimen_holds_a_wide_exhibit_inside_the_column is a stale read rather than a layout regression, and it is still live. At the failing read every box on the page already measured the narrowed window — #spec 332px, the board's box 305px, main 380px — while document.documentElement.scrollWidth still answered 596, the width the document scrolled to before the window narrowed. So the assertion named the specimen's containment for something the specimen had already got right.

Chromium publishes the document's own scrolling area in the rendering update after the one that dispatches resize, and resized() returned as soon as the event reached its listeners. Measured on the specimen page narrowed to 380px, with a fresh load per probe point so no read forces the layout the next one asks about — identical across three runs of the set:

read taken at documentElement.scrollWidth
the resize handler 596
a task behind the handler 596
that update's animation frame 596
the next update's animation frame 596
a task behind that second frame 380

Solution

resized() now waits one rendering turn once the resize event has reached its listeners, with page.evaluate(ONE_FRAME) — the module's own one-turn wait, the one navigate takes after the readiness stamp. It resolves in that turn's animation-frame callback, so the caller's next read is a round trip behind it, which is the first point the measurement above shows settled.

Fixed in the shared helper rather than in the one test: document.documentElement.scrollWidth is read after a resize in five browser modules — test_render_options.py, test_render_pages.py, test_render_controls.py, test_render_widgets.py, test_render_projection.py — and all of them were reading at the same stale point. It costs one frame per resized() call.

Testing

Reproduction, bug-back, and suite
  • Reproduced on main at 77a8681: 5 failures in ~180 runs of the test as written, -n0, with the identical read (1 in the first 6).
  • The probe table above is the deterministic form of it: the stale value is reachable at four defined points and gone at the fifth, 3/3 per point.
  • After the change: 60/60 runs of test_a_specimen_holds_a_wide_exhibit_inside_the_column on d7d9fc2, the ONE_FRAME form; 30/30 on the first push's hand-rolled poll, which it replaced.
  • uv run pytest tests --run-nightly -n 2 with this change on 77a8681, main's last green head: 1569 passed, 6 skipped.
  • The same suite on this branch's base (bba885a): 14 failed, 1558 passed, 6 skipped — the same fourteen, test for test, that main's own ci run on bba885a reports. They are that commit's, not this change's, and tend-ci-fix is already running on them. test_a_specimen_holds_a_wide_exhibit_inside_the_column passed in that run.
  • tests/test_site.py::test_the_public_catalog_is_a_visual_index_of_full_page_routes passes at 77a8681, which is what confirms the digest half of the original run was Refresh public example preview manifest #164's. It is red again at bba885a, on that commit's own preview inputs, and is one of the fourteen above.

Automated fix for failed run

resized() returned as soon as the resize event reached its listeners, and the browser publishes the document's own scrolling area in the rendering update after that one. So a read of document.documentElement.scrollWidth taken behind it came back with the width the document scrolled to before the window narrowed, while every box on the page already measured the new one.

It now asks for a frame and polls the synchronous fact that the frame ran, which puts the caller's next read in a task behind it -- the first point at which the measurement settles. The frame is requested rather than awaited inside page.evaluate, so the driver's deadline still bounds the wait.

test_a_specimen_holds_a_wide_exhibit_inside_the_column failed this way on the nightly run for 7f58225, and five times in about a hundred and eighty runs locally.

@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 and the measured settled point both hold up, and the fix lands the caller's read at that point. One finding, on the shape rather than the timing.

The added block hand-rolls ONE_FRAME, the harness's own one-rendering-turn primitive, and the docstring's reason for not using it names a case FRAMES already bounds. page.evaluate(ONE_FRAME) resolves in the rAF callback of the next update — the same frame lfResizeFrames++ runs in — so the caller's next read is in a task behind it either way. It is the idiom navigate already uses in this file, and it costs no page globals and one round trip instead of two. Substituted for the added block, test_a_specimen_holds_a_wide_exhibit_inside_the_column passed 25/25 here at -n0.

The docstring says awaiting inside page.evaluate would make a stopped compositor "run the job's whole step". That is the case FRAME_DEADLINE_MS was added for: its own comment says the page-side timer keeps running through the frames that stop and "its rejected promise comes back through evaluate as the failure of the test that asked for it". What that comment leaves genuinely unbounded is a blocked main thread, which stops the deadline along with the frames — and a driver-side wait_for_function does bound that. So the shape is defensible on a reason the docstring doesn't give; as written, a later reader takes away that ONE_FRAME risks spending a whole step on a stopped compositor, which is the belief that comment block exists to correct.

Either reuse ONE_FRAME (the inline suggestion), or keep the poll and say it is the blocked-thread wedge being bought off, not the stopped compositor.

Checks run here
  • tests/test_render_options.py::test_a_specimen_holds_a_wide_exhibit_inside_the_column — 1/1 on the branch as pushed, then 25/25 with the added block replaced by page.evaluate(ONE_FRAME), -n0.
  • tests/test_render_controls.py tests/test_render_options.py -n 4 under that same substitution: 2 failed, 104 passed. Both failures (test_each_control_archetype_holds_its_neighbours_still[margin-action], test_every_ring_the_layer_draws_is_shown_whole_somewhere_in_the_corpus) reproduce with the branch's own harness restored, so they are the base's, not this change's or the substitution's.
  • The five modules the description names as reading documentElement.scrollWidth after a resize check out: test_render_options.py, test_render_pages.py, test_render_controls.py, test_render_widgets.py, test_render_projection.py.

Comment thread tests/render_harness.py Resolved
`resized` hand-rolled the one-rendering-turn wait the module already has.
`page.evaluate(ONE_FRAME)` resolves in the next update's animation-frame
callback — the same frame the hand-rolled block arranged — so the caller's
next read sits a round trip behind it either way, without two page globals
and a second round trip.

The docstring justified the poll as keeping a stopped compositor off the
job's whole step, but `FRAME_DEADLINE_MS` already bounds that case on the
page's own clock; what a driver-side wait would add is a bound on a blocked
main thread, which the module weighed and declined where `FRAMES` is
defined. Reworded to name the wait it uses instead.
@max-sixty
max-sixty merged commit 6e0c5f8 into main Aug 31, 2026
6 checks passed
@max-sixty
max-sixty deleted the fix/ci-33360981578 branch August 31, 2026 21:51
max-sixty pushed a commit that referenced this pull request Aug 31, 2026
…text (#173)

## Problem

The nightly `test` job on [run
33425820038](https://github.com/max-sixty/leaf/actions/runs/33425820038)
(afd65dd) came back `15 failed, 1561 passed`. Thirteen of the fifteen
are the failure shape that has been red on main since `bba885a`, and
#169 already fixes them; this PR is the fourteenth,
`test_render_widgets.py::test_suggestion_controls_stay_out_of_the_column`,
which is new on this run and is a real layout bug rather than the test's
timing.

A margin row that docks next to an inline perch lands **on** the line it
decides instead of under it. `.lf-margin-item` is `display:
inline-flex`, and it is `position: absolute` that blockifies it while it
hangs in the rail. Docking only swaps `position: static` back in, so the
row becomes inline-level again and joins whatever line box its perch
sits on. For a change inside a card the perch is the inline
`lf-suggestion` element itself — `externalPerch` takes `blockAt(target)
?? target`, and `TEXT_BLOCK` matches no ancestor inside `lf-card` — so
the ✓/✗ row is baseline-aligned onto the last line of the sentence it
decides.

<details><summary>Measured, at 820×900 with the panel closed</summary>

The row (`.lf-margin-item.lf-docked`, `display: inline-flex`, no
transform) and the two line boxes of the inline `#sug-in-card` it is a
sibling of:

| box | top | bottom |
| --- | --- | --- |
| `#sug-in-card` line 1 | 511.09 | 530.09 |
| **docked row** | **536.28** | **566.28** |
| `#sug-in-card` line 2 | 539.53 | 558.53 |

`#sug-in-card.contains(row)` is `false` and the row's parent is
`LF-CARD#card-heater`, so this is not overflow out of the widget — the
row is inline content sharing the widget's last line, extending above
and below the text because an inline-flex box 30px tall is
baseline-aligned against a 19px line.

</details>

## Why it went twelve commits without failing

The test read the layout while it was still moving. Closing the thread
panel gives the room back on an eased `margin-right`, and the column
re-wraps for the whole ~0.2s of it; the test clicked **Close threads**,
resized, waited for the docked class, and measured. On an unloaded
machine every read landed with body margin still at ~152px, where the
narrower column wrapped the card's sentence onto enough lines that the
row fell below it and the assertion held. A machine loaded enough to
reach the settled layout first reads the real one. The transient and
settled readings, same test, same commit:

| body margin at the read | row top | `#sug-in-card` bottom | verdict |
| --- | --- | --- | --- |
| 151.9px (transition running) | 563.47 | 557.28 | passes |
| 0px (settled) | 536.28 | 558.53 | fails |

So this is not a regression from #166, and reverting all of `skills/` to
`28b0e2b` — the commit before it — reproduces the identical `assert
536.28125 >= 558.53125`, 6/6. It is a bug the suite could not see. #167,
which adds a rendering turn to `resized()`, would have surfaced it the
same way.

## Solution

- `.lf-margin-item.lf-docked` states its own `display: flex`, so a
docked row is a line of its own wherever it comes to rest rather than
inheriting the inline level the absolute position was covering for.
`width: fit-content` keeps the box the width it had in the margin:
`.lf-margin-item` carries `pointer-events: auto`, and a block-level row
stretched to the column would take presses across a whole line the
reader may be selecting in.
- The test says the ordering it depends on: `panel_settled(page,
open=False)` before the resize, so it reads the layout the reader ends
up in. Without it the test proves the transient one, which is how it
stayed green.

Fixed in the theme rather than in `externalPerch`, because the perch is
the right one — the row belongs beside the change, not after the card —
and "docked is a line of its own" is the property every perch needs, not
just an inline one.

## Testing

- `test_suggestion_controls_stay_out_of_the_column`: 3/3 unloaded and
4/4 with the machine loaded, on the rebased head. Bug-back: with
`theme.css` alone reverted to `origin/main`, it fails on the first run,
unloaded — the ordering statement makes it deterministic in both
directions.
- Everyday suite: `740 passed, 6 skipped`.
- Complete nightly suite, run file by file: the only failures left are
the thirteen #169 covers (`test_render_controls` ×2,
`test_render_widgets` ×5, `test_render_export`,
`test_render_navigation`, `test_render_outbox`, `test_render_projection`
×2, `test_site`). No new ones, and `test_render_margin.py`,
`test_render_pages.py` and `test_render_aim.py` are green.
- `pre-commit` on both changed files: pass.

<details><summary>The fifteenth failure, left alone</summary>


`test_render_navigation.py::test_composer_marks_the_passage_instead_of_quoting_it`
failed once on this run (`assert 'specimen' in ''`) and I could not
reproduce it: 5 runs at `-n0`, 12 more with the machine loaded, and 3
whole-file runs at `-n 2`, all green, including on the rebased head. It
stays unclassified rather than fixed — a guess at a wait for a failure
that reproduces nowhere is how a test stops proving anything.

</details>

---
Automated fix for [failed
run](https://github.com/max-sixty/leaf/actions/runs/33425820038)

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