Skip to content

Credit a fold's reflow across a shadow boundary in the shift watch - #3882

Closed
max-sixty wants to merge 2 commits into
mainfrom
grind/f-main-tests-2
Closed

max-sixty wants to merge 2 commits into
mainfrom
grind/f-main-tests-2

Conversation

@max-sixty

@max-sixty max-sixty commented Oct 25, 2026 •

Copy link
Copy Markdown
Owner

test_a_reopening_in_a_folded_diff_thread_waits_in_its_summary errored at teardown on every macOS run. The shift watch reported the paragraphs after LONG_LINE_DIFF_PAGE's diff, and a line-comment button inside the diff, as moving up about 18-33px without input. Linux CI passes the test (the nightly of 2026-10-24 and main's runs).

Cause

The shift is the resolve's own fold. Pressing Resolve folds the thread card with foldBlock (motion.js): a 200ms block-size animation, and the content below follows it up. That is the reflow the Stability contract allows for a change the user asked for (browser/AGENTS.md). The press owns its rendering only until the page adopts the server's reading. After that, the watch credits the rest of the fold through animation_reflow, which covers a later box only where sizeReaches finds the size change on the layout path to it. On this Mac the reading landed about 55ms after the press, mid-fold, and sizeReaches missed both boxes:

  • The card is in lf-diff's shadow root and the paragraphs are in the document. animationMotion skipped any target whose root node differs from the moved box's, and sizeReaches climbed parentElement, which stops at the shadow root.
  • The comment button is position: absolute in its relatively positioned div.lf-diff-line. sizeReaches refused any out-of-flow box between the moved node and the following sibling, even one whose containing block is that line.

Delaying the resolve's POST by 400ms, so the reading lands after the fold ends, makes the test pass on unchanged main. I infer that Linux CI passes the same way, because its server answers after the fold has finished. I haven't confirmed that on Linux.

Change

sizeReaches now climbs the rendered tree (up, the runtime's renderedParent, which the watch already uses), skipping elements that generate no box (display: contents, such as a slot), so a size change inside a widget's shadow root reaches the boxes after its host. It orders the moved box after the size change only where both stand in one tree, since the DOM gives no order across trees. An absolutely positioned box counts as carried when a positioned box between it and the following sibling holds it, since its containing block is that box or one nearer. A fixed or floated box still is not carried. The rule still requires every box on the path to change by the animation's change, the moved box to move by exactly that much, and a block flow.

The root-node filters in front of sizeReaches, in the size-animation path and the <details> closing path, give way to mayFollow. It orders the two nodes through their trees' hosts, with no style or layout read, so a moved box before the size change is still dropped before any layout lookup. sizeReaches reads the moved box's path once per call rather than once per step of the branch climb. The style values the path reads, and each animation's geometry properties (getKeyframes), are kept for the task that reads them (forTask): every moved box in a frame asks the same of the same ancestors and effects, and the watch changes neither within a task.

Known limit, unchanged from main: within one tree, named slots can render a host's children in a different order from the DOM's, so a scripted move of a child that the DOM puts after the size change but a slot renders before it is still credited.

New test test_press_owned_size_flow_crosses_a_shadow_boundary: a press-owned fold inside a shadow root, advanced after the press's rendering has ended.

  • in-its-line: the reading after the host and an absolute button in a later relative line are credited. It fails on main's watch.
  • in-the-window: a button positioned against the window, which a script moves by the fold's travel, still fails. It also fails when the containing-block check is removed, so that check carries the case.

Evidence

At a load of about 25-40 on macOS:

  • test_a_reopening_in_a_folded_diff_thread_waits_in_its_summary, both cases, -n 0: errors on main, passes on four runs with the change.
  • test_render_shift_watch.py -k "size or details or news or fold or flow or disclosure or closing or native or slot or shadow": 161 passed on this push.
  • With the containing-block check removed, in-the-window fails on this push as well.
  • tests/browser/threads/test_resolving.py and tests/journeys/test_render_read_state.py, -k "fold or resolv or diff": 29 passed on the first push. On this push, test_resolving.py and the folded-diff test pass (18 tests).

Cost

I timed protectedMotion per frame on a scratch page. It has 300 paragraphs, a host whose shadow root holds a 3000px block-size fold followed by 100 paragraphs, and then 300 more paragraphs. The fold runs for 3s, and the window is scrolled to where the fold carries the paragraphs across it. CPU throttling comes from Emulation.setCPUThrottlingRate. Each figure is the mean of three runs, interleaved, at a load of about 15-19:

Watch 4× throttle full speed
main 12.8 ms 2.70 ms
first push of this PR 16.1 ms 3.50 ms
this push 12.1 ms 2.55 ms

With the window also scrolling 3px a frame through the fold, so the paragraphs before the fold move too, two runs at 4× gave 17.2 ms on main, 24.1 ms on the first push and 19.1 ms on this push. The remaining cost over main is the credit itself: main reported those paragraphs as moving without input instead of weighing them. The harness is scratch and not committed. It wraps protectedMotion in a timer and swaps the watch source in through render_harness.SHIFT_WATCH_SOURCE.

Not run: the whole browser suite, Linux, VERIFY = 1. The change mostly adds credit. The one place it can remove some is a size change and a moved box that share a flow from different trees, which the old parentElement climb could order and the new one doesn't credit. The larger risk is that a real passive shift becomes credited. The reflow rule's existing negatives (test_absolute_size_animation_cannot_credit_an_independent_control_move, the flex-row, inline-sibling and width cases) still fail as they should.

This was written by Claude Code on behalf of max-sixty

max-sixty and others added 2 commits October 24, 2026 21:10
`test_a_reopening_in_a_folded_diff_thread_waits_in_its_summary` errored at teardown on every macOS run. The shift watch reported the paragraphs after `LONG_LINE_DIFF_PAGE`'s diff, and a line-comment button inside the diff, as moving up about 18-33px without input. Linux CI passes the test (the nightly of 2026-10-24 and main's runs).

## Cause

The shift is the resolve's own fold. Pressing Resolve folds the thread card with `foldBlock` (`motion.js`): a 200ms block-size animation, and the content below follows it up. That is the reflow the Stability contract allows for a change the user asked for (`browser/AGENTS.md`). The press owns its rendering only until the page adopts the server's reading. After that, the watch credits the rest of the fold through `animation_reflow`, which covers a later box only where `sizeReaches` finds the size change on the layout path to it. On this Mac the reading landed about 55ms after the press, mid-fold, and `sizeReaches` missed both boxes:

- The card is in `lf-diff`'s shadow root and the paragraphs are in the document. `animationMotion` skipped any target whose root node differs from the moved box's, and `sizeReaches` climbed `parentElement`, which stops at the shadow root.
- The comment button is `position: absolute` in its relatively positioned `div.lf-diff-line`. `sizeReaches` refused any out-of-flow box between the moved node and the following sibling, even one whose containing block is that line.

Delaying the resolve's POST by 400ms, so the reading lands after the fold ends, makes the test pass on unchanged main. I infer that Linux CI passes the same way, because its server answers after the fold has finished. I haven't confirmed that on Linux.

## Change

`sizeReaches` now climbs the rendered tree (`up`, the runtime's `renderedParent`, which the watch already uses), skipping elements that generate no box (`display: contents`, such as a slot), so a size change inside a widget's shadow root reaches the boxes after its host. It orders the moved box after the size change only where both stand in one tree, since the DOM gives no order across trees. An absolutely positioned box counts as carried when a positioned box between it and the following sibling holds it, since its containing block is that box or one nearer. A fixed or floated box still is not carried. The root-node filters in front of `sizeReaches` (the size-animation path and the `<details>` closing path) are gone. The rule still requires every box on the path to change by the animation's change, the moved box to move by exactly that much, and a block flow.

New test `test_press_owned_size_flow_crosses_a_shadow_boundary`: a press-owned fold inside a shadow root, advanced after the press's rendering has ended.

- `in-its-line`: the reading after the host and an absolute button in a later relative line are credited. It fails on main's watch.
- `in-the-window`: a button positioned against the window, which a script moves by the fold's travel, still fails. It also fails when the containing-block check is removed, so that check carries the case.

## Evidence

At a load of about 25-40 on macOS:

- `test_a_reopening_in_a_folded_diff_thread_waits_in_its_summary`, both cases, `-n 0`: errors on main, passes on four runs with the change.
- `test_render_shift_watch.py -k "size or details or news or fold or flow or disclosure or closing or native"`: 160 passed.
- `tests/browser/threads/test_resolving.py` and `tests/journeys/test_render_read_state.py`, `-k "fold or resolv or diff"`: 29 passed.

Not run: the whole browser suite, Linux, `VERIFY = 1`. The change mostly adds credit. The one place it can remove some is a size change and a moved box that share a flow from different trees, which the old `parentElement` climb could order and the new one doesn't credit. The larger risk is that a real passive shift becomes credited. The reflow rule's existing negatives (`test_absolute_size_animation_cannot_credit_an_independent_control_move`, the flex-row, inline-sibling and width cases) still fail as they should.

> _This was written by Claude Code on behalf of max-sixty_

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Review of the first push found `sizeReaches` re-climbing the moved box's
ancestry with `getComputedStyle` at each step of the branch climb, and
the cheap order prefilter before the layout reads gone. On a 700-paragraph
page with a fold in a shadow root, `protectedMotion` per frame went from
12.8 ms on main to 16.1 ms at 4x CPU throttle.

`sizeReaches` now reads the moved box's path once per call. `mayFollow`
orders the two nodes through their trees' hosts, with no style or layout
read, ahead of the layout lookups in both the size-animation and the
`<details>` paths. The style values the layout path reads, and each
effect's geometry properties, are kept for the task that reads them
(`forTask`). Per frame at 4x throttle: main 12.8 ms, first push 16.1 ms,
this push 12.1 ms; at full speed 2.70, 3.50 and 2.55 ms.

The order comment now names the named-slot limit: within one tree, a
slot can render a host's children in another order than the DOM's, so
a scripted move there is credited, as on main.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@leaf-agent

Copy link
Copy Markdown
Collaborator

Another fold-credit failure reached Linux CI in run 40173703910: test_resolved_file_threads_share_the_file_disclosure_edge reported its resolved summary moving from y=209.203125 to 207.953125, with zero animation credit. A held-fold probe reproduces that completion-frame shape on main and with this PR's current watch patch: y=209.90625 → 207.953125, zero animation credit, while the functional assertions pass. This adds a completion case to the reflow boundary being repaired here; I have left it with this PR rather than opening a competing watch change.

The target changes parent at completion: immediately before finish(), the folding card is in .lf-diff-file-thread-outlet and is 1.953125px tall; afterward it is inside closed .lf-resolved-threads and has a zero rectangle. From code reading, the live DOM ordering/path used by mayFollow and sizeReaches cannot establish the preceding-sibling relationship after that move. I have not yet verified a correction using the retained pre-completion path.

Probe and limits

On main d035ac869, insert this before the test's existing with sending(page, "the resolution"):

from render_cases_interaction import HOLD_MOTION
from render_harness import judge_watches
page.evaluate("() => {" + HOLD_MOTION + "}")

After expect(summary).to_have_text("Resolved · 1"), insert:

page.evaluate("() => __lfHeld.forEach(a => a.currentTime = 150)")
one_frame(page)
page.evaluate("() => __lfHeld.forEach(a => a.currentTime = 175)")
one_frame(page)
judge_watches()
page.evaluate("() => __lfHeld.forEach(a => a.finish())")

Run the single node id:

uv run pytest tests/browser/test_render_diff_controls.py::test_resolved_file_threads_share_the_file_disclosure_edge -q -n0

This produced the matching teardown error both on main and after applying the tests/shift_watch.js diff from this PR's head d52903c7a6b25937e796ee15deeb047c0692d4c6. It is still timing-sensitive: adding geometry reads around finish(), or explicit screenshots between seeks, made it pass. Unmodified main also passed locally at normal speed and CPU throttle 6 and 20. The junit records for earlier scheduled runs 40087560199 and 39942183901 show this test passing. These passes do not establish that the completion credit loss has been repaired.

max-sixty added a commit that referenced this pull request Oct 25, 2026
#3939)

Adds a nightly macOS run of every test tier, and fixes every test that
failed in its first run or in the Linux nightly beside it: 89 tests in
[run
40156291557](https://github.com/max-sixty/leaf/actions/runs/40156291557),
60 of them only on macOS.

## The macOS nightly

`ci.yaml` gains a `test-macos` job: every tier on `macos-15`, `-n 2` on
its three cores, in the daily schedule and a dispatch. It belongs to
`ci`, so a failure turns that run red and reaches tend through the
existing `workflow_run` trigger, with no tend configuration change.
GitHub doesn't bill hosted runners for public repositories; the job
holds one of the account's macOS slots for about three hours. The test
step names `shell: bash`, without which a step runs without `pipefail`
and piping pytest through `tee` reported the first run's failures as a
green job. The setup action's Ubuntu mirror step now runs only on Linux.

`tests/AGENTS.md` counts `test-macos` among what tend repairs and leaves
only failures no CI run shows to local sessions. It drops the
instruction to confirm a macOS-only failure at normal priority because
`taskpolicy -b` slows headless Chrome: a test that fails on a slower
host depends on timing, and the fix is to the test. `running-tend` tells
the session fixing a red run, which has only a Linux runner, to verify a
macOS-only fix by dispatching `ci` on its branch.

## The fixes, by cause

Product fixes:

- A drafted margin card rose against the window's foot and never came
back as the draft shrank (#3524). It now holds the top it opened at and
drops back.
- A tapped pin reseated 11px lower as it unfolded, because the
hold-to-read toggle was pressed before the browser focused it (#3341).
- A page's first thread card could cover its passage, because the
placement that makes room was dropped while Floating UI loaded (since
#1526).
- A heading's "Copy link to section" stayed at the heading's far end
after the window narrowed and widened, since every engine keeps its last
`position-try` fallback (#3836). It now picks its place from the current
width.
- Putting the response bar away moved focus off the button the press had
just focused, so the next `e` found nothing (#3756).
- A trace's image-tools status shared a class with the image's loading
notice, whose rules hid it (#3707).
- WebKit scrolled the outer page 1,386px when a sample editor took focus
(#3634).
- In draw mode a press left the previous press's release timer pending,
so a fast second click reached the page.
- Hint refreshes read the geometry of every target inside a closed
disclosure, forcing layout of skipped content.
- A sidebar page's sticky track clipped focus rings (#3918). A stuck
track body now keeps the ring's room inside its edges, so its blocks
stand 5px in from each side.
- Tab revealed a block's Copy flush with its scroller, cutting its ring
(#3916).
- The hidden "my change" word inside a choose group took a cell's
padding and read as clipped content (exposed by #3837's check).
- Visual review case buttons kept their wide padding after the first
breakpoint crossing, a Chromium restyle bug avoided by making the case
list a plain container.
- A held shot's scrolling stage didn't declare that it holds its height
(#3703/#3704).
- When the log refused a reply, the floating panel's head moved down
69px and the restored draft pushed its controls up 21px (#3400). Through
a refusal the panel now holds its head and the field its height, on the
holds a press already takes; the refused turn's room goes at the user's
next turn.
- A reply box's ↑ (edit your last message) appeared only after an
unrelated repaint once its last message became editable (#3855). Every
message draw, by any thread reader, now recomputes that row's keys.
- A trace's images took the page's scroll anchor, so a lane change in
the timeline scrolled the page 62px under an arrow key; they no longer
anchor scroll. The trace overview wrote its window's new start before
reading its size, so for one layout the window ran past its strip and
Chromium scrolled the page up to 838px; it now reads before it writes.
The image tools' status keeps its line when its text clears.
- Web Awesome's radio group moves focus on an arrow with a bare
`focus()`, which Leaf's ring scroll margin turned into a page scroll.
The vendored bundle is patched (`build/vendor.mjs`) so both calls pass
`preventScroll`.
- A Leaf page inside an iframe took focus from the page around it when
it finished arriving. Its arrival recovery now runs only at top level or
in a frame that holds focus.
- The margin rail's one Tab stop stayed on whichever row last held it,
so a resize could leave it below a row the user sees first. It is now
the highest row in view; a focused row keeps it.
- A resize that moved a sidebar page's track into the page, with neither
place made by the reader, took the track's place over the page's:
live-progress jumped 1861px (#3918). On a tie the page's own place wins.
- The whole-page rule read a shut disclosure whose children are all
generated as showing what it holds (#3908); it now skips only `.lf-ui`
apparatus.
- The gallery revealed its stamped frame at the centre, carrying the
pressed button 45px; it now scrolls only as far as needed.

Test fixes:

- The Codex fixture copies the running interpreter as `codex`; on a
framework Python, as on the runner, the copy fails its code signature
and macOS kills it at launch. That broke 39 tests. The copy is now
re-signed ad hoc, and the fixture no longer leaks `PYTHONHOME` into the
command it runs.
- The plain-HTTP copy test missed Chromium's lower-cased host; the
event-door refusal test read its answer after the server's reset; the
stale-keys sweep raced the browser entering fullscreen; the words watch
didn't credit a blur from a press elsewhere.
- Several tests read state before it settled (a shown gesture's arm, a
side list's smooth scroll, a sample's focus returning, a held reply's
menu), and now wait for it. Assertions predating #3830, #3916, #3670,
#3673 and #3217 now read the current behavior.
- Three waits fixed their own deadline instead of the suite's, among
them the async-probe test's 500ms.
- The command hub's record now sticks in view, so the Atlas journey
opens its news before reading each row; the region-capture journey drags
over the unreadable image it means to fail on (#3861 draws only the
element that alone paints the crop).
- The touch-capture removal test, which fails intermittently on main,
now reads the shelf right after the tap and names the elements the tap
reached, so its next failure says whether the tap missed or the image
came back.
- The feature-gallery scroll pass allows a third of its steps to write
the contents' `aria-current`, as gestures already do, since the count
depends on where sections fall under the platform's fonts.

The branch also merges the four open `grind/f-main-tests-*` pull
requests, whose fixes cover five more of the run's tests: #3871, #3882,
#3887 and #3906. This pull request lands them.

Each fix was reproduced failing and then passing by node id, on this Mac
or, for a Linux- or runner-only failure, against a run's log, except
where its commit says otherwise. Dispatched full runs on this branch
([40156291557](https://github.com/max-sixty/leaf/actions/runs/40156291557),
[40186545420](https://github.com/max-sixty/leaf/actions/runs/40186545420),
[40196342887](https://github.com/max-sixty/leaf/actions/runs/40196342887))
check both platforms; the second took the macOS job from 86 failures to
38, most of the rest fixed since. A few macOS-only failures pass on
every local attempt (two reading-place tests, a scroll repaint, Back
from a thread, opening a line under the last, the Android composer's
Return, margin-entry order, a card paging on, a turn arriving out of
view) and have no fix here; once this lands, the macOS nightly reports
them to tend.

> _This was written by Claude Code on behalf of max-sixty_

---------

Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>
@max-sixty

Copy link
Copy Markdown
Owner Author

Superseded by #3939, which already contains all of this change; merging main left no diff.

This was written by Claude Code on behalf of max-sixty

@max-sixty max-sixty closed this Oct 27, 2026
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