Skip to content

Studio: stop offscreen reasoning transcripts listening to thread scroll - #13046

Merged
danielhanchen merged 8 commits into
mainfrom
studio-reasoning-offscreen-scroll
Oct 12, 2026
Merged

danielhanchen merged 8 commits into
mainfrom
studio-reasoning-offscreen-scroll

Conversation

@danielhanchen

@danielhanchen danielhanchen commented Oct 8, 2026 •

Copy link
Copy Markdown
Member

Part of #12025 (long conversations lag on scroll).

Since #11522, every expanded reasoning trace longer than the transcript threshold mounts a ReasoningTranscript. Each one adds two scroll listeners to the shared thread viewport:

  • TanStack's offset observer, which re-renders through flushSync.
  • The transcript's own measure. On every frame it runs getBoundingClientRect and a reading-anchor scan that walks every text node of the mounted rows.

All of these run for every transcript in the thread, including ones far offscreen. A chat with 200 such replies had 201 scroll listeners on the viewport.

This change watches each transcript's distance from the viewport with an IntersectionObserver (root = the thread viewport, one screen of margin):

  • More than a screen away, the transcript unsubscribes both listeners and skips the anchor scan.
  • Coming back within a screen, it re-seeds TanStack with the current offset, re-attaches, and measures once.
  • The observer reports after paint, so a jump of more than its margin (scrollbar drag, Ctrl+End) could otherwise paint a far transcript's stale rows for a frame. One shared listener per viewport catches jumps of half a screen or more. It re-measures any far transcript that lands near the viewport and renders it before paint. Closed folded rounds (display: none) stay asleep.
  • Each offset subscription has a generation, so TanStack's scroll-end debounce, which outlives its unsubscribe, cannot replay an old offset after a transcript comes back.
  • Resize observation is untouched, so layout changes are still tracked offscreen.
  • Scroll writes still go through the thread controller.

Seeded long thread, production build, headless Chromium at 4x CPU throttle. Wheel up and down over the chat; median of 5 runs, arms alternated. main is listed twice (A/A) to show noise.

Fixture Arm p95 frame gap Long tasks Script time Viewport scroll listeners
200 replies, long reasoning expanded main 133 ms 121 9.3 s 201
main (A/A) 117 ms 120 7.9 s 201
this PR 33 ms 9 2.4 s 4
100 replies, long reasoning expanded main 67 ms 46 4.7 s 101
main (A/A) 67 ms 52 4.8 s 101
this PR 33 ms 3 2.2 s 4
100 replies, reasoning collapsed (control) main / A/A / this PR 33 / 33 / 33 ms 8 / 12 / 5 3.9 / 4.3 / 4.2 s 1
200 plain replies (control, code path not touched) main / A/A / this PR 50 / 50 / 67 ms 94 / 107 / 118 6.6 / 6.5 / 7.3 s 1

Scrollbar-style jumps: 60 instant jumps to random positions in a thread of 100 expanded long traces. The table counts sampled points in the viewport that land on a transcript with no row painted.

Arm Blank on the first frame Blank after 500 ms
main 0 / 565 0
this PR 0 / 563 0

Checks:

  • tests/reasoning-transcript-offscreen-scroll.test.ts fails 4/4 on main and passes here.
  • Full frontend npm test passes (11017) and npm run typecheck is clean.
  • tests/studio/reasoning-transcript-checks.js gives the same results on main and on this branch: every check passes except "threshold activation moved the reading passage", which fails on both in headless Chromium here, and "latest reasoning is missing", which is intermittent on both. The checks cover saved trace bounds, copy, collapse and reopen, streaming anchor, resize anchor, long prompt reflow, selection, resume following, narrow code and list continuation.
  • Wheeling through a 60-reply thread top to bottom gives identical transcript heights and scrollHeight on main and this branch.

Not covered here: the separate, older cost of scrolling a long chat with the pointer over the messages. It is the same before and after #11522, and comes from per-message assistant-ui subscriptions. Also not tested on Windows WebView2 or with real GPU raster.

Studio built from main (BEFORE) and from this PR (AFTER), two separate installs. Each shows the same saved thread of 20 replies, each with a 28k-character reasoning trace, with Thinking set to always expanded, scrolled to the middle. The visible transcript text, its position and the thread height are identical on both sides; only which transcripts listen to scroll changed.

Long expanded reasoning thread, main vs this PR, identical

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 8, 2026 •

Copy link
Copy Markdown

Codex Review Summary

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

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-12T02:40:40.997568Z 943f33e Manual request
🔒 Security Review ⚠️ Failed 2026-10-08T11:15:53.525028Z 0baa393 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[bot]

This comment was marked as resolved.

danielhanchen added a commit to LeoBorcherding/unsloth that referenced this pull request Oct 8, 2026
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Hooray!

Reviewed commit: 16585eb902

ℹ️ 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".

@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

1 similar comment
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 0dc2fee43a

ℹ️ 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".

Comment on lines +545 to +548
: new IntersectionObserver(
(entries) =>
setNearby(entries.at(-1)?.isIntersecting ?? nearby.current),
{ root: scroll, rootMargin: "100% 0px" },

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Reseed transcripts when hidden folded rounds reopen

When a long FoldedReasoningRound is closed, reasoning.tsx deliberately keeps it mounted under className="hidden", so this observer eventually calls setNearby(false) and detaches its offset listener. Reopening that round only changes the ancestor's class; it neither scrolls nor reruns this layout effect, leaving the virtualizer on its old offset until this IntersectionObserver reports asynchronously. If the user scrolled while the round was hidden, the first reopened frame can therefore contain stale or blank rows. The reopen path needs to synchronously remeasure and reseed the offset rather than relying solely on this observer.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not introduced here. Hiding a visible transcript's container with display: none, scrolling 1500px, then reopening it and sampling the first frame before paint from a later ResizeObserver: main shows 15 of 32 transcript samples blank, this branch 12 of 28, both settle by 500ms. A synchronous reseed on the reopen resize made it worse (55 of 55), so it was not kept. The jump watcher now ignores zero-height (closed) rounds in e1111a4.

: new IntersectionObserver(
(entries) =>
setNearby(entries.at(-1)?.isIntersecting ?? nearby.current),
{ root: scroll, rootMargin: "100% 0px" },

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Match the vertical margin to the jump threshold

The fresh evidence beyond the earlier jump report is that IntersectionObserver resolves the vertical 100% root margin against the root's width, whereas onViewportJump compares each delta with half of clientHeight. On a 320×900 viewport, for example, a transcript can be detached just over 320 px below the viewport and a 400 px programmatic or scrollbar jump can land inside it without meeting the 450 px jump threshold; the observer then wakes it only after the stale range has painted. Use a height-based pixel margin or derive the jump threshold from the observer's actual vertical lookahead.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IntersectionObserver resolves a vertical rootMargin percentage against the root's height, not its width. Measured on a 320x900 root with rootMargin '100% 0px': rootBounds.height is 2700 in Chromium, Firefox and WebKit, and a target 400px below the viewport reports isIntersecting true. The observer margin and the half-screen jump threshold are both height-based already.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Chef's kiss.

Reviewed commit: e1111a4a0b

ℹ️ 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".

…ts by their size change

A far transcript stops following the thread's scroll, so TanStack's stored
offset freezes. Its size correction (offset + adjustments - scrollTop) then
threw a scrolled-up reader back to where that transcript went far, e.g. from
reply 24 to reply 1 on a window resize. Shift by the size change instead.
…the reader

A frozen offset can land in the middle of a far transcript once content above
it moves (a reflow on resize, rows prepended above), so TanStack mounts and
measures rows a live offset never would and the reader drifts. Park it above
or below the transcript instead, where the live offset keeps the range.
@Etherll

Etherll commented Oct 11, 2026

Copy link
Copy Markdown
Collaborator

Offscreen reasoning traces no longer listen to the chat's scroll. In a saved chat of 30 replies with long Thinking expanded, the thread viewport goes from 63 scroll listeners on main to 8, with the same visible text and position. At 4x CPU throttle on a 60-reply chat, the p95 frame gap during wheel scrolling went from 483-633 ms on main to 300-350 ms. The machine was shared and heavily loaded, so treat those numbers as a direction, not absolutes.

What changed

  • Resizing the window threw a reader who had scrolled up back toward the start of the chat (from reply 24 to reply 1 in a 40-reply chat). A sleeping trace corrected sizes from the scroll offset it had when it went to sleep. It now shifts the view by the size change alone.
  • A sleeping trace's frozen offset could land in its middle once content above it moved, so it mounted and measured rows main never would, and the reader drifted on reflow. It now parks its offset at the edge nearest the reader, where a live offset would keep it.

The frontend tests (11018) pass, and typecheck, build and bundle check pass on 90d993d4. The reasoning transcript browser checks give the same results as main, and without IntersectionObserver the page behaves like main. Browser checks ran on Chrome 147, Edge 151 and the Firefox and WebKit engines; Safari and Windows WebView2 were not tested.

One gap remains. Narrowing the window enough to reflow the column (1280 to 700 px) still moves a scrolled-up reader by about two screens at one of three tested positions where main keeps it, and main loses the place at another. Fork CI is running: Etherll#241

Unsloth Studio, main vs this PR

main (f51a3ff5) vs this PR (90d993d4): CPU-only Unsloth Studio builds showing the same saved chat on both sides.

@danielhanchen danielhanchen self-assigned this Oct 11, 2026
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. What shall we delve into next?

Reviewed commit: 4437a0a80b

ℹ️ 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".

@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Oct 12, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Oct 12, 2026
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

1 similar comment
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Nice work!

Reviewed commit: 943f33ef6a

ℹ️ 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".

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.

3 participants