Skip to content

Studio CI: long-chat gate measures every interactive area under every appearance mode - #16931

Merged
danielhanchen merged 6 commits into
mainfrom
studio-gate-appearance-matrix
Nov 6, 2026
Merged

danielhanchen merged 6 commits into
mainfrom
studio-gate-appearance-matrix

Conversation

@danielhanchen

@danielhanchen danielhanchen commented Nov 6, 2026 •

Copy link
Copy Markdown
Member

Extends the long-chat CI gate from #16801 / #16902 so it also catches lag in every interactive area, and a new feature or appearance setting that is itself slow (the way Glass shipped).

What it measures

After the existing long-chat checks (unchanged), on the Linux Frontend CI lane in Chromium, the gate opens the real /chat page from the same production build with every /api call answered in-process, seeded with 40 and 200 turns of a fixed agent turn (reasoning, web search, tool calls, code, long reply).

  • 30 areas: typing and scrolling the chat; Settings, every Settings tab (read from the page), a Settings dropdown and scrolling inside Settings; command palette, search chats, model picker; composer, tools, permission, chat options, account, organize and chat row menus; sidebar sections and toggle; browser pane; run settings; API monitor; rename; shortcuts dialog; message action menu, copy, click, reasoning and tool expand/collapse, code copy and source card.
  • Appearance modes are read from the app's own material and lens lists, so a new material is measured with no gate edit: default, Transparent, frosted, blurred, liquid, liquid-3d, macOS, both lens modes, Glass menus off, dark and dark Glass.
  • One Chromium trace per page, split per area: elements restyled and layout objects (exact counts), style, layout and paint time, longest task, and CPU time on every browser thread.

When it fails

  • An area's restyle or layout count grows more than 2x from 40 to 200 turns (counted above 3000 elements).
  • A mode makes an area cost more than 4x its baseline in CPU or elements restyled (baseline = default look; lens, menus-off and dark Glass are compared with plain Glass), with at least 150 ms extra CPU.
  • An area stops running.
  • Coverage: every visible menu or popup trigger on the chat page must belong to an area or be listed with a reason, and a unit test requires every keyboard shortcut to map to an area or a stated reason.

CPU and "did not run" failures are measured again on fresh pages before they count, and the worst CPU failure is re-run with backdrop-filter, box-shadow and filter switched off in turn to name the property responsible. All thresholds can be overridden with LONG_THREAD_AREAS_* environment variables.

CSS lint for whole-chat :has() rules

Runs first (about 1 s): reads every rule in the built CSS and flags selectors where :has() is followed by a combinator (X:has(...) Y, X:has(...) > Y, including Tailwind group-has-*). Those make any change under the anchor re-check every matching element in the chat. The 118 such selectors on main today are listed in tests/studio/has_subject_allowlist.txt until they are rewritten; a new one fails with the selector and its likely source, and selectors that disappear are reported so the list can be pruned (LONG_THREAD_HAS_LINT_WRITE=1 regenerates it).

The nine known whole-chat areas also get a fixed ceiling on elements restyled at 200 turns, about 1.2x today's count, so they cannot get worse; deleting an area's entry restores the normal 2x growth check once it is fixed.

Evidence

Build Verdict
main, repeated runs PASS (3 local, 2 on a 4-CPU machine)
main with the existing-cost allowances removed FAIL: the same 9 areas every run, plus 13 to 22 Glass cells
synthetic [data-wallpaper-workspace]:has(> [data-gate-synthetic]) .aui-thread-viewport [data-role] rule FAIL: the lint names it; chat options restyles 56,135 elements against its 17,000 ceiling, chat row menu 68,522 against 32,000
synthetic slow build: a new "aurora" material with a large blur and shadow, plus #16902's thread protection removed FAIL: aurora on 6 to 8 areas with backdrop-filter named as the cause (0.05x without it); 8 modal areas grow 3.8 to 4.3x with chat length; the existing lock check fails too

Existing costs the gate found on main are allowed explicitly with ceilings about 1.2 to 1.3x above the highest reading, so they cannot get worse and can be tightened as they are fixed (LONG_THREAD_AREAS_KNOWN="" holds main to the plain limits):

  • Nine areas restyle the whole chat when they open (model picker, browser pane, run settings, sidebar sections, sidebar toggle, organize chats, account menu, chat row menu, chat options): 4 to 8k elements at 40 turns, 14 to 37k at 200, 250 to 500 ms of style work per open. A follow-up removes the CSS rules responsible.
  • Glass: Settings scrolling costs 10 to 22x the solid window in CPU, most other areas 2 to 6x.

Cost

About 4 to 6 minutes added on a GitHub runner (6.1 min on a machine pinned to 4 CPUs, 3.8 min on a fast host), inside the step's existing 15-minute timeout. The step only runs when frontend or gate files change. LONG_THREAD_AREAS_LONG_MODES=default trims about 10%; LONG_THREAD_AREAS_FULL=1 runs the full product (12 modes x 30 areas x 2 lengths).

Files

  • tests/studio/_area_matrix.py (new): areas, modes, trace split, thresholds, culprit check.
  • tests/studio/test_area_matrix.py (new, 14 tests): registries, shortcut coverage, threshold logic.
  • tests/studio/playwright_long_thread_gate.py: runs the matrix after the existing checks.
  • studio/frontend/vite.long-thread.config.ts: also builds index.html for the real chat page.
  • tests/studio/_has_lint.py, tests/studio/test_has_lint.py, tests/studio/has_subject_allowlist.txt (new): the :has() lint.
  • .github/workflows/studio-frontend-ci.yml: path filters and the unit tests.

…ength in the long-chat gate

The long-chat gate only measured typing in the default appearance, so Glass shipped with menus,
dialogs and scrolling several times slower and nothing failed. On Linux the gate now also opens
the real chat page from the same production build, with every /api call answered in-process,
seeded with a 40-turn and a 200-turn agent chat, and runs every interactive area: typing,
scrolling the thread, Settings and every Settings tab, a Settings select and scrolling inside
Settings, the command palette, chat search, model picker, composer, tools, permission, chat
options, account, organize and chat row menus, the sidebar sections and toggle, the browser
pane, run settings, the API monitor, rename, the shortcuts dialog, and the message controls
(action menu, copy, click, reasoning and tool blocks, code copy, source cards). Each area runs
under the default appearance and every appearance mode read from the app's registries (each
window material incl. Transparent, lens modes, glass menus off, dark).

One Chromium trace per page, split per area by console.timeStamp marks, gives elements
restyled, layout objects, style/layout/paint ms, the longest task and the CPU of every browser
thread. The gate fails when an area restyles or re-lays out more as the chat grows (2x), when a
mode makes an area cost more than 4x the default (CPU, or elements restyled), when an area no
longer runs, and when a popup trigger on the chat page or a keyboard shortcut belongs to no
area. CPU failures are measured again on fresh pages first; the worst one is re-run with
backdrop-filter, box-shadow and filter switched off to name the property responsible. What main
already costs (glass raster, nine areas that restyle the whole thread) is listed with ceilings
so it cannot get worse.
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 6, 2026 •

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-06T19:00:05.715907Z
We couldn’t complete this review. Comment @codex review to try again.
ad749c8 Manual request
ℹ️ 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.

…e counts of known whole-chat areas in the long-chat gate
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Nov 6, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Nov 6, 2026
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Nov 6, 2026
…tings panel, measure owner tabs

A worker that hit an error after its page loaded (a closed target, a crashed browser) let the
exception escape its thread, so measure() returned fewer pages than planned and judge() only
looked at the ones that existed: with every page closed before its sweep the gate passed with
nothing measured. Each page's failure is now recorded as that page's error, a worker that dies
reports every page it owed, any planned page without a result is an error, a sweep that fails
part way ends its browser-wide trace so the next page can start its own, and a missing default
page fails the popup coverage check instead of emptying it.

The Settings tab sweep moved on after two frames, but panels mount lazily behind
useDeferredValue and Suspense, so a slow panel could be skipped while the area read OK. The
dialog's pane now carries data-settings-panel (the panel it has committed) and the error
boundary data-settings-panel-failed; the sweep waits for each tab's panel inside the measured
window and fails the area when one never commits, fails, or fewer tabs render than the app
defines.

The stub session token had only `exp`, so sessionAccount() found no account and five
owner-only tabs (Accounts, Resources, Remote LAN, Agents, Debugging) were hidden. It now carries
sub "unsloth" and role owner, and all 18 tabs are measured.
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Nov 6, 2026
…s messages for real; :has() lint skips pseudo-class arguments

Shortcut-driven areas waited only for a settle, and a key press always succeeds, so an ignored
shortcut still read OK. The sidebar toggle now waits for the sidebar's data-state to flip and
flip back, the API monitor for its panel to appear and go, and rename for its dialog to open and
close. Every area's close is now checked as well: one that opened but never closed reads NOT_RUN.
With those three shortcuts suppressed in the page, all three areas now fail.

message_click dispatched constructed events, which move no focus, so the action bar's focus
reveal was never measured. It now uses a trusted click and waits for a focusin inside the
message; with the old dispatched click the area fails.

The :has() lint read the `+` in `:nth-child(2n+1)` as a sibling combinator, so a subject :has()
followed by an nth pseudo-class would have failed CI. Arguments of functional pseudo-classes
other than the selector-taking ones are now skipped as a unit. Main's count is unchanged (118).
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

…area matrix

When Chromium's trace buffer filled, later areas lost their begin or end marks, split_trace()
returned no counters for them, the area kept its OK status with an empty row and judge() read
zeros. Tracing.tracingComplete's dataLossOccurred was ignored as well.

The trace now records as much as possible into a 256 MB buffer
(LONG_THREAD_AREAS_TRACE_BUFFER_KB), well above a 200-turn sweep. Data loss voids the page: it
is measured once more on a fresh page and, if the trace is lost again, reported as that page's
error. An area that ran but has no complete begin/end window is NOT_RUN, so on the default page
it fails the gate and in a mode it fails as broken. With a 512 KB buffer the loss is reported;
with the default no page lost data on main.
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Nov 6, 2026
…ide its Suspense boundary

data-settings-panel sat on the pane outside <Suspense>, so it named the selected tab even while
the Loading fallback showed, and the gate's tab sweep accepted a panel that had not loaded.

The marker is now a hidden, empty element (data-settings-panel-ready) rendered by the resolved
panel subtree itself, inside Suspense, so the fallback removes it until the panel commits. An
effect on the pane would not do: on first open the pane's ref is attached after the panel's
layout effects run, so the first panel was never marked. The sweep waits for this marker. With
every lazy panel module held pending, all 18 tabs now report as not committed instead of OK.
@danielhanchen
danielhanchen merged commit 66bc1c9 into main Nov 6, 2026
@danielhanchen
danielhanchen deleted the studio-gate-appearance-matrix branch November 6, 2026 21:42
danielhanchen added a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Nov 7, 2026
…the browser pane open or close (unslothai#16961)

## Problem

On long chats in WebKit (the macOS app, and the Linux app's WebKitGTK),
closing any dialog or menu took 5 to 7 seconds, and on Linux WebKit the
browser pane took over 20 seconds to open. Chromium (Windows) was not
affected.

WebKit restyles every element on the page when certain document-level
listeners or stylesheets change:

| Side effect (Playwright WebKit, 1 -> 100 turns) | WebKit | Chromium |
|---|---|---|
| Add / remove a non-passive `wheel` or `touch*` listener on document |
27-38 ms -> 2.6-2.8 s | 0 |
| Add / remove a `pointermove` / `pointerleave` listener on document |
25-35 ms -> 2.6-2.7 s | 0.1 ms |
| Remove an injected `<style>` | 60 ms -> 2.95 s | 11 ms |
| Body `data-scroll-locked`, `pointer-events`, `aria-hidden`, focus
restore | under 100 ms | under 4 ms |

Three things hit those paths:

- Radix's scroll lock (`react-remove-scroll`) adds non-passive wheel and
touch listeners on the document when a dialog or modal menu opens and
removes them on close, and `react-remove-scroll-bar` removes its
injected stylesheet on close.
- Closing a dialog while focus is still inside it during the exit
animation (Settings, command palette, search, rename, shortcuts) costs
one more full pass.
- `react-resizable-panels` removes and re-adds its document pointer
listeners each time the chat's panel group re-registers, which is what
the browser pane triggers (3 passes on open, 2 on close, with or without
any CSS).

## Fix

- `src/lib/remove-scroll.tsx`, aliased for `react-remove-scroll` in
`vite.config.ts`: the same component and the same `data-scroll-locked`
counter on `<body>`, but no document listeners; the styles the library
injected live permanently in `index.css`. Under a modal layer nothing
outside it can be wheel-scrolled anyway (body is `pointer-events: none`
and the thread sits under the unslothai#16902 cover), and lists inside dialogs
scroll on their own.
- `src/lib/pointer-listener-pin.ts`: one passive no-op document listener
per pointer event type registered at startup, so the panel library's add
and remove no longer change the set of listener types WebKit tracks.
- `index.css`: the transparent cover unslothai#16902 puts over the thread while a
modal is open now also covers the side pane (browser, research). The
pane sets its own `pointer-events: auto` once shown, so without the
library's document listeners its file view would scroll under a modal
menu; the cover blocks it without a per-open listener.
- `index.css`: elements that restore their own pointer events stay inert
under a modal layer, so a wheel over them cannot scroll what sits behind
it. Two class-keyed rules, CSS only:
- inside a dialog or menu Radix has turned into a lower layer (for
example the Skills list under its actions menu);
- in the page while the lock is up (toolbars, the Downloads card,
sidebar row actions), except the thread (its cover handles it), the top
dialog, popper popups, and window chrome, toasts and overlays meant to
work over a modal (marked `modal-pe-live`).
- The side-pane cover keys on a static class, so toggling the lock only
restyles those elements: about 13 ms at 200 turns in the long-chat gate
(budget 30 ms).
- `vite.config.ts`: `react-remove-scroll/UI` is pre-bundled for the dev
server. It is only imported by the stand-in, so a cold dev server found
it late and reloaded the page, which native Safari did not recover from.
- `src/lib/closing-dialog-focus.ts`: when a dialog starts its exit
animation with focus inside it, the focused element is blurred; Radix
still returns focus to the trigger afterwards.

## Results

Real macOS (GitHub `macos-15`, real WebKit, 150 turns, 2 reps, all arms
on one runner), time to close:

| Surface | Before | Scroll-lock replacement only | This PR |
|---|---|---|---|
| Settings | 4,982 ms | 4,130 ms | 970 ms |
| Command palette | 6,948 ms | 734 ms | 677 ms |
| Search chats | 6,044 ms | 726 ms | 674 ms |
| Rename chat | 4,906 ms | 430 ms | 428 ms |
| Composer menu | 5,124 ms | 655 ms | 628 ms |
| Tools menu | 5,124 ms | 598 ms | 650 ms |
| Chat options | 4,746 ms | 640 ms | 648 ms |

Opening was already fast on real macOS and stays so. On Linux WebKit
(Colab, 100 turns, 3 reps) the browser pane opens in 1.9 s instead of
22.4 s and closes in 0.9 s instead of 11.1 s; Settings open/close goes
from 6.6 / 7.1 s to 1.2 / 1.1 s. Chromium is unchanged or 10 to 40 ms
faster.

Behaviour is the same in both engines: wheel over the browser pane under
the Tools menu moves it 0 px (it scrolls normally with no menu open);
the lock attribute is set and the body has `overflow: hidden` and
`pointer-events: none` while a dialog or menu is open; wheel over the
thread under Settings or the tools menu moves it 0 px while the Settings
pane itself still scrolls; focus lands on the same element after close.
Screenshots of 10 surfaces, open and after close, show no visible change
(pixel differences at 100 turns match a base-vs-base run).

## Tests

- New `studio/frontend/tests/webkit-modal-page-restyle.test.ts`: the
alias, the static lock styles, the pointer listener pin and the
closing-dialog blur.
- Long-chat gate (unslothai#16931): PASS.
- Full frontend suite: 15,088 pass; the one failure is the KaTeX
stylesheet test that also fails on main in a local setup with a
symlinked `node_modules`. `node scripts/typecheck.mjs --tests` is clean.

One deliberate change: clicking the side pane, or a page control that
restores its own pointer events (Downloads button, banners), while a
modal menu is open now only closes the menu, as clicking the thread
already did. Wheel over the Skills list, the Library toolbar, the
Downloads card or the sidebar under a modal menu moves them 0 px (they
scroll normally otherwise). Recipe Studio comboboxes inside its dialogs
stay usable.

Not covered: touch devices such as iPad Safari (the lock's touch
cancelling is dropped), and users with reduced motion, for whom the
closing-dialog blur does not run.
imaderaya pushed a commit to pub-forks/unsloth that referenced this pull request Nov 7, 2026
…unslothai#16978)

Follow-up to unslothai#16931. The long-chat gate carried allowances for costs
main had when it landed. unslothai#16938 (the `:has()` rewrite), unslothai#16942 and
unslothai#16957 removed most of those costs, so this lowers the allowances to
today's readings so they cannot creep back.

## Changes

- `tests/studio/has_subject_allowlist.txt`: regenerated. 57 selectors
are still allowed, 61 are gone. Lint on main: 197 `:has()` rules, 57
non-subject, 0 new, 0 stale.
- `tests/studio/_area_matrix.py`:
- All 9 per-area element-count ceilings are removed, so those areas get
the normal 2x growth check. unslothai#16938 fixed every one of them; none
restyles the whole thread on open any more.
- Glass ceilings lowered to about 1.2-1.3x the highest reading on
current main.
- A recheck page that fails to load or measure now keeps the first
verdict instead of crashing the gate with a traceback. A recheck can
only lower a reading, so this never hides a failure.

## Count ceilings removed (elements restyled at 200 turns)

| Area | Old ceiling | Now | 200 vs 40 turns |
|---|---|---|---|
| model_picker | 44000 | 459 | 0.99x |
| chat_options | 17000 | 2091 | 1.45x |
| browser_pane | 45000 | 1259 | up to 2.55x |
| account_menu | 30000 | 346 | 1.0x |
| organize_chats | 30000 | 226 | 1.0x |
| chat_row_menu | 32000 | 1817 | 1.55x |
| sidebar_sections | 45000 | 163 | up to 1.18x |
| sidebar_toggle | 30000 | 365 | 1.06x |
| run_settings | 45000 | 1214 | 2.13x |

browser_pane and run_settings grow a little faster than 2x but stay
under the 3000-element floor (about 4 elements per turn, not a
whole-thread restyle).

## Glass ceilings (ratio vs the default look)

Highest reading over 3 runs pinned to 4 CPUs and 7 runs on a loaded
36-core host.

| Mode | Old | Highest | New |
|---|---|---|---|
| frosted, other areas | 10 | 5.79 | 7 |
| blurred, other areas | 10 | 5.50 | 7 |
| liquid, other areas | 10 | 5.65 | 7 |
| liquid-3d, other areas | 12 | 5.41 | 7 |
| frosted, Settings scroll | 28 | 9.69 | 12 |
| blurred, Settings scroll | 28 | 12.18 | 15 |
| liquid, Settings scroll | 28 | 10.08 | 13 |
| liquid-3d, Settings scroll | 28 | 9.60 | 12 |

## Testing

- Full gate on main: PASS 4 times (270-310 s).
- Still fails when it should:
- a planted subject-after-`:has()` rule is reported by name ("57
allowlisted, 1 new");
- a synthetic Glass material with a 40px backdrop blur fails 8 cells at
4.0-15.7x, with no real mode failing.
- `test_area_matrix.py`, `test_has_lint.py`, `test_css_culprit.py`: 58
passed.
danielhanchen added a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Nov 7, 2026
…ng (unslothai#16985)

Follow-up to unslothai#16931. The long-chat gate fails a PR on one reading of the
dialog/menu lock cost. On a shared runner that reading can catch the
page mid-settle.

## Problem

Staging for unslothai#16983 failed on `Inline images (windows-latest)`: the lock
check read 125 ms of style recalc per toggle at 200 turns, against a 30
ms budget. The same commit read 14.3 ms in `Composer (windows-latest)`
and 15-16 ms on Ubuntu and macOS. That page also read 0.2 ms/key of
typing style recalc (normally 8) and about 400 extra DOM nodes, so it
was not in its usual state. unslothai#16983 does not touch CSS.

## Fix

When the lock reading is over budget, measure the 200-turn page once
more on a fresh page and keep the lower value. A real regression reads
high twice, so it still fails. Runs under budget are unchanged and do no
extra work.

## Testing

- With `LONG_THREAD_MAX_LOCK_MS=1` the gate remeasures, prints
`dialog/menu lock 11 ms is over budget; measured again on a fresh page:
11 ms`, and fails as before.
- Under the normal budget the over-budget branch is never taken, so
passing runs are unaffected.
danielhanchen added a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Nov 7, 2026
…ery shortcut (unslothai#16983)

## Problem

On long chats, opening and closing dialogs gets slower with chat length
on every platform. Most of the extra time is not rendering. While a
dialog opens or closes, Radix toggles `aria-hidden` / `inert` and the
dialog registers and drops its shortcut triggers. Each of those changes
re-ran every `useShortcutAvailable` subscriber, and every `claims()`
check queried the whole document: modal backdrop, find scope and open
dialog content. At 150 turns that came to about 120 queries and 170-190
ms per Settings or shortcuts dialog close, against under 5 ms on a
1-turn chat.

Real runners at 150 turns: Edge Settings / shortcuts dialogs take
217-376 ms, about 2-3x their 1-turn cost. A CPU profile puts
`querySelector` at 86 of 193 ms.

## Fix

- `use-shortcut.ts`: availability updates coalesce into one pass per
microtask. Within a pass, each shortcut id and each
`isSurfaceInForeground` / `isSurfaceBackgrounded` selector is answered
once and shared, because nothing changes the DOM between two listeners.
Press-time checks and render-time snapshots are unchanged and always
read the live DOM.
- `vite-plugin-preload-nonce.ts`: Vite's preload helper looked up the
CSP nonce meta on every lazy import with deps, a whole-document miss
each time (19 on Settings open). The lookup now searches only `<head>`,
the only place that meta can be.

## Results

150 turns, about 55.5k nodes, same host, base and head alternated each
rep (Chromium 3 reps, Playwright WebKit with a mac UA 5 reps). Medians:

| Surface | Engine | Time to visible (ms) | Max frame (ms) |
Shortcut-check queries |
|---|---|---|---|---|
| Settings close | Chromium | 275 -> 164 | 200 -> 83 | 120 -> 30 |
| Shortcuts close | Chromium | 272 -> 157 | 217 -> 83 | 120 -> 30 |
| Settings open | Chromium | 157 -> 150 | 150 -> 133 | 44 -> 31 |
| Settings close | WebKit | 440 -> 359 | 232 -> 139 | 120 -> 30 |
| Shortcuts close | WebKit | 384 -> 293 | 210 -> 130 | 120 -> 30 |
| Settings open | WebKit | 536 -> 481 | 329 -> 310 | 44 -> 31 |

Command palette and tools menu are unchanged within noise. The remaining
~30 queries per close come from render-time reads, which are left live
on purpose.

## Behaviour

- In the live app, an 18-step shortcut walk behaves identically on base
and head in both engines:
  - the palette chord works with and without Settings open;
  - Escape closes the palette, shortcuts dialog and Settings;
  - Mod+B toggles the sidebar and is ignored under Settings;
  - the find bar hides under dialogs and returns after Escape.
- `playwright_keyboard_shortcuts.py` (Chromium + WebKit, macOS / Windows
/ Linux layouts, including Escape decline / approve): 232/232 on base
and head.
- `playwright_find_in_page.py`: 452/452 on base and head.

## Tests

- New `tests/shortcut-availability-pass.test.ts`: 3 of its 4 tests fail
on main.
- Long-chat gate (unslothai#16931): PASS.
- Full frontend suite: 15,096 pass. The one failure is the KaTeX
stylesheet test, which also fails on main with a symlinked
`node_modules`. `node scripts/typecheck.mjs --tests` is clean.
ouyang-2019 pushed a commit to ouyang-2019/unsloth that referenced this pull request Nov 7, 2026
…t on long chats (unslothai#16986)

## 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` (unslothai#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 (unslothai#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.
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.

1 participant