Repository navigation
Measure a settled scroll in frames the glide would have moved on - #876
Conversation
One gesture's travel is two moves: scrollRevealedElement places the element's nested scrollports at once and then glides the scroller that owns it to the centring position, so the page holds still for a frame or more between them. The suite read that pause as the arrival. Three copies of one idle-window predicate asked whether the scroll number had held for 50ms — 0ms and 400ms at two call sites — and a window measured in milliseconds fits inside a frame gap as soon as the machine's frames are further apart than the window. Replace all three with one scroll_settled helper that counts animation frames. The compositor advances a glide on every frame it runs, so a still frame can only be one the glide has not started on, and a loaded machine takes fewer frames through the pause rather than more. The helper owns its own record, so the three call sites that deleted or seeded the old predicate's globals before their own wait could mean anything no longer have anything to reset, and the one that held for 400ms to outlast a conversation refresh now reads behind the card that refresh writes.
leaf-agent
left a comment
There was a problem hiding this comment.
scroll_settled takes over three of the five copies of this predicate. Two are still live in tests/test_render_controls.py: test_covering_threads_keeps_the_reader_and_their_work_inside and test_a_covering_tray_uses_the_same_auxiliary_modality_boundary each seed window.__lfAuxiliaryScroll and window.__lfAuxiliaryScrollSince and then hold performance.now() - window.__lfAuxiliaryScrollSince > 50 over a nested scrollport — .lf-threads and .lf-asks-panel .lf-tray-list. That is the shape scroller= was added for, and leaving it means the description's "there is nothing left for a caller to reset" is not yet true, and the rule this PR writes into tests/CLAUDE.md — "Do not measure that hold in milliseconds" — is broken two files away from where it is stated.
It is not cleanup. Each of those waits gates the same kind of negative assertion the nightly failure was: the document must not have moved while the auxiliary surface scrolled. A 50ms window that answers inside the glide's pause reads the document before the move it is meant to forbid, and the test passes for the wrong reason rather than failing. The conversion is one line each, and I am pushing it to this branch.
What the two waits become, and the bug-back on the restructured anchors test
Both become a call on the scroller they were already watching:
scroll_settled(page, scroller=".lf-threads")
scroll_settled(page, scroller=".lf-asks-panel .lf-tray-list")tests/test_render_controls.py passes whole after the conversion — 92 tests, 5m54s, default parallelism — and pre-commit is clean over the file.
Separately, test_a_press_on_a_passage_opens_its_thread_where_it_stands is the one call site whose wait this PR rewrites rather than translates: a 400ms hold chosen in #809 to outlast the conversation refresh becomes expect([data-lf-thread]).to_be_in_viewport(ratio=1) plus a four-frame hold, which is a shorter wait for the same negative assertion. Bugging the behaviour back — travel: false to travel: true on the mark-press call to openPageThread in skills/leaf/assets/runtime/composing/surface.js — still fails it, assert 738 == 457 ± 1, so the card's arrival is a real edge behind the refresh and the guard #809 added is intact.
`test_covering_threads_keeps_the_reader_and_their_work_inside` and `test_a_covering_tray_uses_the_same_auxiliary_modality_boundary` each seeded `__lfAuxiliaryScroll` and held it for 50ms over a nested scrollport. Both gate the same negative assertion the nightly failure was — the document must not move while the auxiliary surface scrolls — so a window that answers inside the glide's pause reads the document before the move it forbids and passes for the wrong reason. `scroll_settled`'s `scroller=` is what those two call sites wanted, and with them converted nothing is left for a caller to reset and the rule `tests/CLAUDE.md` now states holds everywhere the suite waits on a scroll.
`ci` on `main` went red at f3de402 (#881): [`lint` and `test` passed and the complete suite in `nightly` failed on seven cases](https://github.com/max-sixty/leaf/actions/runs/35616173899). Six are #884's, unchanged from [the run before it](https://github.com/max-sixty/leaf/actions/runs/35615354769) and still open there. The seventh is this one, and it is not #881's: that commit moves the Pierre diff bundle and its pin, and the binding-badge fixture draws no diff. `test_ask_binding_badges_do_not_cover_their_key_line` failed with the shape #876 repaired — the badge the test scrolls one pixel into the shortcut bar's band still worn, count 2 rather than 1, stable across all fourteen polls. ## What the wait could not see Stillness is half a reading. A page that has not begun an effect is indistinguishable from one that finished it when the only evidence is the scroll number holding still, which `tests/CLAUDE.md` already states under **A wait consumes a fact the system states**. [`goToAskNow`](https://github.com/max-sixty/leaf/blob/cf0c6cf185346c5e68a392b176578c4d1f4d0466/skills/leaf/assets/runtime/asks/view.js#L1115) awaits `materializeAsk` and one or two `reveal`s before it issues any travel, so `scroll_settled` called straight after the press can count its three still frames on a page the walk has not moved yet. The test then measures its geometry where the walk began, issues its own `scrollTo` from there, and the travel lands on top of it — the badge back above the bar, legitimately kept, for the rest of the assertion's timeout. #876 changed the unit and not the ordering, and the measurement says it addressed the smaller window. On the ask walk here the glide pause is nought to one frame and holds at nought under `Emulation.setCPUThrottlingRate`, because the compositor starts the glide on the frame after the instant move whatever the main thread is doing. The window that grows under load is the asynchronous gesture before the travel is issued at all, which is main-thread work; no count of frames bounds it, so raising the count would have been the next wording rather than the fix. ## What this changes The walk arrives and then travels, in that order and in one task — [`arriveAt`](https://github.com/max-sixty/leaf/blob/cf0c6cf185346c5e68a392b176578c4d1f4d0466/skills/leaf/assets/runtime/asks/view.js#L936) focuses, `scrollToElement` follows with no await between — so the arrival is a fact the stillness can be read behind. Each press in this test now waits on its ask's focus before `scroll_settled`. That is the rule the rest of the suite already keeps. This was the only one of the suite's 38 `scroll_settled` call sites that read stillness with nothing stated before it: every other waits on a moved scroll number, a painted `data-lf-ask`, a URL, `to_be_in_viewport`, or the focus. So the durable half of the change is in the helper's own contract and in `tests/CLAUDE.md`, which said the helper "waits for a scroller to have arrived" — a promise it cannot keep — and now says it waits for one to have stopped and is asked behind the fact that it started. The frames-versus-milliseconds reasoning #876 established stays; what it is for is now named as the glide, not the gesture. ## Verification The mechanism reproduces on demand: with the stillness wait allowed to answer early (`frames=0`), the page ends at the travel's own position rather than the test's, with the badge worn and the count stable at 2 — the run's failure exactly. The two windows were measured separately on the ask walk at throttling rates 1, 2, 4 and 10; the glide pause reads 0 frames at every rate and the press-to-travel window is the one that carries the slack. `tests/test_render_widgets.py --run-nightly` is 179 passed, `npm run test:runtime` 28 passed, and `pre-commit run --all-files` clean. The everyday suite is 1195 passed beside six cases that fail in this sandbox and fail identically at the merge base — an `AF_UNIX` socket it refuses, a umask it does not grant, and a Node bundle step it cannot run. ## What this does not do The six Web Awesome cases stay with #884; nothing here touches them, and `nightly` stays red until that merges. `scroll_settled` keeps its signature: the ambiguity it carries is not one the helper can settle from outside the page — a gesture that legitimately moves nothing looks the same as one that has not started — so the caller consuming a stated fact is the fix rather than a way around it. <details><summary>The failing cases and where each was read</summary> From [the `nightly` job at f3de402](https://github.com/max-sixty/leaf/actions/runs/35616173899): ``` FAILED tests/test_render_widgets.py::test_ask_binding_badges_do_not_cover_their_key_line Locator expected to have count '1' / Actual value: 2 14 × locator resolved to 2 elements # this change FAILED tests/test_site.py::test_the_published_notification_example_runs_its_authored_module@site FAILED tests/test_site.py::test_published_visual_evidence_loads_from_its_page@site FAILED tests/test_render_controls.py::test_every_base_corpus_tab_stop_has_a_visible_focus_indicator FAILED tests/test_render_controls.py::test_every_ring_the_layer_draws_is_shown_whole_somewhere_in_the_corpus FAILED tests/test_render_projection.py::test_visual_review_gallery_gives_a_laptop_to_the_evidence FAILED tests/test_render_margin.py::test_agent_status_leaves_the_margin_transcript_where_the_reader_scrolled_it # the six in #884 ``` `test_render_export.py::test_a_copy_speaks_reader_origin_after_live_map_is_removed`, the seventh in the 725fca7 run, passed here — consistent with #884 reading it as a latent race rather than #878's. The badge test passed 18 consecutive local runs before this change, including ten under six busy cores, so the window is not one an idle machine reaches. What reproduces it is letting the wait answer early, which is what the loaded runner does. </details> Co-authored-by: leaf-agent <[email protected]>
The nightly suite on run 35527368685 failed on
test_ask_binding_badges_do_not_cover_their_key_line— the badge the test scrolls one pixel into the shortcut bar's band was still worn, count 2 rather than 1, stable across all fourteen polls. The press was fine and the placement pass was fine; the test measured a page that had not finished moving. This replaces the wait that let it.One gesture's travel is two moves.
scrollRevealedElementplaces the element's nested scrollports at once and then glides the scroller that owns it to the centring position, so between the instant move and the glide's first step the page stands still for a rendering frame or more. Three copies of one idle-window predicate —SCROLL_SETTLED,SCROLL_STILL, and an inline third for the board's scrollport — asked only whether the scroll number had held for 50ms, and answered with the place the instant move left as soon as the machine's frames were further apart than that window. The test then measured its geometry there, issued its ownscrollTofrom it, and the glide landed on top of it: the badge ends up back above the bar, legitimately kept, for the rest of the assertion's timeout.scroll_settledcounts animation frames instead. The compositor advances a glide on every frame it runs, independently of the main thread, so a still frame can only be one the glide has not started on — and a loaded machine takes fewer frames through the pause rather than more, which is the opposite of how the millisecond window behaves. Playwright pollswait_for_functiononrequestAnimationFrame, so one evaluation is one frame.The unit was the cause, and the call sites showed it: the same predicate was asked with three different holds (0ms, 50ms, 400ms), one caller deleted its globals and two seeded them before their own wait could mean anything, and the two copies shared a
window.__lfScrollSincebetween them. The helper now owns that record, so there is nothing left for a caller to reset, and the 400ms hold that was outlasting a conversation refresh reads behind the card that refresh writes instead — the edge a travel would have been asked for behind. #13 established the other half of this rule, that stillness is only asked after the movement itself is observed; those call sites keep theirSCROLLEDwait unchanged.Measurement: both predicates against the glide they must outlast
Both predicates evaluated on the same animation frames, next to the scroll trace, for the first
apress on the binding-badge page underEmulation.setCPUThrottlingRate.msis the 50ms window asSCROLL_SETTLEDhad it;framesis the new count;settledis where the travel actually ended.94 is where the instant move left the page; 144 is where the glide put it. Unthrottled the two agree, which is why this held on every desk. At any slowdown the millisecond window answers 94 and the frame count answers 144. Unthrottled, the instant move reports at 9ms and the glide's first step at 43ms, so a 50ms window already spans the pause before the runner drops a single frame.
Verified: the failing test, the other fourteen in
test_render_widgets.pythat wait on a scroll, and the nine acrosstest_render_aim.py,test_render_anchors.py,test_render_commands.py,test_render_controls.py,test_render_drafts.pyandtest_render_projection.py— 30 tests, all passing. The everyday gate passes apart from five cases this sandbox owns (/tmpis read-only here, and the umask case reads the sandbox's); each of those fails identically on f7ef2ef with the branch stashed.pre-commitis clean over the changed files.