Skip to content

test: credit a margin row's lag when its anchor scrolls again before the row catches up - #6856

Merged
leaf-agent merged 2 commits into
mainfrom
fix/issue-6744-anchor-lag
Nov 23, 2026
Merged

leaf-agent merged 2 commits into
mainfrom
fix/issue-6744-anchor-lag

Conversation

@leaf-agent

@leaf-agent leaf-agent commented Nov 23, 2026 •

Copy link
Copy Markdown
Collaborator

The shift watch reported the root-tabs journey's margin marker as moving without input when the page scrolled twice in a row. The marker's carrier is anchored to the document, and Chrome moves an anchored box a frame after its anchor scrolls, which #6763 taught the watch to credit. That credit only applied when the anchor was read exactly at one of the frames the watch compares. test_root_tabs_switch_views_without_moving_the_strip_and_follow_history calls scrollIntoView and then scrollBy(-40) from two scripts. The marker caught up to the first scroll in the reading that already found the document moved by the second, and that reading fell between the compared frames. So the watch credited only the 582px the document had settled at, against the marker's 622px, and reported the marker as moving without input. The marker's painted position never jumped.

laggedTravel now also lets each end of a comparison pair the node with the anchor as it stood one reading before the reading that last placed the node, as well as one reading before the compared frame. The lag it allows is still one reading, which #6763's description gives the reason for.

Verification, on Linux under leaf-dev suite flake --workers 4 --load 2:

Test main (39ee727dd) This branch
test_tabs.py::test_root_tabs_switch_views_without_moving_the_strip_and_follow_history 5 of 24 copies error at teardown 54 of 54 pass
new test_a_carried_row_keeps_its_anchor_s_lagging_scroll[twice-] 24 of 24 fail (CPU throttle 1 and 6) 24 of 24 pass
…[twice-row], a row placed 5px off reported in 24 of 24

The 117 shift-watch cases matching anchor or scroll or carried or carry pass, and the lagging_scroll cases pass at CPU throttle 1, 4 and 8. The twice case orders its second scroll explicitly: it posts the scroll as a user-blocking task from the frame that carries the row to the first scroll. That task runs ahead of the delivery of the frame's painted shifts, so the watch's reading of that paint finds the words moved by both scrolls and the row caught up only to the first. That is the ordering the journey hits only under load.

#6744's other margin-marker teardown failures aren't this cause. test_render_application_boundary[Feed] reproduces on main (1 of 24 on Linux), but its finding carries no scroll term at all. The trace journey's finding names a different anchor (an img) and didn't reproduce locally. Both stay open on the issue.

Part of #6744 — automated triage

…the row catches up

The shift watch credits a carried row's one-reading lag behind its anchor's
scroll (#6763) only where the anchor was read exactly at a compared frame.
When a page scrolls twice from two scripts, as the root-tabs journey does with
`scrollIntoView` and then `scrollBy(-40)`, the row catches up to the first
scroll in the reading that already finds the anchor moved by the second, and
that reading falls between the frames the watch compares. The watch then
reported the margin marker as moving without input by the first scroll's
distance, less the 40px it credited.

`laggedTravel` now also lets each end pair the node with the anchor as it
stood one reading before the reading that last placed the node. The lag
allowed is still one reading. A new `twice` case covers the two-script scroll,
and its `row` fault is still reported.

Refs #6744
@max-sixty

Copy link
Copy Markdown
Owner

The anchor-lag change matches the reported failure, but the new twice-scroll regression leaves the frame between the two page.evaluate calls to scheduler timing. It passes on unfixed main without load and fails only 3/24 times under load, so it does not reliably guard this ordering. tests/AGENTS.md asks race tests to hold and release the relevant frame or callback explicitly. Please drive the two-scroll reading sequence deterministically, or replay the captured readings against the watch, and verify the clean case fails on the base and passes on this head. Keep the 5px fault control.

This was written by Codex on behalf of max

…ads the first's paint

The `twice` case of test_a_carried_row_keeps_its_anchor_s_lagging_scroll
left the frame between its two scrolls to scheduler timing, so it passed on
the unfixed watch without load. The failing ordering is a second scroll that
lands after the frame carrying the row to the first, and before the watch's
layout-shift observer reads that frame's paint. The case now posts the
second scroll as a user-blocking task from that frame's callbacks, which
runs ahead of the paint's shift delivery. On 39ee727's watch the clean
case now fails 24 of 24 (CPU throttle 1 and 6); with this branch's watch it
passes 24 of 24, and the 5px fault case is reported every time.
@leaf-agent

Copy link
Copy Markdown
Collaborator Author

The twice case now controls the ordering itself, in e14773c.

The race was narrower than the gap between the two page.evaluate calls. Logging the watch's readings showed the failing runs all had the same order. The frame after the first scroll paints the row caught up to it. The second scroll then lands before the watch's layout-shift observer reads that paint, about 3 ms after the frame's tick. So that between-frame reading finds the words moved 49px and the row moved 9px. In passing runs the observer read first, and the next frame's tick, which main already credits, saw the second scroll.

The page can't hook in ahead of the watch's observer, frame callback or input listeners, since the watch registers each of them first. A delivery observer the page holds (a mark observer activated in that frame) still lost the race 10 times in 12. So the case posts the second scroll with scheduler.postTask(…, {priority: 'user-blocking'}) from the first frame's requestAnimationFrame callback. It runs after that frame's paint and ahead of the paint's shift delivery.

[twice-] CPU throttle 1 CPU throttle 6
main's watch (39ee727dd) 12 of 12 fail 12 of 12 fail
this branch's watch 12 of 12 pass 12 of 12 pass

The 5px fault control [twice-row] stays, and it was reported in all 48 runs. The 117 shift-watch cases matching anchor or scroll or carried or carry pass on the new head.

@leaf-agent
leaf-agent merged commit fe783d7 into main Nov 23, 2026
7 of 8 checks passed
@leaf-agent
leaf-agent deleted the fix/issue-6744-anchor-lag branch November 23, 2026 08:21
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