Repository navigation
Fix slow typing in long chats on Windows - #16656
Conversation
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
Codex Review: Didn't find any major issues. Keep them coming! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
…space With Glass on, the workspace wallpaper rules still searched the whole chat for the welcome screen and the compare view, and the conversation viewport searched itself for the welcome block. Chromium re-runs those searches while typing, so long chats stayed slow for Glass users after the fade fix. The welcome and compare views now set data-chat-welcome / data-chat-compare on <html> in a layout effect (counted, so compare panes and remounts stay correct), and the viewport rule uses the fixed child path to the welcome block. Every visual state computes the same as before. The guard test now covers every :has() anchored on an element that holds the thread, including ones nested in :not(), instead of only wallpaper paths. [skip ci]
|
@codex review |
1 similar comment
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: a81764fc7c
ℹ️ 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".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| :is([data-wallpaper-workspace], [data-chat-content-root]):has(> .chat-wallpaper[data-ready]):not([data-wallpaper-route="page"]):has([data-tour="chat-compare-view"]) > .chat-wallpaper, | ||
| /* Conversations dim the crop; compare dims even an empty pane so both match. | ||
| Welcome/compare come from root flags (welcome.ts): a descendant :has() here re-walks the thread per keystroke. */ | ||
| html:not([data-chat-welcome]) :is([data-wallpaper-workspace], [data-chat-content-root]):has(> .chat-wallpaper[data-ready]):not([data-wallpaper-route="page"]) > .chat-wallpaper, |
There was a problem hiding this comment.
Update the wallpaper smoke fixture for the new welcome markers
When running /smoke-chat-background.html, smoke-chat-background-main.tsx only toggles .aui-thread-welcome-center and never calls useMarkChatWelcome, so <html> never gets data-chat-welcome. This selector therefore dims the fixture's initial welcome view to the conversation opacity, and the opacity assertion in tests/studio/playwright_chat_background.js:106-107 is already satisfied before “Toggle conversation” is clicked. Update the fixture to drive the new root flag and use the child-only welcome structure required below, so the existing visual/regression harness still represents the welcome-to-conversation transition.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 58d2e8d: the fixture now mounts useMarkChatWelcome with ThreadWelcome's welcome-root nesting, and the smoke checks the welcome view is undimmed before toggling. Old fixture with the new CSS read opacity 0.4 on welcome; now 1 -> 0.4 -> 1, same as main.
The fixture toggled the welcome class by hand, so with the root flag the welcome view was already dimmed and the conversation opacity check passed before the toggle. Mount useMarkChatWelcome with ThreadWelcome's nesting and check the undimmed welcome view before toggling. [skip ci]
|
@codex review |
1 similar comment
|
@codex review |
|
Codex Review: Didn't find any major issues. Keep them coming! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
…s off the thread Light Glass welcome rules (unslothai#16751) read the data-chat-welcome root flag, and the Windows page blur rule (unslothai#16671) uses the child path to the pinned sidebar container. The guard now also covers data-windows-wallpaper-page, which holds the hidden chat. [skip ci]
|
@codex review |
1 similar comment
|
@codex review |
|
Codex Review: Didn't find any major issues. Hooray! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
…the chat grows (unslothai#16801) Adds a browser CI gate that fails when typing in a long chat costs more as the chat grows, the shape of unslothai#16603. **Stacked on unslothai#16656. Please merge unslothai#16656 first**: this branch contains its commits, and the gate fails on current `main` by design (that is the regression it catches). ## Why unslothai#16603 came back because nothing in CI measured per-keystroke cost against chat length. Bisecting the Studio frontend from `v0.1.913` to `main`: | Build (200-turn agent chat, about 427K tokens) | Style work per keystroke | | --- | --- | | before unslothai#16333 | 15.6 ms | | unslothai#16333 (wallpaper fade `:has()`) | 619 ms | | `v0.1.914-beta` | 144 ms | | `main` | 136.5 ms | | `main` + unslothai#16656 | 4.6 ms | unslothai#16333 added a descendant `:has()` on elements that hold the whole thread (`[data-wallpaper-workspace]`, `[data-chat-content-root]`), so Chromium (Desktop, Chrome, Edge) walks every message on each keystroke. Firefox is not affected, which matches the "browser is fine" reports. unslothai#16751 (Reduce Motion default off) then made scroll pay that walk more often (61 ms to 188 ms per wheel step), which is why turning Reduce Motion back on did not help typing. unslothai#16300 (`d56738f40`) already removed two other unslothai#16333 rules that restyled the whole page on every key (real-app bisect: 563.8 to 91.2 ms per key), which is why 0.1.914 was slow but not as slow as unslothai#16333. The fade rule stayed. unslothai#16656 removes every such rule and adds a static guard test; this PR adds the runtime gate so a new rule of that shape, or anything else that scales with chat length, cannot ship again. ## What the gate does `tests/studio/playwright_long_thread_gate.py` runs **first** in every frontend lane, right after `npm ci`: Frontend CI (Linux, Windows), Composer compatibility (Ubuntu, macOS, Windows, Safari) and Inline images (Ubuntu, macOS, Windows). 1. Builds `smoke-thread-weight.html` for production (`vite.long-thread.config.ts`) and seeds an agent-style history inside the real app ancestors (`?shell=1`: sidebar workspace, wallpaper, chat content root) with open reasoning, tool cards, web sources, compaction markers, code, KaTeX and tables. The fixture shape is checked, so a fixture that stops rendering something fails. 2. Measures the 200-turn chat first. Two untraced keys decide how much to trace: a healthy page traces 10 keys, a slow one 2, and a page hundreds of times slower than healthy fails on the untraced number alone. 3. Fails if `:has()` matching costs more than 5 ms per key at 200 turns, or if total selector matching per key grows more than 2x from 40 to 200 turns. A second repeat runs only when the ratio is near the limit. Both checks are ratios or tiny budgets on selector matching, so a slow runner cannot fail them. ## What a failure says A failure prints ms per key at each size, how far over budget it is and the top selectors with their match attempts. Selectors tried on most of the DOM are marked as likely victims of a whole-page restyle. It then pins down the trigger: it removes `:has()` rules from the stylesheet text before fresh page loads (rules switched off in a page that already rendered leave Chromium's `:has()` state behind and blame the wrong rule) and bisects for the rule whose removal makes typing cheap, trying rules that search an element holding the thread first. Each rule found is mapped to its likely source with a text match, worded as a possibility. On current `main`: ``` FAIL: :has() matching costs 63.6 ms per keystroke at 200 turns, budget 5.0 ms (12.7x over); total selector matching 358.9 ms/key pin-down at 60 turns, untraced style recalc per keystroke: 48.5 ms with all 262 :has() rules, 1.1 ms with none of them Measured: removing only this rule takes the keystroke from 48.5 to 1.8 ms (no :has() rules: 1.1 ms); this rule on its own costs 4.9 ms: :is([data-wallpaper-workspace], [data-chat-content-root]):has(> .chat-wallpaper[data-ready] .chat-wallpaper-image[data-fade="false"]) .thread-bottom-fade It is possible this section caused the issue, but we cannot be sure (a text match): studio/frontend/src/index.css:6210 (exact text match) Pattern: `:has(> .chat-wallpaper[data-ready] .chat-wallpaper-image[data-fade="false"])` on `:is([data-wallpaper-workspace], [data-chat-content-root])` searches all descendants (no leading `>`, or a space inside), so Chromium re-walks everything under that element after each DOM change, whether or not anything matches. `[data-wallpaper-workspace]` (first found in studio/frontend/src/app/routes/__root.tsx:720) holds the whole thread, so every keystroke walks every message. ``` `tests/studio/test_css_culprit.py` covers the source mapping and the `:has()` shape check. ## Replay against past stylesheets The gate on this branch, with only `index.css` swapped in from each commit (CPU runner): | `index.css` from | Verdict | Time | Pin-down | | --- | --- | --- | --- | | before unslothai#16333 (`4ce36bc3b5`) | PASS | 25 s | | | unslothai#16333 (`65e868dcf5`) | FAIL | 104 s | fade rule: 276.0 to 1.5 ms without it | | unslothai#16442 (`6401ceda29`) | FAIL | 105 s | fade rule | | `v0.1.914-beta` | FAIL | 101 s | fade rule | | `main` | FAIL | 104 s | fade rule: 48.5 to 1.8 ms without it | | this branch | PASS | 28 s | | On GitHub runners a passing gate takes 30 to 77 s per lane plus 12 to 24 s for Chromium (staging run of every lane on Linux, Windows and macOS). ## Other changes - The smoke fixture gains `rich` agent content (markdown, table, list) and the `?shell=1` app shell. - The gate's Chromium step installs missing Linux libraries only when Chromium cannot launch, through `retry-with-apt-lock.sh` with `APT_ACQUIRE_RETRIES=0` and a 10 minute step timeout, like the other browser steps. --------- Co-authored-by: imagineer99 <[email protected]>
…ng (unslothai#16782) ## Summary Scrolling a long conversation can make the browser repeatedly paint replies far outside the viewport. This change gives distant assistant replies their own CSS paint boundary. A shared IntersectionObserver per chat scroller removes the boundary before a reply comes into view. Replies wider than their column keep their horizontal overflow, and print uses normal page layout. Related to unslothai#16603. unslothai#16656 addresses typing latency. This PR addresses scrolling and can be reviewed independently. ## Verification The production build and the long-chat browser test passed on the submitted commit. The new CI assertions exercise scrolling a reply into and out of view, print layout, and horizontal access to an oversized reply. I also compared production builds with and without the scrolling change on top of unslothai#16656 at `7def5eda`. Both opened the same saved 600-message, 7.11-million-character conversation with two thinking panels expanded, code blocks, and LaTeX. The figures below are the median of three passes' 95th-percentile frame gaps while scrolling through the middle of the thread. | Windows renderer | Before | After | | --- | ---: | ---: | | WebView2 | 25.0 ms | 12.5 ms | | Chrome (headless) | 24.9 ms | 8.4 ms | The WebView2 run used a local host for the Windows renderer. The packaged desktop app still needs a manual pass. Browser interaction checks covered find, text selection, message menus, thinking expansion, code highlighting, and print styles in Chrome, Firefox, and WebKit. --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Daniel Han <[email protected]> Co-authored-by: Daniel Han <[email protected]>
…16854) Opening panels and scrolling long chats can stall WebKitGTK because offscreen message content still participates in style and layout work. For Linux threads with 100+ messages, park completed offscreen bodies behind measured placeholders while retaining their React state. Restore rich content for scrolling, focus, find, selection, and print. Also reduce offscreen code highlighting and keep browser-panel constraints stable during opening and closing. Prevent blank chat frames while history loads or the native scrollbar jumps. A transparent fixed-background sentinel synchronizes WebKitGTK overflow scrolling with main-thread painting. Commit small history batches and their anchor corrections in the same rendering frame, pause loading during scrolling, typing, composition, and pointer interaction, and hold message heights during thumb drags. Reuse the existing measurement-free collapsible for tool panels to avoid repeated forced layouts from closed disclosures. Keep text stationary as history loads: preserve the compensated anchor between batches so intervening reflows are included, and absorb fractional inserted heights in a leading spacer under one pixel. WebKit can then apply whole-pixel scroll corrections without repeatedly moving the text between fractional positions. Validation: - Production build, frontend/test typecheck, and 87 focused progressive-mount, autoscroll, and message-window tests pass on the updated branch. - Existing Chromium autoscroll smoke test passes. Earlier validation also passed all 13 tool-activity scenes. - Native Tauri / WebKitGTK 2.54.2: switched from the 300k-token copy to the 600-message (~911k-token) thread and exercised wheel scrolling, thumb reversals/release, and bottom-following during loading. After native wheel motion ended, a fixed text range varied by 0.015625 px, down from 2.234375 px before this change. The same bound held after thumb release. Repeated the wheel run after incorporating the branch's main merge. - None of the 96 OS screenshots across these four loading runs captured blank chat content. Earlier settled-drag checks kept the scroll range fixed. - Earlier native typing validation delivered all 40 keystrokes, paused history loading throughout input, and measured at most 30 ms from input to the second animation frame. Native Settings and browser-panel checks, plus find, selection, and print restoration, also passed. Full history still mounts progressively. Extremely fast drags through complex replies can drop frames; these checks establish that the reproduced periodic blanking and visible loading shake did not recur in the tested sequences. Related to unslothai#16603. This complements unslothai#16656 and unslothai#16782; message windowing and the scrolling workaround are limited to WebKitGTK. --------- Co-authored-by: Daniel Han <[email protected]> Co-authored-by: Daniel Han <[email protected]>
What changed
Typing in a long, idle chat could stall in Unsloth Desktop on Windows. The wallpaper fade rule used a descendant search inside
:has(), so editing the composer could trigger a costly style recalculation across the chat. The slowdown reproduced with turn navigation disabled and no model running.Use direct-child selectors for the two wallpaper layouts. The plain Glass backdrop contains the image directly, and an uploaded wallpaper wraps it in a frame. Both keep their existing fade behavior.
Verification
:has(). On the original stylesheet, the three prior checks pass and the new check fails on the fade selector. All 28 tests across the thread-ancestor, wallpaper and appearance suites pass with the fix.Playwright sent the final key at 1.88 seconds in both recordings. The full phrase appeared at 4.09 seconds before the fix and 1.88 seconds after it. The capture compares the parent and implementation commit. The follow-up commits only change the regression tests.
Glass users and the latest main
The fade selector was one of four whole-thread
:has()searches on the workspace that holds the chat. With Glass on (stored per origin, so Desktop can have it on while the same chat at 127.0.0.1:8888 does not), the other three still made every keystroke re-walk the thread::not(:has(.aui-thread-welcome-center))and:has([data-tour="chat-compare-view"])on the workspace (wallpaper dim, plus two Glass rules added in Studio: glass theme polish and a composer position slider #16643).aui-thread-viewport:has(.aui-thread-welcome-center)on the thread scroller itselfThe welcome and compare views now set
data-chat-welcome/data-chat-compareon<html>in a layout effect (counted, so compare panes and remounts stay correct), and the viewport rule uses the fixed child path to the welcome block. The branch is merged with main. The guard test now checks every:has()anchored on an element that holds the thread, including ones nested in:not().Typing into an idle 600-message chat, headless Chromium, same server, JS and DOM, only the stylesheet differs, arms interleaved, 6 reps each, median [min-max]:
No visual change: 192 wallpaper states (workspace and chat root, backdrop / frame / crossfade, ready, fade, welcome / conversation / compare / compare with an empty pane, Glass on and off) compute the same display, opacity, viewport wash and composer glass values on main and on this PR in Chromium, Firefox and WebKit (576 cells, 0 differ; dropping the rules flips 96 of 192, so the check is live). The real app shows the same computed values on main and on this PR for welcome, conversation and compare, with and without Glass.
Typing a 57-character question at 80 ms per key into the same 600-message chat with Glass on (4.6 s is the floor):
Issue #16603
Fixes #16603. Bisecting the Studio frontend from
v0.1.913tomainon a seeded 200-turn agent chat (about 427K tokens: reasoning, tool cards, web sources, compaction markers, code, KaTeX), headless Chromium, same server and data for every build::has()this PR bounds)v0.1.914-betamainmain+ this PR#16751 (Reduce Motion default off) made scroll pay the same walk more often (61 ms to 188 ms per wheel step); this PR removes the walk, so no separate change is needed there, and it is why turning Reduce Motion on did not help typing. A spoofed agent session that grows to 30 turns with tool calls, file edits, web search and compaction rounds goes from 23.7 to 100.3 ms per key on
mainand stays near 1.2 ms per key with this PR.#16801 adds a CI gate that fails when selector matching per keystroke grows with chat length; it should merge after this PR.