Repository navigation
Studio: keep syntax colour on settled thinking code in tilde, four-backtick and stopped fences - #13415
Merged
Conversation
…, indented and stopped forms
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. |
Member
Author
|
@codex review |
1 similar comment
Member
Author
|
@codex review |
|
Codex Review: Didn't find any major issues. Breezy! 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". |
danielhanchen
pushed a commit
to danielhanchen/unsloth-staging-2
that referenced
this pull request
Oct 12, 2026
danielhanchen
pushed a commit
to danielhanchen/unsloth-staging-2
that referenced
this pull request
Oct 12, 2026
danielhanchen
pushed a commit
to danielhanchen/unsloth-staging-2
that referenced
this pull request
Oct 12, 2026
danielhanchen
added a commit
to Sneakr/unsloth
that referenced
this pull request
Oct 19, 2026
The default no longer moves line windows, which is what stopped the scrollbar stall, so Thinking code can keep the worker-coloured rendering it had before this branch (unslothai#13415). Restores the settled colour path and its tests, and drops the plain-Thinking action test that only covered the removed path.
danielhanchen
added a commit
to Etherll/unsloth
that referenced
this pull request
Oct 19, 2026
## Summary Dragging the chat scrollbar thumb across a long code fence stalled Studio: the line window inside large fences moved on every frame of the drag, swapping hundreds of thousands of nodes. This PR fixes the stall and keeps the line window, which turned out to matter for every other way people read a long chat. Original change by @Sneakr (defer highlighting by default, plus chunked fence rendering, hoisted line colour and a progressive highlight queue). The scrollbar guard is the one @oobabooga proposed in review. On top of that I merged main, kept the line window as the default, kept syntax colour in Thinking, and fixed two highlight-blocking bugs found while testing. ## What changes - **Scrollbar guard.** A thumb press targets the scroller, an ancestor of the fence, so the existing drag guard never saw it. The held scrollbar is now tracked and the window stays put until release (`code-fence-defer.tsx`, `onScrollbar` in `code-fence-window.ts`). - **Default stays `window`.** `defer` is still reachable through `__UNSLOTH_DEFER_FENCE_HIGHLIGHT__` / `VITE_UNSLOTH_DEFER_FENCE_HIGHLIGHT`. See the slow read numbers below for why. - **Rendering work from this branch, kept:** 32-line memoized line chunks, plain-text chunks, line-level colour hoisting (fewer spans), skipping source-only re-renders, and the input-aware highlight queue. - **Thinking code keeps its colour** (the unslothai#13415 path), so nothing visible changes for reasoning traces. - **Fix:** any non-empty selection on the page blocked the highlight queue, so after selecting a sentence and scrolling on, newly reached fences stayed uncoloured until the selection was cleared. Only a selection that ends inside a fence holds it now. - **Fix:** a handler that cancels `dragstart` (the model picker's pinned rows, the hub carousel) left the pointer marked as held forever, which stopped all deferred highlighting until the next real drag or a window blur. - Startup bundle: +11,012 B raw / +3,984 B transfer, budget raised with the measurement. ## Measurements Real Studio (production build, own backend), a thread of ten Python fences of 280 to 3,200 lines (about 134K characters in the largest), headless Chromium driving the native scrollbar thumb, each arm a fresh browser context, arms interleaved. "Long-frame time" is the time past one frame spent in frames over 50 ms. **Thumb drag across the 3,200-line fence, 8 s** (Linux Chromium, median of 3): | | main | main + guard | this PR as first submitted (`defer`) | this PR | |---|---|---|---|---| | 1x CPU: long-frame time | 933 ms | 50 ms | 0 ms | 33 ms | | 1x CPU: frames over 50 ms | 15 | 1 | 0 | 1 | | 4x CPU: long-frame time | 4,166 ms | 300 ms | 350 ms | 33 ms | | line-window DOM swaps during the drag | 72K to 229K | 4.9K | 0.5K | 4.9K | The same drag on a Windows 11 runner in Microsoft Edge at 4x: main 3,940 ms of long frames, main + guard 67 ms, `defer` 0 ms, window + guard 267 ms. No renderer crash or browser disconnect in any arm, including 15 rapid back-and-forth drags per arm, so the STATUS_BREAKPOINT report did not reproduce on that machine. **Reading the thread slowly** (mouse wheel, 400 px every 350 ms from the bottom to the top, then idle; two runs each, both shown): | | main | `defer` default | this PR | |---|---|---|---| | DOM elements afterwards | 34K / 35K | 111K / 111K | 28K / 28K | | theme change, 1x | 0.28 / 0.40 s | 2.60 / 2.12 s | 0.32 / 0.34 s | | theme change, 4x | 1.55 / 1.40 s | 8.06 / 10.19 s | 1.48 / 1.28 s | | thumb drag after the read, 4x (long-frame time) | 3.37 / 2.60 s | 2.53 / 1.72 s | 0.95 / 0.28 s | With `defer` every line the reader passes keeps its token spans, so a slow read of this thread ends with every token mounted. The window caps that, which is why this PR keeps it as the default. Long-frame time during the read itself was too noisy on this shared host to rank the window arms: main measured 1.2 and 3.7 s at 1x (29 and 22 s at 4x), main + guard 2.4 and 0.9 s (35 and 16 s), this PR 3.4 and 0.8 s (41 and 18 s), and `defer` 4.6 and 33.4 s (26 and 43 s). **Expanded Thinking** (six turns, three 150-line fences each, all expanded, median of 3 at 1x): expand long-frame time main 200 ms / this PR 183 ms, DOM 18.3K / 14.3K, theme change 147 / 129 ms. Screenshots of the answer fences and of Thinking are pixel-identical to main in the thread area. ## Testing - Frontend: 12,762 tests pass, typecheck, production build and bundle check. New tests for the scrollbar guard, the selection scope and the cancelled `dragstart`, each failing without its fix. - Cross-platform CI on Linux, macOS (Apple Silicon) and Windows: node tests green, Studio Playwright smoke OK. - Studio UI regression suite (auth, settings, model picker, chat UI, compaction, page crawl), base vs head: no regression. One crawl page diff is an animated remote image; two checks fail identically on main. - studiobench standard tier, A/B against main with a main-vs-main null control (4 repetitions): no metric outside the null control's detection floor. This host was heavily loaded, so the floors were wide. ## Not covered - STATUS_BREAKPOINT itself was not reproduced (Edge on Windows 11 and Chromium on Linux, headless). Users who still hit it can set `__UNSLOTH_DEFER_FENCE_HIGHLIGHT__ = "defer"`. - Overlay and left-side scrollbars and document-level scrolling are not covered by the guard; Studio's thread scrolls in its own viewport with a right-hand scrollbar. - WebKit and the macOS desktop app were covered by unit tests only. ## Before and after Same seeded thread on main (BEFORE) and this PR (AFTER), each served from its own production build. The thread area is identical in both scenes apart from one antialiased pixel.  --------- Co-authored-by: Daniel Han <[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.
Follow-up to #13255.
In a thinking block, code is coloured while it streams, and a closed
```fence stays coloured once the reply finishes. Three other forms lost their colour at completion and fell back to plain text:~~~or four backticksBefore #13255 these were highlighted on the main thread. After it, the settled fallback for these forms rendered
PlainFenceBlock, which has no highlighting.This routes that fallback through
LiveThinkingFencewith a newsettledflag. The block is coloured once by the background highlight worker when it is near the viewport, the same path the closed```fence uses. Nothing moves back onto the main thread and the rendered text is unchanged.Tests:
tests/code-fence-body.test.tspins the settled fallback toLiveThinkingFence settledand the hook'ssettledargument. Both new assertions fail against main and pass here. The full frontend suite passes, except one wall-clock timing test instreaming-render-schedule.test.tsthat passes on rerun.UI before / after
Two clean Studio installs from this PR's merge base (main) and head (828d94b), driven by the same Playwright scene over a scripted stream, so the text is identical on both sides. Read from the page: the three thinking code blocks carry syntax colour on 0 of 3 before and 3 of 3 after.
A closed
~~~pythonfence in a thinking block, after the reply finishes: plain on main, coloured with this PR.A closed four-backtick fence in a thinking block: plain on main, coloured with this PR.
A fence the stream ended inside (what Stop mid-code leaves), below the four-backtick one: plain on main, coloured with this PR.