Repository navigation
Keep a margin card's reader at its transcript's end with one keeper - #5811
Merged
Merged
Conversation
A reader at the end of a margin card's transcript fell behind when its last turn grew after the card drew it, as when a picture in an answer loaded: the reader was left 97px short of the end. The card kept the end with two partial keepers. `keepFoot(transcript, {atEnd: true})` kept it through a change of the transcript's room only, and ignored any reading in which a turn changed size. The placement's fit followed the growth a reading of the thread drew, through `buildThreadCard`'s `follow` (an agent turn that changed, its foot near the reply box) and the reading's `end` and `limit`. Growth after a reading reached neither, since it changes no room and takes no reading.
`followEnd` (scrolling.js) replaces both. It watches the transcript and each turn in it, and puts a reader who stood at the end back there whenever the end moves, whatever moved it: the reply box taking room or giving it back, a fit, a turn drawn, a turn growing. Whether the reader stood at the end is read at each scroll, against the end as the box stood at its last size reading, so a scroll whose event arrives between a change and its size reading counts against the end the reader saw. A box moved back since that reading, or headed back by a glide that has yet to move it, stays where it was sent. Layout may carry it toward the end in the change itself, as Chromium's scroll anchoring did by 58px when a shorter window shrank a card's transcript, and that reader still follows. A change that leaves the end where it stood, or the reader at it, writes nothing, so the rubber band of a flick into the end stays the browser's (#5763).
Before following, the keeper asks whether another placer owns the end, with how the box stood before the change. The card answers that it does while it arrives on its opening turn (`showArrival`), and asks the thread (`ThreadView.placesEnd`). The thread owns the end while an answer to the user's turn is its to place (`answering`), as before. It now also takes back an answer its end followed into sight once that answer grows: `#fitAnswer` decides again, with the box as it stood before the growth, whether the end follows or New reply stands for the rest, so a picture loading in an answer can't carry the user's turn out of sight. The keeper asks before it checks whether the reader is already at the new end, since Chromium's scroll anchoring carries a reader there in the same layout when the node it anchors stands below the picture. Where the answer still fits, its placement then writes the end the reader already stands at, which `setScroll` skips while nothing moves the box (the change this branch stands on).
The fit no longer follows the end, and `buildThreadCard` no longer computes `follow` or keeps the latest turn for it. `keepFoot` loses its `atEnd` mode; the floating panel's thread view still uses it, and both keepers share the observation of a box and its children (`watchHeld`).
Behavior changed: a reader at a card's end now follows any growth at that end, a turn's late layout and a turn from anyone included, where the card followed only a new or changed agent turn whose foot stood near the reply box; and an answer that outgrows the card after the card followed it says New reply, keeping the user's turn in sight. `test_a_card_at_its_end_follows_its_last_turn_as_it_grows` and `test_an_answer_a_card_followed_says_new_reply_once_its_picture_outgrows_it` each hold a picture's request until the reader stands at the end, then let it load; both fail without the change.
…d report one that does neither The write watch now reports a page's instant scroll write that leaves its box where it stood (`unmoved-scroll`), as it reports a DOM write that changes nothing. A margin card's bounce in Firefox came from such writes: placing the card at every scroll's end put its transcript back at an end it already stood at, and each write cancelled the rubber band of the flick into it, which Firefox plays after the scroll has ended (#5763). Run over the card's tests on main, the check named the writers that do the same: `showReturnTurn`'s end before its step back, `keepThreadLanding` re-landing a transcript already at its end, `#fitAnswer`, `restorePlace` on a revision, the editor's caret reveal, `keepFoot` moving by zero, and the fit #5763 left. Every one wrote through `setScroll`. So `setScroll` (arrivals.js) skips an instant write that would leave a still box where it stands. While the browser or a glide moves the box (`browserScrolls`, `holdScroll`), the same write has an effect: it is how `stopScroll` takes a landing's place from a wheel's scroll, and how a glide takes over one. So there it writes the box's own position (`stopWhereItStands`), the one write meant to leave a box in place, which the watch allows by name. A script's own instant write leaves nothing in motion. With that guard the card's wheel test passes in Firefox on the card code from before #5763, and fails there without it. Where the box stands is read to the pixel, since a box's scroll size is whole pixels and an end read from it can stand a fraction short of the browser's own (Firefox's 314.25 against 314 at a 2x display), and against the box's range, which callers aim past at both ends. A box scrolls from zero to the side where its content's flow starts: the negative side where that start is the bottom or right edge, as in a right-to-left box, a reversed flex row or column, a wrap-reverse flex container, or a vertical writing mode. Off zero, the box's position says which side; at zero nothing does but the style that places the flow's start, so `scrollsBack` reads writing mode, direction, and a flex container's direction and wrap. The page itself scrolls from the start of its principal flow, which an HTML page takes from the body's writing mode and direction unless the root or the body is contained (as the default theme's body is), and which no flex flow on the root reverses. No API reports a box's scroll range (Firefox's non-standard `scrollTopMin` aside). `scrollRange` is that answer's one home: `localScrollBy` in element-frame.js read the same range from `direction` alone, and now asks it. Judging a write at zero against both sides instead would have written every move past the top of a box at rest, which the watch then found in seven tests (`returnTo`, `restorePlace`, a landing in a rotated port). The watch judges every other write, and found two that could never move anything. A landing walked every box that clips its destination and asked each to scroll, `overflow: clip` boxes included, which no script can scroll (`innerMoves` in landing-scroll.js now asks only scroll containers). And restoring a draft's editing wrote the field's scroll offsets directly rather than through `setScroll`. CodeMirror's own measure restates its scroller's offset where the browser clamps it, which `EXPECTED_SCROLLS` allows as `EXPECTED` allows vendored DOM writes. The shift watch's passive gesture case scrolls by nothing on purpose, and consumes the finding. Tests: `test_a_landing_that_moves_nothing_stops_a_scroll_still_under_way` holds the stop in Chromium: a bounded log scrolling smoothly when the reader lands on a name already in place stops where the landing found it, where a skip that ignored the scroll under way let it run to its end. In Firefox the log runs to its end on main too, since a write of the position the page last saw doesn't stop Firefox's smooth scroll; that is left as it was. `test_a_write_from_zero_moves_a_box_as_far_as_the_browser_lets_it` moves fifteen boxes, one per style that decides the side, from zero past each side, and `test_the_page_scrolls_from_the_start_of_its_body_s_flow` does the same for the page under four root and body styles; both pass in Chromium and Firefox. `tests/runtime/arrivals.test.mjs` holds the end clamp and the write while the browser scrolls. A second check, a page's write to a box the browser was scrolling for the user, found no real case once a newer key was read as asking for its scroll, and missed the bounce itself, whose writes landed after the scroll's end or during a wheel pushing at an edge that scrolled nothing, so it is not kept.
The page scrolls from its principal flow, the root's writing mode and direction or the body's. Which one applies turns on containment, content visibility, a hidden body or a frameset, and Chromium and Firefox differ on a hidden body, so modelling the choice kept missing cases. Both candidates are known, so where the root and the body agree, that is the side; where they don't, a write from zero is judged against both sides, which never drops a move and at most writes one that moves nothing. No flex flow on the root reverses the page.
leaf-agent
reviewed
Nov 10, 2026
…hat moves nothing setScroll skipped an instant write that would leave a still box where it stands, but while the browser or a glide moved the box it made the write anyway, since writing where the box stands is how a landing stops a scroll and a glide takes over a wheel's. One call meant both place and stop, so a writer restating a position mid-scroll would stop the user's scroll, and callers kept their own checks for a write that moves nothing: moveScrollerBy's half-pixel guard and the thread's New reply placement. The stop is now its own write, stopWhereItStands, which stopScroll and a glide taking over the browser's motion call by name and the write watch already knows. setScroll never writes a move of under a pixel, and the two callers' checks go. A skipped write no longer claims the box's position for the script, since it wrote nothing; the runtime test of a held scroll now gives its box a range its writes can move in. The touch Align test's second tap now goes through press_visible, which waits out the tap run the first began. Its raw locator.tap() landed on the same pixel within Chromium's ~400ms run, so the click carried detail 2 and the panel's runOfClicks pressed nothing for it; the test passed only where the page ran slow enough to space the taps, and failed on main as on this branch on a quick host.
… of nothing followEnd checked that the reader wasn't already at the new end before it wrote, its own copy of setScroll's rule, kept while setScroll still wrote in place for a box the browser was scrolling and so would have stopped the user's scroll. With the stop its own write (scroll-write-watch), a restated end writes nothing, and the copy goes.
leaf-agent
approved these changes
Nov 11, 2026
max-sixty
added a commit
that referenced
this pull request
Nov 11, 2026
…l as theirs from the input (#5834) Two changes to how Leaf keeps a box's end and who owns a scroll under way. Both came up on the thread card's Firefox bounce (#5763), and both are on the path a reader of a streaming log takes. ## One keeper for a log's end A block bounded at its end (`data-bound="end"`) followed its newest entry with a follower of its own in `bounds.js`, which judged a reader at the end from the box's offset alone. A press of u inside such a log starts a glide whose first frame can leave the box where it stands, so when an entry arrived before the glide moved, the follower took the reader for one still at the end, put the log back there and stopped the glide: the press did nothing, in 1 of 8 presses in Chromium and 4 of 8 in Firefox while entries streamed in every 4 ms. `followEnd` (`scrolling.js`), written for a margin card's transcript in #5811, already lets a box a glide heads back from go. `bounds.js` now opens a following block at its end once it is drawn and hands it to that keeper, so Leaf keeps a reader at a box's end one way. `bounds.js` keeps its watch on what a log holds and asks the keeper to read the log at each change (`check`): text grows a `<pre>` log without resizing any element a size observer reports, and a log emptied and refilled in two steps is clamped to its top in between. The keeper takes its first reading as it starts, reads nothing while its box isn't drawn, and says whether its reader stands at the end (`standsAtEnd`), which a revision asks of a bounded log to record its place. ## The reader's scroll is theirs from the input Leaf learned that the reader had set a box scrolling only from the box's first scroll event, which comes a frame or more after the wheel or key, and Firefox applies a wheel's or key's scroll that late too. Anything that asked in between heard that nobody was scrolling: - The keeper wrote a streaming log's end at each new entry, and Firefox cancels its pending scroll for a script write that moves the box, so a wheel, PageUp or ArrowUp up a log fed every 4 ms was pulled back to the end every time, on main too. - `afterBrowserScroll` didn't wait for PageDown when `d` came before PageDown's first scroll event, so `PageDown d` typed as a pair didn't add up, in Chromium and Firefox. An input the browser scrolls for (`scrollsFor`: a wheel, or a scroll key pressed where focus rests on no control) now starts the scroll sequence of the one box it moves: `inputScroller` (moved to `scroll-containers.js` from version.js, with `scrollChainOf` from reading-regions.js) names the box, and `startReaderScroll` (`arrivals.js`) opens its sequence, so `browserScrolls` holds from the input and `keyScrolled` says whether a key set it going. A touch may be a tap and a control takes keys of its own, as Space presses a button, so neither counts. A `scrollend` heard while the box still stands where the input found it, from its top or from its end, ends some other scroll, as Firefox ends a write it applied before the input and layout a clamp as a log loses its oldest entries, so it ends nothing of the reader's; an input that moves nothing ends after the 80 ms quiet spell. An input heading up a box tells its end keeper, which writes no end and says its reader isn't at the end (`standsAtEnd`) until that scroll ends, then reads the box again; where the input moved nothing, as one a handler prevented, it catches up with what it held back. A first version deferred the keeper's writes for any input, and layout moving the box meanwhile read as the reader leaving. `stopWhereItStands` stopped too little: Firefox ignores an instant write of the position the page last saw, and in Chromium 158 and Firefox 159 no instant write, even one that moves the box, stops the smooth scroll a key such as PageDown sets off. So a landing that moved nothing let a smooth scroll run on in Firefox, and `m` pressed as PageDown moved the page lost its landing to PageDown in both engines. A smooth write to where the box stands, then an instant one, stops each. **Behavior changed:** a page-up, wheel or arrow key away from the end of a following log while entries arrive now moves it, in both engines; `d` typed right after PageDown steps on from where PageDown lands; `m` pressed during PageDown lands; a landing that moves nothing stops a smooth scroll in Firefox too. A wheel or key up a following box that moves nothing pauses its following for about 80 ms. **Left as it was:** a key pressed on a control (a link or a button in a log) and a touch drag are still read from their first scroll event, as on main, since the input alone doesn't say a scroll follows. ## Tests - `test_a_page_up_in_a_log_a_stream_feeds_leaves_its_end` aims u, PageUp and a wheel up a streaming log in Chromium and Firefox; PageUp and the wheel fail 6 of 6 in Firefox on main. - `test_keys_pressed_while_the_page_moves_act_as_if_it_had_landed` now presses `PageDown d` back to back and `m` during PageDown; both failed before this change. - `test_a_landing_that_moves_nothing_stops_a_scroll_still_under_way` now also runs in Firefox, where it failed. - `test_a_log_follows_text_it_gains_and_opens_at_its_end_once_drawn` holds the `<pre>` log, a log first drawn late, and a log refilled just after End at its end; each failed on an earlier version of this change. - `tests/runtime/scrolling.test.mjs` holds which inputs the browser scrolls for, and `arrivals.test.mjs` the reader's sequence and the two-write stop. An independent Codex review ran three rounds. It found five regressions in earlier versions of the second change (a deferral that lost a clamp or an anchoring move, Space on a button and a tap standing down a place hold, control keys no longer stopping a glide); each reproducer passes on this head in Chromium and Firefox. Its last round also named cases left as on main: the thread card's answer placement (`#fitAnswer` in thread-card.js) decides from the offset before a wheel up and writes after it, and keys on controls (above). Locally the 915 runtime unit tests pass, and so do 227 of 228 browser tests over bounded blocks and card ends and 625 of 628 scroll-heavy browser tests. The failures also fail on main: `test_sending_flashes_only_the_new_message[card]`, `test_a_resolve_s_notice_stands_for_that_resolve_alone`, `test_a_transfer_keeps_its_persisted_source_when_the_destination_write_fails[reply]`, and the attached-image test's teardown. > _This was written by Claude Code on behalf of max-sixty_
max-sixty
added a commit
that referenced
this pull request
Nov 11, 2026
…efore holding news (#5837) A reader at the end of a margin card's transcript saw an agent's edit to the last turn wait behind the card's "1 new" notice when the edit arrived in the same task as that turn grew, for example as a picture in it loaded. The card's held-news check (`thread-card.js`, `newsMoves`) asked the transcript's scroll offset whether the reader followed the end. In that task the picture had already pushed the end 97px past the reader, and the end keeper hadn't yet read the growth. So the check said no and the edit waited. One frame later the keeper took the reader to the end, and the notice still stood for words they would have seen. The transcript's end keeper (`scrolling.js`, `followEnd`, from #5811 and #5834) already owns that answer in `standsAtEnd`. `thread-preview.js` now keeps the keeper itself rather than only its `stop`, and gives the card a `standsAtEnd` outlet, which `newsMoves` asks in place of the offset. Nothing outside `scrolling.js` calls `followsEnd` any more, so it is no longer exported, and `browser/AGENTS.md`'s question index points at `followEnd`. What to weigh: since #5834, `standsAtEnd` reads false from the moment a wheel or key heading up arrives, before the box moves. News to the last turn in that frame now waits, as it would a frame later once the box has moved. The keeper doesn't follow that reader either, so the check and the keeper agree. `test_an_edit_landing_as_a_card_s_last_turn_grows_shows_at_its_end` holds the page's state reading until the picture's `load` event fires, so the reading is taken in that task. It fails on the old check and passes with this change. The card's other held-news tests, the `u`-press glide smoke test and `pnpm run check` pass. > _This was written by Claude Code on behalf of max-sixty_
This was referenced Nov 13, 2026
leaf-agent
added a commit
that referenced
this pull request
Nov 13, 2026
…5928) #5853 made a thread card stand clear of its subject by `subjectGap` (the mark's room, `--focus-region-room`, plus `COMMENT_GAP`) instead of `COMMENT_GAP` alone. As that PR said, a card beside its words now narrows by 8px and needs 8px more room before it gives up standing beside. Five tests were sized to the old gap and have failed on main since, four in every `ci` push run and one in the nightly tier: each passes at #5853's parent `7c2112135` and fails at `a298398f6`. This change keeps #5853's placement and gives each test back the room the new gap takes; no runtime code changes. - `test_a_card_s_head_stands_whole_beside_news[True]`: at 1400px the touch card no longer fits beside its words, so it went under, grew wider and kept its time whole. At 1408px it stands beside again, and the docstring names the new width. - `test_a_head_s_words_take_its_controls_room_while_they_hide`: at 1440px the card is now 336px, which cuts the queued receipt (118px of words in 111px). At 1456px the card is 344px again, the width the base drew at 1440px. A margin card grows 0.5px for each 1px of window, which is why this takes 16px. - `test_one_unchanged_rewrite_stands_open_in_a_thread_across_its_readers`: at 1400px the card no longer fits beside the Feed reader, so it stands over the Feed message and blocks its double-click (Playwright: "`.lf-msg-head` … intercepts pointer events"). That test checks that only one rewrite stays open at a time, not where the card stands, so it now opens at 1408px. - `test_a_source_replacement_preserves_the_focused_draft_and_its_original_anchor[whole-datum]`: the reopened card stands under the document 15px down. The old bound, `+ 10`, held only the old 8px gap. The bound now asks the overlay for `subjectGap()`, so the test follows the `place-clear` rule from its owner. - `tests/journeys/test_render_margin.py::test_a_second_margin_reply_grows_below_the_first_line` (nightly): the card under its subject now starts 8px lower, so in a 1000×600 window the grown draft reaches the window's foot and its transcript gives up 8px, which moves the reply box's top up 8px. At 608px tall the card grows downward as it did before, and the long draft that follows still bounds it. The four push-tier tests pass on this PR's CI and fail on main without it. The journey's placement assertions now pass, but the journey still errors at teardown with `ResizeObserver loop completed with undelivered notifications`. That error comes from #5811 (`f58c2cac7`), not from #5853 or this change: bisected locally, it's absent at #5811's parent and present at every commit since, including #5853's parent. On main it's hidden behind the placement failure this PR fixes. #5933 tracks it, so the journey stays red until that's fixed. Closes #5917 — automated triage --------- Co-authored-by: leaf-agent <[email protected]>
leaf-agent
added a commit
that referenced
this pull request
Nov 13, 2026
…transcript's size delivery (#5934) A margin card's transcript holds a scrollbar gutter once its turns overflow (`data-lf-overflows` → `scrollbar-gutter: stable`, `annotation-chrome.css`), which narrows its content box. Only the reach pass's paint decided that gutter (`paintContinuation` in `thread-preview.js`). That paint runs inside reach's own ResizeObserver delivery for the transcript, so marking the gutter resized a box the delivery had just reported, and Chromium raised `ResizeObserver loop completed with undelivered notifications`. The nightly journey `test_a_second_margin_reply_grows_below_the_first_line` hit this at teardown. Before #5811, the card's fit scrolled a reader at the end to the new end, and that scroll ran the same paint in the placement's script, before the frame's layout. #5811 (intended: one keeper, `followEnd`, for a reader at the transcript's end) removed that scroll, so the decision waited for reach's delivery. This PR keeps #5811's design. The gutter decision is now one function, and the card's fit (`measureThreadCard`) calls it right after changing the card's room, before the frame's layout. The paint still calls it for overflow that no fit answers. What the gutter is and when it changes are unchanged. **Verification** - The journey errors on main `415cf1d6f` and passes three of three runs with the change. - 33 card and margin-journey tests pass: scrollbar room, end-following, New reply, ride and bounded draft (`-k "scrollbar or follows_its_last_turn or new_reply_once_its_picture or grows_below or bounded or end or ride"` over `tests/browser/margin/test_card_reply.py` and `tests/journeys/test_render_margin.py`). - `pnpm run check:browser` and `pnpm run test:runtime` pass. <details><summary>How the delivery was traced</summary> I wrapped `ResizeObserver` and added a document `MutationObserver` in an init script. On main, in the frame that errors, the order is: 1. The card's `max-height` drops from 534px to 260px. 2. reach's observer (`reach.js:419`) is delivered the transcript at 413px wide. 3. `data-lf-overflows` is set during that delivery. 4. The next round reports the transcript at 403px, and the error fires. 5. reach is delivered the 403px reading one frame late. At #5811's parent, the same trace shows `data-lf-overflows` set right after the `max-height` write, before any delivery in that frame. </details> One path is left. If the gutter's answer changes when a turn grows inside a card already at its cap, with no new fit, the decision still lands in a size delivery. That path predates #5811, and nothing currently reports it. Closes #5933 — automated triage Co-authored-by: leaf-agent <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Builds on #5806, which stopped
setScrollmaking a scroll write that moves nothing.A reader at the end of a margin card's transcript fell behind when its last turn grew after the card drew it, as when a picture in an answer loaded: the reader was left 97px short of the end. The card kept the end with two partial keepers:
keepFoot(transcript, {atEnd: true})kept it through a change of the transcript's room only, and the placement's fit followed growth a reading of the thread drew (buildThreadCard'sfollow, the reading'sendandlimit). Growth after a reading reached neither, since it changes no room and takes no reading.followEnd(browser/runtime/scrolling.js) replaces both. It watches the transcript and each turn in it, and puts a reader who stood at the end back there whenever the end moves, whatever moved it: the reply box taking room or giving it back, a fit, a turn drawn, a turn growing. Whether the reader stood at the end is read at each scroll, against the end as the box stood at its last size reading, so a scroll whose event arrives between a change and its size reading counts against the end the reader saw. A box moved back since that reading, or headed back by a glide, stays where it was sent. A change that leaves the end where it stood asks nothing, and a write to an end the reader already stands at moves nothing, whichsetScrollskips (#5806), so the rubber band of a flick into the end stays the browser's (#5763).Before following, the keeper asks whether another placer owns the end. The card answers that it does while it arrives on its opening turn, and asks the thread (
ThreadView.placesEnd). The thread owns the end while an answer to the user's turn is its to place, as before, and now also takes back an answer its end followed into sight once that answer grows:#fitAnswerdecides again, with the box as it stood before the growth, whether the end follows or New reply stands for the rest, so a picture loading in an answer can't carry the user's turn out of sight. Where the answer still fits after scroll anchoring already carried the reader to the new end, its write to the end moves nothing, whichsetScrollskips (#5806).The fit no longer follows the end, and
buildThreadCardno longer computesfollow.keepFootloses itsatEndmode; the floating panel's thread view still uses it, and both keepers share the observation of a box and its children (watchHeld).Behavior changed: a reader at a card's end now follows any growth at that end, a turn's late layout and a turn from anyone included, where the card followed only a new or changed agent turn whose foot stood near the reply box; and an answer that outgrows the card after the card followed it says New reply, keeping the user's turn in sight.
test_a_card_at_its_end_follows_its_last_turn_as_it_growsandtest_an_answer_a_card_followed_says_new_reply_once_its_picture_outgrows_it(plain and after progress) hold a picture's request until the reader stands at the end, then let it load; both fail without the change. They and the card's end, wheel, New reply and ride tests pass in Firefox too. Three card tests fail on this branch and identically with main's runtime files, so they come from main:test_a_thread_card_reply_stays_in_the_visible_viewport[tablet], and the Firefox cases oftest_a_press_that_changes_the_edge_holding_a_card_moves_it_from_where_it_stoodandtest_a_card_a_scroll_moves_onto_or_off_the_windows_foot_as_it_resizes_only_resizes; so doestest_a_transfer_keeps_its_persisted_source_when_the_destination_write_fails[reply].