Repository navigation
Make stills states draw the same on every run, each waiting for the event that ends its input - #6798
Conversation
…hart have fit their frames `leaf-dev stills` reported chart-preview and chart-point-aim as changed on runs of one commit, because the document's scroll offset moved after the state had settled. Scrolling the gallery to its line chart brings two live samples in "Margin controls" (#bg-margin-layer-actions and #bg-margin-layer-status), 650 to 1300 px above the window, within the window's height of it at which the runtime starts a sample's page. `settle` waits for those pages to load. Once the browser has read a frame as out of sight, though, the runtime stops counting its page's drawing and marks the frame `data-lf-unseen` (sample.js), so `settle` returned while both frames still stood at their 512 px placeholder. 150 to 250 ms later each frame took its page's height (148 px and 269 px), and scroll anchoring took the 364 + 243 = 607 px from the scroll offset: 9311, then 8947, then 8704. What a user sees doesn't move. A probe that read positions every frame found the chart at 317 px, the preview at 390 px and the aimed ring at 457 px through both changes, in Chromium and in Playwright's WebKit. With `overflow-anchor: none` the offset stayed at 9311 while the chart rose 607 px and the preview closed. No script scrolled the page: hooks on every scroll call and on `focus` recorded none after the state's own `scrollIntoView`. The stills did move. The scrollbar's thumb follows the offset, and a screenshot whose offset read fell before a change and whose capture fell after it drew the window 607 px further down the page, blank below the content, since Playwright's Chromium screenshot reads `Page.getLayoutMetrics` and then captures that region of the document. Where both arms' pixels matched, the computed styles read after the screenshot could still differ: a sample's Reset still disabled in one arm, and the margin clusters 243 px apart. `samples_drawn` passes one rendering so the observer that starts samples reads the window, settles while their pages load, waits until no frame carries `data-lf-unseen`, and settles again for the frames' fit. gallery-metrics, chart-preview and chart-point-aim call it after their last scroll, and chart-preview opens the tab and scrolls to the chart itself rather than through gallery-metrics. Both pages also draw out of sight in Firefox, so the wait ends there too. Evidence, from `uv run leaf-dev stills --base HEAD --state chart-preview --state chart-point-aim --state gallery-metrics` on one commit: - Before, three runs: every state changed in every run, 9 of 9 pairs (1.0 to 1.7 million pixels, or 0 pixels and 11 to 15 styles). - After, three runs: 3 of 3 states unchanged each time, and all 18 stills (3 runs, 2 arms, 3 states) match pixel for pixel.
…e of three states The chart states' race (the previous commit) is a gap in what `settle` waits for, so every caller of `settle` (`load`, `visits` and each probe) now waits for it, and `samples_drawn` and its calls in gallery-metrics, chart-preview and chart-point-aim are gone. chart-preview again reaches the chart through gallery-metrics. `settle` now passes one rendering so the observer that starts a sample reads the window the last input left, waits until the page is ready (the samples' loading), waits until no frame carries `data-lf-unseen` (their drawing out of sight), and waits until the page is ready again (their frames' fit) before the fonts, `pageSettled` and the hover catch-up it already waited for. Cost: on lost-update, a page with no samples, 30 interleaved calls on a settled page took a median of 26.6 ms (p90 30.1 ms) against 6.5 ms (p90 9.7 ms) before, about 20 ms per call, mostly the rendering it now passes. Survey: two runs of `uv run leaf-dev stills --base HEAD` over the 74 states whose page holds a live sample (feature-gallery 59, diff-thread-gallery 9, dynamic-widgets 2, corpus 2, thread-panel-gallery 1, quoted-playground 1). No state failed or timed out on the new wait. Runs reported 66 and 65 of 74 unchanged, and 71 of 74 states drew identical stills in all four captures (2 runs, 2 arms), chart-preview, chart-point-aim and gallery-metrics among them. The rest have causes outside this change: - share-link draws each arm's own commit, dirty flag, port and page token in About this page, so its arms always differ. - retained-quote clicks the corner of its sample's page while that page is still starting. The page's body is inert until then, so Playwright's click retries, and each retry scrolls with a different alignment (none, end, center, start), so the window's offset depends on how long the page took. It also differed in one of two runs with the old `settle`. - panel-leaf drew the leaf's focus preview in one of four captures. Two probes of its steps saw no preview open within 2 s of the focus; the cause is not established. - detached-thread, thread-picture and image-preview differ in styles only, every run: a thread card names its quote `lf-thread-quote-<random id>`, and stills keys elements by id. - page-comment-photo (main's auto margins read as 0 px in one arm), page-comment-photo-hover and option-add-hover (the pointer preview, which opens after a 200 ms dwell, opened between one arm's screenshot and its style read) and gallery-theme (off-screen margin rows 34 px apart, once) differ in styles only, with identical pixels. page-comment-photo and page-comment-photo-hover also differed with the old `settle`.
retained-quote scrolls its live sample into view and at once presses the corner of the sample's page to give it the keys. That page's body is inert until the page starts, so Playwright's click retried: with `DEBUG=pw:api`, a run logged four "element is inert" attempts before the press landed. Each retry scrolls the target with the next alignment (none, end, center, start), so the window's offset depended on how many attempts the page's start took. Three probes of the state's steps left the sample's frame 142, 58 and 142 px below the window's top, and the stills survey caught one run's still 42 px off. The state now waits for `sample.ready`, as live-sample-embedded does, before it presses. A probe of the new steps logged no inert attempt and no retry, and the offset stayed where the state's own scroll left it (frame top 119 px).
… not a random id A thread view named its quote `lf-thread-quote-<random id>` for the Full quote press's `aria-controls`, so the name changed on every load, and `leaf-dev stills` reported every state with an open thread as changed in styles (detached-thread, thread-picture, image-preview). A name made from the thread alone would collide: a probe on review-a-plan that opened a margin card and then the same thread in the floating panel found two drawings of the thread, each with its quote. So the name is now the view's ordinal among the views the document has drawn (`lf-thread-quote-1`, `-2`): unique however many views draw one thread, and the same on every load that draws the same views in the same order. The same probe now finds `lf-thread-quote-1` for the card and `lf-thread-quote-2` for the panel's view. Tests: `pnpm run test:runtime`; the quote tests in tests/browser/threads/test_targets.py (test_original_quoted_words_remain_readable_after_the_page_rewrites_them, test_a_long_quote_of_replaced_data_has_a_local_reading, test_a_changed_datum_keeps_its_old_words_open_when_its_label_changes) and tests/browser/test_render_floating_panel.py (test_a_package_s_places_for_a_thread_s_parts_take_them_as_its_outlet_does, test_a_thread_whose_words_are_gone_keeps_its_quotation_in_the_panel).
…on a control A preview opens 200 ms after the pointer comes to rest (preview.js, `DWELL`), and nothing in `settle` waits for that timer, so a state ending on a hover caught the preview in one capture and not the next, in the pixels or in the styles read after the screenshot. A probe of each of the 25 states whose last pointer action is a hover read whether the preview was open once the state settled and 700 ms later. Three opened one late: - panel-status-hover, "On Me, 1 waiting on me, 1 thread with news"; - page-comment-photo-hover, "View attached image 1"; - option-add-hover, "Add and select option ⏎". Each now waits for the preview (`preview_shown`), since each state's subject is a pointer resting on the control, and the preview is what that pointer gets. Ending with no preview instead would mean capturing inside the dwell, or moving the pointer or pressing Escape, which drops the hover face the state shows or acts on the draft the state typed. control-preview's own copy of the same wait now calls `preview_shown`. Of the other 22 states, chart-preview, chart-point-aim, control-preview and link-preview already waited for their preview; panel-status-cut, thread-preview and age-preview already showed it, since they sleep `PREVIEW_DWELL_MS`; and the rest opened none. Two runs of `uv run leaf-dev stills --base HEAD --state panel-status-hover --state page-comment-photo-hover --state option-add-hover --state control-preview` reported panel-status-hover, option-add-hover and control-preview unchanged both times, and all 16 stills match across runs, each with its preview drawn. page-comment-photo-hover still reports `main`'s margins as 336 px in one arm and 0 px in the other, the difference page-comment-photo shows, whose cause is open.
leaf-agent
left a comment
There was a problem hiding this comment.
The data-lf-unseen wait in settle fixes the same symptom as #6783, but in the dev tool instead of in the page's readiness. Both PRs are open and both rewrite settle. #6783 makes a block sample's arrival count toward the page's arrival wherever its frame stands. That covers the case described here: two samples above the chart shrank after settle returned, and only a block sample changes its frame's height. Under "Fix the underlying issue" in AGENTS.md, the fix belongs where readiness is defined. A dev-side wait would repeat a rule the readiness probe should state, and every other reader of readiness (page check --render, probe) would still see the page as ready early.
Once #6783 lands, this wait would only add a wait with no cap. That matters because settle reaches more than the corpus. load calls it, and so do the eval's simulated user (eval_user.py, through load and after each press) and visits.py. Both open pages an agent wrote. A chart sample standing just outside the window there now raises TimeoutError after the 15 s default, where #6783 caps the same wait at 20 s and carries on. The docstring and the PR body name this case but measure it only against examples/.
The other three fixes stand on their own: the view counter in thread-card.js, the sample.ready wait in retained_quote, and preview_shown. Dropping the data-lf-unseen wait and the first one_frame/wait_until_ready pair from settle, and landing these on top of #6783, would avoid the conflict in settle.
…hromium's margins
`leaf-dev stills` reported page-comment-photo and page-comment-photo-hover as
changed in styles on most runs: `main`'s margins read 336px in one arm and 0px
in the other, with identical pixels.
The layout never changed. Visiting page-comment-photo six times as stills
does (scale 2, its window), `main` read `margin-left: 336px` before the
screenshot every time and 0px after it four times, while its box stayed at
x = 336 (`offsetLeft` 336, width 768). The screenshot's style (`HELD`,
`:root { caret-animation: manual; }`) is the trigger: a plain
`page.screenshot()`, one with `caret="initial"`, one with a style that sets
nothing on the root, and a raw CDP capture all left 336px in four of four
visits, while adding `:root { caret-animation: manual; }` or
`:root { --lf-probe-x: 1; }` as a stylesheet, with no screenshot, gave 0px
in one to four of four, focus in the field or not. So after a change to the
root's style, Chromium can report `main`'s auto margin as 0px where its box
stands 336px in. Leaf's runtime reads no such margin, so no user meets it.
`capture` now reads the styles before it takes the screenshot, from the page
as the state left it. Two runs of `uv run leaf-dev stills --base HEAD --state
page-comment-photo --state page-comment-photo-hover` reported 2 of 2
unchanged both times, with identical stills across runs.
…focus panel-leaf drew the leaf's focus preview in some captures and not others. The state presses Tab, so the focus it places next draws as the keyboard's, and then focuses the leaf. The runtime takes focus that arrives while a Tab's step stands, from its keydown until a timer that keydown queues, as the step itself, and a step opens the focused control's preview (focus.js, `stepping`). Playwright's next command could run before that timer. Ten visits of the state's steps as stills makes them, with a keydown listener queuing a timer of its own after the runtime's: in five, the leaf's focus arrived before that timer ran, and in exactly those five the preview opened. With the state awaiting a timer queued after the Tab, the leaf's focus came after it in ten of ten, and the preview stayed shut in ten of ten. `keyboard_modality` presses Tab and awaits that timer. Each state that pressed Tab only to place focus by keyboard modality now calls it: panel-leaf, captured-source-keyboard, recorded-video-keyboard, the tab-focus states, section-ring-keyboard, activity-feed, triage-composer-send-focused, and the triage grab states. Two runs of `uv run leaf-dev stills --base HEAD` over those 12 states reported 12 of 12 unchanged both times, with identical stills across runs.
…roll gallery-theme sometimes reported the margin's off-screen rows 34 px apart between arms, with identical pixels. The rows had not moved. The margin's layout writes the scroll offset at the time of its pass into each carrier's place (`top: calc(337px + anchor(top))`) and stands the rows in the carrier by their margins. In eight visits of the state as stills makes them, seven carriers read 337px with the rows at 1846.8px and one read 371px with the rows at 1812.8px: the same places, 371 being the offset after the state's final scroll. Logging each write of a carrier's style against that scroll showed why. The state opens and closes the theme's disclosure by key and scrolls once it reads closed, and the closing queues one more pass. In two of ten visits that pass landed after the scroll and rewrote the carriers with 371px; in the other eight it ran first and wrote nothing new. With the state settling before the scroll, no pass followed the scroll in ten of ten. Three runs of `uv run leaf-dev stills --base HEAD --state gallery-theme` reported it unchanged each time.
# Conflicts: # dev/leaf_dev/browser.py
leaf-dev stillsreported states as changed when both arms ran the same commit, each state for a cause of its own. Each is fixed where it arises:thread-card.jsnow numbers views in drawing order, since one thread can show in two views at once.keyboard_modalityhelper now waits for that step, in 12 states.The flake that started this, the chart states' scroll offset, was fixed in the runtime by #6783, which landed meanwhile, so this branch takes main's
settle. With it, chart-preview, chart-point-aim, gallery-metrics and six of the fixed states drew unchanged stills in two runs on identical arms, and each fix's own reruns match across runs.Max asked for the chart flake to be fixed, as a follow-up to #6771; these are the other flakes the survey for it found.
dev/tests/model/test_stills.pyand the thread-quote tests intests/browser/threads/test_targets.pyandtests/browser/test_render_floating_panel.pypass.