Skip to content

Studio: skip layout of distant messages so the browser pane opens fast on long chats - #16986

Merged
danielhanchen merged 5 commits into
mainfrom
studio-pane-rewrap
Nov 7, 2026
Merged

danielhanchen merged 5 commits into
mainfrom
studio-pane-rewrap

Conversation

@danielhanchen

@danielhanchen danielhanchen commented Nov 7, 2026 •

Copy link
Copy Markdown
Member

Problem

Opening the browser pane narrows the chat column from about 1018 px to 509 px, and every message in the thread re-wraps at the new width. On real macos-15 runners at 150 turns (300 messages, about 56k nodes) the pane takes 1.09-1.85 s to open, with single frames of 0.73-1.25 s. On macOS Chromium it takes 369-713 ms, 423 ms of that layout. Closing pays the same re-wrap again.

Fix

  • distant-rows.ts: an IntersectionObserver marks message rows further than max(1500 px, 2x the window height) from the viewport with data-row-distant. The reach stays ahead of Chromium's own content-visibility: auto activation margin (150% of the window height), so a row is released, and its re-wrap compensated, before the engine renders it. WebKit uses no margin. The observer is rebuilt when the window height changes. index.css gives those rows content-visibility: auto, so a width change only re-wraps the rows near the reader.
    • Every row carries contain-intrinsic-size: auto 600px, so a skipped row keeps the height it last rendered at and the scrollbar does not move. The 600 px estimate only applies to a row that never rendered.
    • A row is skipped only after it has stayed distant for two frames, once the engine has recorded its size.
    • Whenever rows are skipped or released, the first visible row is held in place through the existing autoscroll owner. A reader pinned to the bottom stays pinned, and a reader scrolled up does not jump when old rows re-wrap at the new width.
    • Skipped rows get flex-shrink: 0: Chromium otherwise shrinks a size-contained flex item below its remembered height.
    • Rows that own horizontal scroll range, and rows with numbered equations (their counters run across messages), are never skipped. Print shows every row.
    • Select All (Cmd/Ctrl+A outside an input) releases every skipped row through the same anchored path first, so the reader does not jump when the browser lays them out to select them.
  • message-row-containment*.ts: gated like the existing containment flags, so it can be turned off at runtime with __UNSLOTH_MESSAGE_ROW_CONTAINMENT__. On in Chromium (Windows WebView2) and Safari 26+. Off on Linux WebKitGTK, where message-window-controller.ts (Studio: reduce long-chat panel and scrolling lag on Linux #16854) already parks distant rows.
  • code-fence-defer.tsx: the idle highlighter ranks fences inside a skipped row by the row's box instead of the fence's. Reading the fence forced Chromium to lay out the skipped row on every idle pass.

Results

Local, 150 turns (300 messages), base and head interleaved, 3 runs x 3 toggles, median [min-max] ms:

Engine Measure main This PR
WebKit (mac UA) Pane open, longest frame 749 [719-1645] 96 [65-342]
WebKit (mac UA) Pane open, total time in frames over 50 ms 1484 309
WebKit (mac UA) Pane close, longest frame 702 [671-725] 68 [53-170]
Chromium Pane open, longest frame / layout 133 / 123 33 / 25
Chromium Pane close, longest frame / layout 133 / 80 17 / 14
Chromium Forced layout when the column halves 97 4

Real GitHub runners, 150 turns, both arms on the same runner per rep (2 reps, alternating order):

Engine Measure main This PR
macOS WebKit (macos-15) Pane open, total (longest frame) 1463 (990) / 1625 (968) ms 699 (299) / 751 (326) ms
macOS Chromium Pane open, longest frame 333 / 317 ms 100 / 133 ms
Edge (windows-latest) Pane open, longest frame 233 / 217 ms 83 / 83 ms
Edge Pane layout, open / close (trace) 342-350 / 350-387 ms 57-62 / 44-55 ms

Typing, scrolling and Settings open/close are unchanged within noise on all three engines, and nothing got worse by more than 1.5x in both reps. Screenshots of the thread and the pane match main apart from sub-pixel text antialiasing.

Locally, typing is unchanged: WebKit p50/p95 24/32 vs 27/33 ms, Chromium 12/24 vs 13/23 ms. Scrolling p50 is unchanged in both engines. WebKit scroll p95 read 26 vs 32 ms, inside this host's run-to-run spread.

Behaviour (WebKit with a mac UA and Chromium, main vs this PR)

  • Scrolling up on a tall window (1400x2200) while older messages are still mounting, after narrowing the column: no jumps from this change in Chromium or WebKit (a 106 px shift on user messages also happens on main).
  • Pinned to the bottom after load and after opening the pane: 0 px in both, 12 of 12 loads and 6 of 6 pane toggles.
  • Scrolling up with the pane open through rows last laid out at the wider width: the first visible row moves at most 0.2 px (WebKit), and Chromium matches main.
  • The find bar finds text in an old offscreen message in both engines. Select all and copy give the same character count.
  • Expanding a tool block in an old message, jumping to a skipped message, and printing all behave as on main.
  • Streaming a reply (WebKit, mock server): the view stays pinned to the bottom, as on main.
  • Screenshots at the bottom of the thread are pixel-identical in WebKit.

Not covered: Select All from a menu (not the keyboard) while scrolled up after the column narrowed can still jump once, since releasing every row on each selectstart would re-wrap the thread on every mouse selection; an old row that starts overflowing horizontally only after the column narrows adds its scroll range once it comes within reach, not while it is far away; real Safari / WKWebView and the desktop shells (local WebKit is WebKitGTK with a mac UA); streaming in Chromium; dragging the scrollbar or jumping more than 1500 px into rows skipped at a different width, which can show their re-wrap.

Tests

  • New tests/message-row-containment.test.ts (13 tests); turning off the hold-in-place, the Select All release, the numbered-equation exemption, or pinning the reach to 1500 px makes them fail.
  • math-block-containment-wiring.test.ts counts the new content-visibility: auto rule.
  • Long-chat gate (Studio CI: long-chat gate measures every interactive area under every appearance mode #16931): PASS. Full frontend suite passes except the KaTeX stylesheet test that also fails on main with a symlinked node_modules. node scripts/typecheck.mjs --tests is clean.

…t on long chats

Opening the browser pane halves the chat column, and every message in the
thread re-wrapped at the new width. At 150 turns that was a 0.7-1.5 s frame
on WebKit and 130-170 ms on Chromium, for both open and close.

Message rows far from the viewport (beyond 1500 px) are now marked by an
IntersectionObserver and skipped with content-visibility: auto. Every row
records its rendered size through contain-intrinsic-size: auto, and a row is
marked only after it has stayed distant for two frames, so a skipped row
keeps its real height and the scrollbar does not move. Marking or releasing
rows keeps the first visible row in place through the autoscroll owner, so a
row released at a different width (after the pane opened) never moves the
reader, and a following reader stays pinned to the bottom.

Gated like the existing containment flags: on where the engine finds skipped
content (Safari 26+, Chromium), off on WebKitGTK where the message windowing
already parks distant rows, overridable with
__UNSLOTH_MESSAGE_ROW_CONTAINMENT__ / VITE_UNSLOTH_MESSAGE_ROW_CONTAINMENT.
Print renders every row. Distant rows are flex items, so they must not shrink.

The idle code fence ranking now reads the box of a skipped row instead of
each fence inside it; reading the fence forced a layout of the skipped row
per fence (180 forced style updates per idle pass on Chromium).
@chatgpt-codex-connector

Copy link
Copy Markdown
Codex Review Summary: ❌ Failed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ❌ Failed 2026-11-07T03:48:53.507100Z
We couldn’t complete this review. Comment @codex review to try again.
b21beec PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, add credits to your account and enable them for code reviews in your settings.

…ll windows

Chromium renders a content-visibility: auto element again once it is within
150% of the window height of the window (kViewportMarginPercentage in
display_lock_document_state.cc); WebKit only once it intersects
(ContentVisibilityDocumentState.cpp, no root margin). On a tall window the
fixed 1500 px reach was inside Chromium's margin, so after the browser pane
narrowed the column a skipped message re-wrapped before the observer released
it, outside the anchor correction. With native scroll anchoring off (as while
older messages still mount), scrolling up then jumped.

The reach is now max(1500, 2 x window height), and the observer is recreated
with the new reach when the window height changes (once per change, keeping
every observed message). The fence speculation wiring test follows the
ranking line it pins.
Containment on a message row scopes the KaTeX equation counters to it,
so skipping a distant row with numbered equations renumbered the
equations in later messages. Keep such rows laid out, the same
exemption math-block-marker.ts gives a single math block.
Select All lays out every skipped message at once in WebKit; a reader
scrolled up after the browser pane narrowed the column jumped by the
height the old messages gained. Release them through the anchored path
on the select-all keydown, before the browser picks its range, as
message-window-controller.ts already does for parked rows.
Like data-reply-paint, it marks messages far from the viewport, carries
no content and depends on scroll position, so it is not thread structure.
Every message read 18 characters longer at 100K, the attribute name.
@danielhanchen
danielhanchen merged commit 3d41bf4 into main Nov 7, 2026
@danielhanchen
danielhanchen deleted the studio-pane-rewrap branch November 7, 2026 06:15
danielhanchen added a commit that referenced this pull request Nov 7, 2026
…t is 26.04 (#16987)

## Summary

`Chat UI Tests (chat)` and `Loaded-models indicator (cross-browser)` are
red on main (run 42338613438) and on #16986, #16984 and #16973, all in
the same step:

```
Image: ubuntu-26.04
Version: 20261101.186.1
...
engines that will not start: webkit: TargetClosedError
system libraries are missing, installing them
...
engines that will not start: webkit: TargetClosedError
##[error]Process completed with exit code 1.
```

`ubuntu-latest` is being moved to the ubuntu-26.04 image. Playwright
1.64.1's WebKit build exits at launch there, and `playwright
install-deps` does not fix it, so the browser probe in "Install
Playwright browsers" fails before any test runs. Chromium and Firefox
start fine. The last green runs of the same jobs ran on ubuntu-24.04
(for example 42319231838, 42313662909, 42311916438, all today), so the
image is the only thing that changed. As the rollout reaches more jobs,
every Linux job that drives WebKit will hit this.

## Change

- `studio-ui-smoke.yml`: `ui-smoke` (Chat UI Tests) and `ui-indicator`
(Loaded-models indicator) run on `ubuntu-24.04`.
- `studio-composer-compatibility.yml` and `studio-inline-images.yml`:
the `ubuntu-latest` matrix leg runs on `ubuntu-24.04` through `runs-on:
${{ matrix.os == 'ubuntu-latest' && 'ubuntu-24.04' || matrix.os }}`. The
matrix value is unchanged, so the check names (`Composer (ubuntu-latest,
browsers)`, `Inline images (ubuntu-latest)`) stay the same; macOS and
Windows legs are untouched.
- Each pin carries a comment to move back once WebKit starts on 26.04.
- `tests/studio/test_webkit_jobs_skip_ubuntu_latest.py`: finds every
workflow job whose steps or matrix mention WebKit, resolves the images
it lands on (a plain `runs-on`, `matrix.os`, or the mapped form above),
and fails if any of them is `ubuntu-latest`. A job counts when its steps
or matrix mention Playwright and `webkit` as a whole word, so a file
name like this test's does not. It also checks it still sees the four
jobs above, so it cannot pass by finding nothing.
- `workflow-trigger-lint.yml`: the new guard runs in that job too, since
it is the one job without a paths filter
(`test_workflow_guards_run_unfiltered.py` requires this of every
workflow-reading guard), so a PR that only edits workflows still meets
it.

## Testing

| | guard test |
|---|---|
| this branch | passes |
| main's three workflow files with this test | fails, naming
`studio-composer-compatibility.yml::composer`,
`studio-inline-images.yml::images`, `studio-ui-smoke.yml::ui-smoke`,
`studio-ui-smoke.yml::ui-indicator` |

The new test plus `tests/studio/test_workflow_guards_run_unfiltered.py`,
`test_ui_shard_engines.py`,
`test_indicator_browsers_run_in_parallel.py`,
`test_playwright_suites_run_in_ci.py`,
`test_chat_ui_shards_cover_everything.py` and
`tests/security/test_lint_workflow_triggers.py`: 240 passed.

End to end, the same probe on the two images:

| | probe before install-deps | probe after install-deps | job |
|---|---|---|---|
| main, `ubuntu-26.04` (run 42338613438) | webkit: TargetClosedError |
webkit: TargetClosedError | failed |
| this PR, `ubuntu-24.04` | webkit: TargetClosedError | all three
engines launch | `Loaded-models indicator (cross-browser)` passed |
danielhanchen added a commit that referenced this pull request Nov 9, 2026
… WebKit (#17035)

## Problem

On long chats in WebKit (macOS Safari / WKWebView), opening or closing
Run settings costs 3-4x what it costs on a short chat (real `macos-15`
runners at 150 turns: longest frame 120-159 ms against 32-49 ms). The
sidebar toggle grows the same way (120-245 ms against 35-46 ms).

At 1440 px the sheet does not re-wrap anything: the message column is
capped at 744 px and stays 744 px when the chat area narrows from 1160
to 888 px. Only 3 of 300 rows are in layout in WebKit (7 in Chromium)
after #16986. The cost that grows with the chat comes from the
autoscroll owner instead:

- Any width change of the chat column opens a follow window, and the
owner flips `data-aui-following` on at the start and off in the settle
tail about 600 ms later.
- The flag sat on the hidden portal host, and `index.css` reached the
viewport through it: `.aui-thread-host[data-aui-following] +
.aui-thread-root .aui-thread-viewport`. For a rule that reaches its
subject through a sibling and then a descendant combinator, WebKit
invalidates every descendant of the host's later siblings, which is the
whole thread.
- The flip runs inside the autoscroll tick, and the tick reads
`scrollHeight` right after, so the restyle is forced there: 40-70 ms per
flip at 150 turns against 1-4 ms at 1 turn, twice per toggle (once in
the opening frame, once in the settle tail).

Chromium only restyles the viewport for the same rule (2.6 ms per flip
at 150 turns), which is why Chromium and Edge were already close to
flat.

## Fix

- `use-intent-aware-autoscroll.tsx`: the flag is set on the viewport
itself (the element the hook already owns), through one `setFollowing`
helper used by the tick, the idle frame and teardown.
- `index.css`: the rule matches the flag on its subject,
`.aui-thread-viewport[data-aui-following] { overflow-anchor: none; }`.
Same property, same element, same window as before, so scroll anchoring
behaves as it did.
- `thread.tsx`: drops the now unused `markerRef` from the portal host.

## Results

Local, Playwright WebKit with a macOS user agent and Chromium, 1440x900,
1 and 150 turns (300 messages, 57k nodes). Arms interleaved per rep:
`main`, a second build of `main` served by a separate server (A/A), and
this PR. 5 runs x 3 toggles per cell, median [min-max].

Cost of one flag flip (forced style + layout, 16 flips per cell, the
element each build's hook writes):

| Engine | Turns | main | main (A/A) | This PR |
|---|---|---|---|---|
| WebKit (mac UA) | 150 | 56.5 ms [31-261] | 62 ms [43-111] | 4 ms [3-9]
|
| WebKit (mac UA) | 1 | 4 ms [1-86] | 2 ms [1-112] | 1 ms [0-3] |
| Chromium | 150 | 2.6 ms [1.5-11.5] | 4.7 ms [1.6-25.5] | 0.1 ms
[0-1.1] |
| Chromium | 1 | 0.1 ms | 0.1 ms | 0.0 ms |

Script time inside animation frames during a toggle (the autoscroll
ticks, where the restyle is forced), WebKit:

| Surface | Turns | main | main (A/A) | This PR |
|---|---|---|---|---|
| Run settings open | 150 | 141 [82-646] | 173 [123-555] | 16 [1-80] |
| Run settings close | 150 | 142 [103-1068] | 184 [104-3010] | 17
[4-175] |
| Run settings open / close | 1 | 8 / 9 | 7 / 6 | 5 / 5 |
| Browser pane open | 150 | 288 [153-686] | 346 [62-927] | 138 [0-600] |
| Browser pane close | 150 | 311 [8-1803] | 359 [2-571] | 266 [0-1436] |

Long / short ratio of that script time: Run settings 15.8-30.7x on
`main` (both builds), 3.2-3.4x with this PR.

Chromium, style / layout thread time from a trace of one open + close at
150 turns: Run settings 28.0 / 5.8 ms (`main`), 14.9 / 6.0 ms (A/A),
16.7 / 5.6 ms (this PR), against 13-15 / 2.5 ms at 1 turn. Browser pane
73 / 101, 51 / 77, 52 / 68 ms (about 45-51 / 46-50 ms at 1 turn).
Elements restyled per toggle are the same in all arms (418-422 for Run
settings). Chromium was already close to flat, and this PR keeps it
there.

Longest frame (ms, median [min-max]):

| Engine | Surface | Turns | main | main (A/A) | This PR |
|---|---|---|---|---|---|
| WebKit | Run settings open | 1 / 150 | 132 / 197 | 104 / 178 | 182 /
219 |
| WebKit | Run settings close | 1 / 150 | 79 / 177 | 149 / 233 | 127 /
227 |
| WebKit | Browser pane open | 1 / 150 | 636 / 444 | 260 / 535 | 364 /
881 |
| WebKit | Browser pane close | 1 / 150 | 201 / 200 | 124 / 230 | 145 /
462 |
| Chromium | Run settings open | 1 / 150 | 50 / 167 | 67 / 83 | 50 / 150
|
| Chromium | Run settings close | 1 / 150 | 67 / 167 | 67 / 67 | 67 /
183 |
| Chromium | Browser pane open | 1 / 150 | 100 / 167 | 100 / 183 | 100 /
183 |
| Chromium | Browser pane close | 1 / 150 | 100 / 117 | 67 / 117 | 83 /
217 |

The longest-frame numbers do not separate the arms. This host ran at a
load average of about 390 on 49 cores, the two `main` builds differ by
up to 2x in the same cell, and Chromium traces show single style passes
of 541 ms wall time for 9 ms of thread time. The table is here for
completeness. The flip cost and the script time above are the
measurements that hold up on this host.

What else runs during a toggle at 150 turns (WebKit, after this PR):

- Rows re-wrapped: Run settings, none at 1440 px (column stays 744 px).
Browser pane, the 3 rows in layout (744 -> 580 px); the other 297 stay
skipped. No rows were skipped or released during a toggle at the bottom
of the thread, so the `distant-rows.ts` anchor correction did not run.
- Forced layouts in ResizeObserver callbacks during a pane open: the
side-panel inset observer, the resizable panel group observer, the code
block `data-scrolls-x` check and the thread width steps observer. Median
98-120 ms at 150 turns and 52-61 ms at 1 turn in all three arms; they
are where the per-frame layout of the pane's 260 ms flex-basis
transition gets forced. Run settings fires none of them.
- The sheet has no animation: its width goes from 0 to its full size in
one commit, so the chat re-wraps once. The browser pane does animate
`flex-basis`. Turning that transition off locally did not make WebKit
cheaper at 150 turns (longest frame with it off: open 684 ms, close 334
ms; with it on: 459 ms and 257 ms; within noise), so this PR leaves it
alone.

## Behaviour

Main and this PR, WebKit (mac UA) and Chromium, 150 turns:

- Pinned to the bottom: 0 px from the bottom after every Run settings
and browser pane toggle in both arms (WebKit 5 of 5 runs). The viewport
computes `overflow-anchor: none` while following and `auto` after the
window closes, in both arms and both engines.
- Scrolled up 3000 px: the first visible row moves 0.0 px when Run
settings opens or closes, in both arms and both engines. The browser
pane moves it by 24 px (47 px when pinned), identically on `main`.
- Screenshots with the sheet and the pane open and closed, at the bottom
and scrolled up: 14 of 16 pixel-identical between `main` and this PR,
all 8 WebKit ones included. The other two (Chromium, pane closed) differ
in a 1-2 px wide strip of glyph antialiasing at a line end.

## Tests

- New `tests/thread-follow-flag-selector.test.ts` (3 tests): the flag is
matched on the viewport as the subject, the hook writes it on the
viewport through one setter, and no thread rule reaches the viewport
through an attribute on a sibling. All 3 fail on `main`.
- `npm test`: 15160 passed, 1 failed. The failure is the KaTeX
stylesheet Vite test, which also fails on `main` with a symlinked
`node_modules`.
- `node scripts/typecheck.mjs --tests`: clean.
- Long-chat gate (`tests/studio/playwright_long_thread_gate.py`): PASS.
Its `run_settings` area restyles 571 -> 1,217 elements from 40 to 200
turns, the same as other trees from today (567-577 -> 1,209-1,216).
- `tests/studio/test_autoscroll_harness_contract.py`: 16 passed.
`tests/studio/playwright_chat_autoscroll.py` fails the same way on
`main` and on this PR on this host ("the content did not grow while
detached; the re-pin check proved nothing").

## Not covered

- Real Safari / WKWebView on macOS and the desktop shells. Local WebKit
is WebKitGTK with a macOS user agent. The invalidation that made the
flip expensive is shared WebCore code, but the frame-level win on a real
Mac was not measured.
- Frame-level gains on this host: the longest frame stays within the A/A
spread. A rerun of the menu bench on `macos-15` runners would settle it.
- Windows WebView2 and Linux WebKitGTK were not run. Edge uses the same
Blink invalidation as Chromium (already cheap here), and WebKitGTK parks
distant rows through `message-window-controller.ts`.
- Windows narrower than about 1300 px, where opening Run settings does
narrow the message column and re-wrap the rows in layout: not measured.
- Streaming: the flag flips at the start and end of every follow window
during a reply too. That path uses the same setter but was not measured
here.


## Real macOS runner check

`macos-15`, current main vs a second build of the same main (A/A) vs
this PR merged onto main, 150 turns, 4 reps in balanced order, all built
== served.

- WebKit max frame: Run settings, sidebar toggle and browser pane are
within the spread between the two main builds (A/A per rep 0.51-3.34x on
the same runner). No surface is worse beyond that spread in more than 2
of 4 reps, and the tools menu control behaves the same. So on real macOS
the per-flip saving does not show up at frame level; it removes a
whole-thread restyle per flip without a measurable cost.
- Chromium: style time for opening the sidebar is 0.39-0.61x of main in
every rep, and Run settings open style time and close max frame improve
beyond A/A in 3 of 4 reps.
danielhanchen added a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Nov 9, 2026
unslothai#17282)

## Problem

Opening or closing the browser pane in a long chat still cost far more
than in a short one, worst on macOS WebKit (Round 11 real runners: open
460 to 562 ms at 150 turns against 144 to 165 ms at 1 turn). unslothai#16986
already keeps distant rows out of layout; this PR removes the per-frame
work that remained.

## Causes

- The pane's open and close slide the chat column's width over 260 ms,
and every frame of the slide re-wraps every row still inside the layout
reach around the reading position. Turning only the slide off cut
slow-frame time on macOS WebKit from 401 to 549 ms to 312 to 354 ms.
- The side-panel inset lookup in `chat-page.tsx` used
`root.querySelectorAll(":scope > [data-side-panel-inset]")`, which
matches against every node below the root (about 57,000 elements in a
150-turn chat), and the resize observer ran it on every frame of the
slide: the largest single per-open cost in the Chromium profile (about
25 ms).
- `dismiss-click-streak.ts` ran a descendant selector for an open menu
against the whole document on every press anywhere: about 10 ms per
click at 150 turns.

## Change

- The inset lookup reads the root's direct children.
- The press check first looks for a Radix popper wrapper and only runs
the menu selector when one exists; the result is identical.
- A chat taller than the layout reach (viewport plus 2x `rowReachPx`,
about 4,500 px on a 900 px window) takes the pane's new width in one
step (`data-artifact-layout-instant`); shorter chats keep the slide. The
attribute is set or cleared on every open and close.

## Look

In long chats only, the chat column snaps to its new width instead of
sliding when the pane opens or closes. The pane's own entrance is
unchanged, and the end state is the same. The Linux desktop app already
resized in one step and is untouched. Reading position through open and
close (Chromium, 150 turns): at the bottom it stays at the bottom, as on
main; mid-chat the top message moves 5 px (146 px on main).

## Results

Real runners, 1 vs 150 turns, main measured twice (A/A), interleaved:

| 150 turns | main | main (A/A) | this PR | 1 turn |
| --- | --- | --- | --- | --- |
| macOS WebKit, slow-frame time on open | 332 ms | 288 ms | 150 ms | 0
ms |
| macOS WebKit, longest frame on open | 92 ms | 80 ms | 98 ms | 43 ms |
| macOS Chromium, open layout / style | 20 / 23 ms | 18 / 26 ms | 10 /
15 ms | 7-9 / 16-20 ms |
| Windows Edge, open layout / style | 45 / 55 ms | 47 / 56 ms | 28 / 33
ms | 22 / 40 ms |
| Windows Edge, close layout | 32-40 ms | 39-49 ms | 9-16 ms | |

The Windows result held on two runners; the macOS result is one runner
with three interleaved reps (the head's worst rep, 291 ms, overlaps the
A/A range). The longest single frame is within noise.

Not addressed: the first pane open of a session on macOS WebKit still
costs about 350 to 560 ms; it is not code loading or row layout
(prefetching and hiding every row did not remove it), most likely
garbage collection over a long chat's heap.

## Tests

- New `tests/dismiss-click-streak.test.ts` case (fails on main) and
`tests/browser-pane-open-cost.test.ts` source checks for the inset
lookup and the one-step rule.
- Frontend node suite 15,326 pass, `tsc --noEmit` clean; the long-chat
gate passes.

---------

Co-authored-by: Nilay Yadav <[email protected]>
iam-knoit pushed a commit to SynhalaAI/unsloth that referenced this pull request Nov 10, 2026
…#17351)

## Problem

On Chromium (Chrome, Edge, the Windows app's WebView2), opening a long
chat often lands far above its latest message: 4,000 to 23,000 px up,
and it stays there. On main, in a Playwright harness with a 200-turn
chat, 3 to 6 of 10 fresh loads and 3 to 4 of 10 switches from the
sidebar ended up off the bottom; with the CPU throttled 4x, 6 of 18.
WebKit was not affected (0 of 60).

Nothing in the page scrolls the thread when it happens (no input, no
programmatic scroll). While older messages mount, the autoscroll hook
holds the chat at its bottom. Then Chromium moves `scrollTop` up by
about 259 px while `scrollHeight` reads unchanged at the scroll event: a
row that `distant-rows.ts` (unslothai#16986) skips or releases
(`data-row-distant`) at the bottom clamps the scroll position. The hook
reads an upward move from the bottom with no height change as the user
scrolling up and stops following, and every later batch of mounted
messages keeps that offset.

Forcing `content-visibility: visible` on message rows alone removes it
(0 of 8); doing the same for code fences, reasoning or maths, or turning
off smooth scroll, scroll anchoring or composer focus does not.

## Change

`use-intent-aware-autoscroll.tsx` only:

- The hook's MutationObserver also watches `data-row-distant`; a record
for it marks that rows toggled since the last scroll event.
- An upward move from a pinned bottom counts as a clamp, not the user,
when the scroll height changed (as before) or rows toggled since the
last scroll event, still only with no scroll key and no held pointer.
- Wheel and touch still stop following in their own handlers, and PageUp
/ ArrowUp / Home still count as the user.

## Results

Same harness (production build, no input sent, distance from the bottom
5 s after all rows mounted), 200-turn chat, then sidebar switches to a
150-turn chat and back. Main ran twice as an A/A control:

| Arm | Fresh load of the 200-turn chat | Switch to the 150-turn chat |
Switch back to 200 |
|---|---|---|---|
| main | 4 of 10 off (8,543 to 23,046 px) | 3 of 10 (2,329 to 14,755 px)
| 4 of 10 (14,401 to 24,547 px) |
| main again (A/A) | 2 of 9 (12,684, 16,824 px) | 4 of 9 (6,460 to
14,756 px) | 4 of 9 (6,213 to 20,957 px) |
| this PR | **0 of 10** | **0 of 10** | **0 of 10** |

Chromium, 2 rotated rounds of 5 per arm. An earlier run with 10 loads
per arm, also on WebKit (Mac UA) and with a 4x CPU throttle, read the
same way: main 14 and 10 of 30 off, this PR 0 of 30; throttled main 6 of
18, this PR 0 of 18; WebKit 0 everywhere.

- A reader who scrolls up (wheel or PageUp) still stays where they left
it 5 s later, on Chromium and WebKit, same as main.
- Long-chat gate passes on this branch.

## Tests

- `tests/chat-autoscroll-shrink-intent.test.ts`: new test for the row
toggle case; `tests/desktop-webkit-paths.test.ts` updated for the
observer signature. The related autoscroll suites (81 tests) pass; `tsc
--noEmit` clean.
- Not measured: real Safari / Edge / Chrome on macOS and Windows and the
desktop apps (Edge and WebView2 share Chromium's behaviour); dragging
the scrollbar (a held pointer already keeps the old path).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant