Skip to content

Studio: defer off-screen code fence highlighting by default - #9567

Merged
danielhanchen merged 6 commits into
mainfrom
studio-defer-fence-default
Aug 23, 2026
Merged

danielhanchen merged 6 commits into
mainfrom
studio-defer-fence-default

Conversation

@danielhanchen

Copy link
Copy Markdown
Member

Turns on the deferred off-screen code fence highlighting merged in #9462. That mechanism has been inert behind a flag defaulting to off, because turning it on caused two things a reader could see. Both are fixed here rather than accepted, so the default moves with neither of them.

The two regressions, reproduced before they were fixed

Both were reproduced at the candidate commit first, with the same instruments that found them.

reproduced at the candidate after this PR
painted frames showing plain code on a jump, Chromium 100K 29 of 274, 8 of 16 jumps, median 92 ms 0
deferred fences on a printed page, Letter 1 to 2 on every sampled page none
printed page against main, differing pixels, Letter 6.5628% 0.0034%

A discontinuous scroll painted plain code

A scrollbar drag, Ctrl+End or an anchor jump can move the viewport further than the observers' one-viewport lookahead, with no React render in between, and an IntersectionObserver record is delivered after the browser has painted.

A capturing scroll listener now latches the fences the jump landed on inside the same task, so the swap is part of the frame the reader is about to see. Scroll events are dispatched in the "run the scroll steps" of the same rendering pass that will paint the new position, before animation-frame callbacks and before style, layout and paint.

The test for "is this a jump" is derived from the observer margin rather than picked. rootMargin grows the band by one root height, so after a scroll of d the newly visible strip is inside the old band exactly when d <= h. A scroll of at most one root height can therefore only reveal fences the observers had already reached. A continuous scroll pays one subtraction per event, and the single capturing listener is removed when the last fence latches, so a thread with nothing left to defer carries no scroll cost at all.

Print lost colour on one or two fences per page

A print lays the document out at paper width while the scroll offset carries across as a raw pixel count, so the printed page lands several fences away from the reader's window. Matching the paper to the window removes the difference, which is what identifies the cause and is also why chasing the window is the wrong fix: the whole document is on the page, so the whole document is what has to be highlighted. Both doors are covered, beforeprint for Ctrl+P and the print menu, and the print media query for page.pdf and PDF export.

An earlier attempt at this was removed from #9462 after it was measured to leave 53 of 56 blocks on streamdown's raw fallback. The reason was not the latch. Streamdown's highlighted body asks the plugin for tokens from a passive effect and shows a plain fallback until it answers, and the plugin answers null while a grammar is still loading, so latching alone renders the block unhighlighted. Three things close it, and each one was measured to matter:

  • the tokens are warmed first, so the render that follows is a cache hit;
  • grammars are loaded at idle as empty-string tokenizations, which mount no span and tokenize no fence, so a loading grammar can never be what is missing when the snapshot is taken;
  • the flush is nested, because react-dom only runs pending passive effects when it has sync work (performSyncWorkOnRoot begins with flushPendingEffects), and flushSync restores the update priority before it flushes, so an update scheduled by a passive effect during a scroll resolves as continuous and is not flushed. An outer flushSync holds the priority discrete while the two inner ones do the work.

What it costs and what it saves

Measured on this commit, Chromium, 100K rung, against main built and served concurrently on the same machine, every delta printed beside the delta its own concurrent same-commit null control reported for the same metric in the same wall clock. floor = max(|null delta|, null spread); a metric counts only if it clears its own floor, its paired ratios agree on sign, and the effect exceeds its own scatter.

metric base this PR delta null delta floor verdict
reasoning_toggle.close_ms 718.9 150.8 -76.9% +0.8% 10.6% faster
jank_index 26.4 10.7 -59.5% -3.4% 8.4% faster
time_in_jank_pct 5.5 2.3 -58.3% +0.9% 8.2% faster
select_all_copy.total_ms 944.6 511.3 -45.8% -3.1% 7.5% faster
census.scroll_after.highlight_spans 42,077 6,988 -83.4% 0.0% 0.0% faster
census.scroll_after.elements 63,126 28,037 -55.6% 0.0% 0.0% faster

Every other metric in the battery is reported VOID against its own floor rather than claimed. The three user-visible ones above are the same three that cleared their floor before the two fixes were written, so the fixes did not erode the win; reasoning_toggle.close_ms, jank_index and time_in_jank_pct all came back larger with tighter floors.

At rest the 100K thread mounts 22,808 elements instead of 61,760 and 2,458 highlight spans instead of 41,410, with 53 of 56 fences deferred. That is unchanged by the two fixes, so neither the jump latch nor the idle grammar warm gives back any of the standing saving.

The worst case, a traversal that visits every fence so nothing can be saved, shows no metric slower than its floor.

What is unchanged

  • 160 of 160 viewports byte-identical to main at matched scroll positions once settled, with the in-band null also 160 of 160.
  • 0 reverse edges within a mount, against a deliberately bidirectional mutant scoring 152 in the same run.
  • 0 settled positions showing a plain fence, against a no-lookahead mutant scoring 37.
  • select_all_copy.count.selected_chars held exactly at 194,992: the text a reader can select and copy is the same text.
  • off still means what it meant. The build flag and the runtime global still override the default in both directions, a typo still degrades to off rather than to the new default, and tokenize is still reachable only by its exact string.

Controls

Every number above comes from a run that also served two deliberately defective builds and refuses to report anything if it cannot see them. The pixel probe classifies composited frames from a CDP screencast, never from a DOM read, on a classifier calibrated at a 209x separation between the two known states. In the same runs the no-lookahead mutant scored 172 to 176 painted plain frames and the pre-fix candidate scored 26 to 29, while this branch scored 0.

Turns on the mechanism merged in #9462, which has been inert behind a flag
because turning it on caused two things a reader could see. Both are fixed here
rather than accepted, so the default moves with neither of them.

A DISCONTINUOUS SCROLL PAINTED PLAIN CODE. A scrollbar drag, Ctrl+End or an
anchor jump can move the viewport further than the observers' one-viewport
lookahead, with no React render in between, and an IntersectionObserver record
arrives after the browser has painted. Measured in Chromium at the 100K rung:
29 of 274 painted frames on 8 of 16 jumps, median 92 ms.

A capturing scroll listener now latches the fences the jump landed on inside the
same task, so the swap is part of the frame the reader is about to see. The test
for "is this a jump" is derived from the observer margin rather than picked: a
scroll of at most one root height can only reveal fences the observers had
already reached, so the pass runs when, and only when, the lookahead provably
did not cover the movement. A continuous scroll pays one subtraction per event,
and the listener is removed when the last fence latches.

PRINT LOST COLOUR ON ONE OR TWO FENCES PER PAGE. A print lays the document out
at paper width while the scroll offset carries across as a raw pixel count, so
the printed page lands several fences away from the reader's window. The whole
document is on the page, so the whole document is now highlighted, through both
doors: beforeprint for Ctrl+P and the print menu, and the print media query for
page.pdf and PDF export.

An earlier attempt at this was removed after it was measured to leave 53 of 56
blocks on streamdown's raw fallback. The reason was not the latch. Streamdown's
highlighted body asks the plugin for tokens from a passive effect and shows a
plain fallback until it answers, and the plugin answers null while a grammar is
still loading, so latching alone renders the block UNHIGHLIGHTED. Three things
close it, all of them needed: the tokens are warmed first so the render is a
cache hit; grammars are loaded at idle, empty-string tokenizations that mount no
span, so a loading grammar can never be what is missing; and the flush is nested,
because react-dom only runs pending passive effects when it has sync work, and
it restores the update priority before it flushes.

Measured on this commit, Chromium, 100K rung, against current main served
concurrently on the same machine, with the pre-fix build served alongside as an
in-run control:

  painted frames showing plain code   main 0/822   this 0/821   pre-fix 81/817
  jumps affected                      main 0/45    this 0/45    pre-fix 24/45
  printed page vs main, Letter        6.5628% -> 0.0034% differing pixels
  deferred fences on a printed page   1 to 2 per page -> none

Idempotency is unchanged: 160 of 160 viewports byte-identical at matched scroll
positions with the null also identical, 0 reverse edges within a mount against a
mutant scoring 152, and 0 settled positions showing a plain fence.

At the 100K rung the thread mounts 22,808 elements instead of 61,760 and 2,458
highlight spans instead of 41,410, with 53 of 56 fences deferred at rest, which
is what the flag was for and is unchanged by the two fixes above.

@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: b32dc3e73d

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

if (arrived.length === 0) return;
for (const gate of arrived) {
unreached.delete(gate);
gate.warm(true);

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 Wait for grammar loading before synchronously upgrading

When a user jumps to an off-screen fence or prints before the idle grammar warm-up has completed, gate.warm(true) starts the asynchronous createHighlighter load and returns null; the subsequent flushSync calls therefore mount Streamdown's unhighlighted fallback rather than a cache hit. This makes an immediate Ctrl+End visibly show plain code and an immediate print capture uncoloured fences, contrary to the synchronous-upgrade path's purpose. Track grammar readiness or preload it before treating this call as a synchronous warm.

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.

The mechanism is described correctly: code.highlight returns null while a grammar is loading, and a swap taken then renders streamdown's fallback rather than a cache hit. Neither of the two consequences reproduces, though, so I am marking it not-useful for the defect rather than for the reading of the code.

Both halves were measured in the coldest window the instruments can reach, by adding a settle knob and turning it to zero, so the thread is driven the moment its first code block exists and long before requestIdleCallback(..., {timeout: 2000}) could have fired. The seeded thread carries five distinct fence languages, c, go, python, rust and typescript, so this is not a single-grammar fixture that could not show the race.

An immediate jump, DOM read per animation frame, separating the two ways a fence can be uncoloured:

settle 0 ms   M_base      shells on 0 frames (0 jumps)   unhighlighted fallback on 0 frames (0 jumps)
settle 0 ms   H_on        shells on 0 frames (0 jumps)   unhighlighted fallback on 0 frames (0 jumps)
settle 0 ms   Mut_nojump  shells on 6 frames (5 jumps)   unhighlighted fallback on 0 frames (0 jumps)

Mut_nojump is this branch without the jump latch, served in the same run, and it shows the defect the latch exists for. If the grammar race were reachable here it would appear in the fallback column, and it is empty.

An immediate print, taken as a real PDF rather than as a DOM read 1.5 s later, because only the PDF is the synchronous snapshot the concern is about:

settle 0 ms   H_on   deferred fences on paper: none at any of the five positions, on both papers
                     Letter raster delta against main: 0.0034% worst, same as the settled run

What I have not ruled out, and cannot: a thread whose off-screen fences use a language appearing nowhere on the first screen. There warm(true) genuinely returns null and the swap renders the fallback for the frames the grammar takes. No amount of tracking readiness fixes that, because nothing can tokenize with a grammar that is not loaded and neither a scroll event nor beforeprint can wait; the only lever is loading it earlier, which is what warmGrammars already does at idle. Worth saying plainly rather than claiming the path is airtight.

…move

The heavy-thread smoke asserts every kind of content its fixture claims to
build is really on the page, so that a thread which quietly stopped rendering
code cannot pass as a heavy thread. It asked that question in highlighted
tokens, and with off-screen fences deferred a token count is partly a
measurement of where the viewport is: the same untouched fixture renders 1,322
tokens for one cycle where it rendered 3,216 before, and the check failed.

The number was doing two jobs, and deferral separates them.

IS THIS THE HEAVY THREAD IT CLAIMS TO BE. Asked in characters of code, which the
deferred shell carries because it holds the same text node the highlighted block
holds. Measured at 12,660 for one cycle and 51,081 for four, with 2 of 5 and 15
of 20 fences deferred, and identical to the character on Chromium, Firefox and
WebKit. One cycle is seven code blocks averaging about 1,800 characters, so the
660 of slack under the floor is well short of the smallest thing that could go
missing.

HAS THIS THREAD FINISHED BUILDING ITSELF. Asked per block rather than in total:
every fence is either a deferred shell, which is a state with an attribute, or it
is highlighted. The third state, mounted and showing streamdown's own
unhighlighted fallback, lasts a frame on any build and a settled thread holds
none. That is stricter than the floor it replaces, which one block stuck on the
fallback passed as long as the others made the count up.

The census also prints fence blocks, deferred fences and code characters beside
the token count, so a reader can see how much of the thread the viewport had
reached rather than inferring it from a total that now means two things.

Proved to still bite by breaking the fixture for real rather than by argument:
stopping the python fence from growing, with highlighted tokens untouched, fails
with "rendered 19595 codeChars, short of the 24000 its 2 content cycles should
produce". The three offline cases are pinned as tests, including one asserting
that a deferred thread is NOT a failure.
@danielhanchen

Copy link
Copy Markdown
Member Author

Pushed a follow-up for the Frontend CI failure in "Browser smoke for heavy-thread interaction cost". It was genuine and caused by this PR.

harness_failures() asserts every kind in the fixture's expectedPerCycle is fully rendered, and one of those rows was a floor of 2,500 highlighted tokens per cycle. With off-screen fences deferred, a token count is partly a measurement of where the viewport is: the same untouched fixture renders 1,322 tokens for one cycle where it rendered 3,216 before, so the check fired. Reproduced locally at both sizes, byte for byte with CI, before changing anything.

I did not lower the number. That check exists to catch a fixture which is not the heavy thread it claims to measure, and a lower floor would have left it unable to tell a deferred thread from one that had quietly stopped rendering code.

I also did not have the harness force-latch everything before the census. The census is taken before the timed actions, so latching there would have left every timing in this harness measuring the non-deferred configuration while reporting itself as the shipped app. That is the same class of defect the check is for.

Instead the one number was split into the two questions it was conflating.

Is this the heavy thread it claims to be? Now asked in characters of code, which the deferred shell carries because it holds the same text node the highlighted block holds. Measured at 12,660 for one cycle and 51,081 for four, with 2 of 5 and 15 of 20 fences deferred, and identical to the character on Chromium, Firefox and WebKit. One cycle is seven code blocks averaging about 1,800 characters, so the 660 of slack under the 12,000 floor is well short of the smallest thing that could go missing.

Has this thread finished building itself? Now asked per block: every fence is either a deferred shell, which is a state with an attribute, or it is highlighted. The third state, mounted and showing streamdown's own unhighlighted fallback, lasts a frame on any build and a settled thread holds none. This is stricter than the floor it replaces, which one block stuck on the fallback passed as long as the others made the count up.

The census also now prints code chars, fence blocks, deferred fences and mounted but unhighlighted fences beside the token count, so a reader can see how much of the thread the viewport had reached instead of inferring it from a total that had come to mean two things.

Proof it still bites, taken by breaking the fixture for real rather than by argument. Stopping the python fence from growing, with highlighted tokens left untouched:

HARNESS-BROKEN chromium at 25000 chars rendered 19595 codeChars, short of the 24000
its 2 content cycles should produce; the fixture is not the heavy thread this harness
claims to measure

The fixture was restored and the exact CI configuration now passes:

code chars                          12660      51081
highlighted tokens                   1322       3646
fence blocks                            5         20
deferred fences                         2         15
mounted but unhighlighted fences        0          0

Three offline cases are pinned as tests, including one asserting that a deferred thread is not a failure, so neither half can be quietly removed again.

One thing worth recording rather than hiding: in a single three-engine run Firefox aborted with Execution context was destroyed, most likely because of a navigation before producing a measurement. It did not reproduce when Firefox ran on its own against this branch, which passed with the same 12,660 characters, and the PR gate runs Chromium only. I have treated it as a flake rather than as a finding, and it is the one thing here I have not proved either way.

Separately, and not from this PR: Backend CI -> "Repo tests (CPU)" fails with 17 ReferenceError: stripSearchImageTokens is not defined, which is broken on main and reproduces on every branch staged tonight.

@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: bfbb916b79

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

lastScrollTop.set(target, top);
// An unseen scroller has no previous position to difference, so its first event is treated as a
// jump. That costs one pass, once per scroller, and never assumes a movement was small.
if (before !== undefined && Math.abs(top - before) <= height) return;

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 Compare jumps against the percentage margin's width

In a narrow, tall viewport or nested scroller, this can skip the synchronous scan even after the scroll has crossed the observer's lookahead. IntersectionObserver resolves the vertical 100% in rootMargin against the root's width, whereas this test compares movement with its height; for example, a 600 px jump in a 300×800 scroller exceeds the actual 300 px margin but returns here because 600 <= 800. The asynchronously delivered observer can then leave a newly visible fence plain for one or more frames, so derive this threshold from the root width (or otherwise make it match the configured margin).

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.

Measured on your exact geometry, and it does not reproduce: the vertical 100% resolves against the root's HEIGHT in every engine, so the margin in a 300x800 scroller is 800 px, not 300, and 600 <= 800 correctly skips the scan because the observer had already covered it.

A synthetic scroller of known size, one 2 px target every 4 px down a long column, the furthest target reporting isIntersecting giving the margin directly. 0px 0px and 300px 0px are run alongside as controls and must come back 0 and 300, and they did on all nine rows:

chromium  root 300x800:  '100% 0px' lookahead 800 px  -> height   (the jump test assumes 800)
chromium  root 1600x600: '100% 0px' lookahead 600 px  -> height
chromium  root 600x1400: '100% 0px' lookahead 1400 px -> height
firefox   root 300x800:  '100% 0px' lookahead 800 px  -> height
firefox   root 1600x600: '100% 0px' lookahead 600 px  -> height
firefox   root 600x1400: '100% 0px' lookahead 1400 px -> height
webkit    root 300x800:  '100% 0px' lookahead 800 px  -> height
webkit    root 1600x600: '100% 0px' lookahead 600 px  -> height
webkit    root 600x1400: '100% 0px' lookahead 1400 px -> height

You are right about the spec TEXT, and it is worth writing down why that does not settle it. Intersection Observer 2.2 says percentages "are resolved relative to the width of the undilated rectangle", for all four sides. No engine does that for top and bottom, and w3c/IntersectionObserver#391 is open on exactly this discrepancy. So the spec says width, three engines say height, and the code has to match the engines.

Rather than depend on that quietly, the run carries a standing control for it. pf9462_parity.py measures this on two geometries on every parity run and fails the run if the observer's lookahead and the pre-paint band ever stop agreeing, which is what would happen if an engine moved to the spec's reading. Latest run:

rootmargin 1600x600: controls reproduced, lookahead 600 px -> height; inBand assumes 600 px  -> AGREE
rootmargin 600x1400: controls reproduced, lookahead 1400 px -> height; inBand assumes 1400 px -> AGREE

I have added the spec-versus-engine discrepancy and the issue link to the comment on REACH_MARGIN, so the next reader does not have to rediscover it. Marked not-useful for the bug as described rather than for the question, which was worth asking.

@danielhanchen

Copy link
Copy Markdown
Member Author

Round adjudicated. One genuine bug found and fixed, two that did not reproduce; each verdict was measured before it was written.

# Item Verdict Why
1 Wait for grammar loading before synchronously upgrading not reproduced mechanism read correctly, but neither consequence appears at settle 0 ms on a five-language thread
2 Scope the printed latch to currently mounted fences real, fixed one print left 0 of 56 fences deferred for the rest of the tab, on threads never printed
3 Compare jumps against the percentage margin's width not reproduced all three engines resolve the vertical 100% against HEIGHT; the 300x800 example gives 800 px, not 300

Detail and numbers are in the three inline replies. The instrument work those needed is in the branch: a settle knob on the paint, print and jump probes so the cold window can be driven at all, and scripts/pf9462_rootmargin_engines.py, which measures percentage-margin resolution per engine with self-proving controls.

Fix for #2: the module-global print flag is gone from every future fence's reached, and a print now latches exactly what is unreached at that moment, which is exactly the set about to be printed. Still one way only, and repeat prints now work rather than the first one winning.

Re-verified on the fixed bundle, everything against current main served concurrently:

painted frames showing plain code   main 0/271   this 0/271   pre-fix control 24/272 (8 of 15 jumps)
print, deferred fences on paper     none at any position, both papers
print, Letter raster delta vs main  0.0034% worst
viewport idempotency                160/160 identical, null 160/160 identical
whole-document digests              28/28 identical
reverse edges within a mount        0, against a bidirectional mutant scoring 151
settled positions showing a plain fence  0, against a no-lookahead mutant scoring 37
E5 painted frames                   0/224, against mutants at 13/224 and 185/224
deferral at rest                    53 of 56 deferred, 2,458 spans, 22,794 elements (unchanged)

The performance battery was not re-run for #2 and I do not think it should be: the change removes a term from reached that is only ever set by a print, the battery never prints, and the at-rest census on the new bundle is identical to the one the battery measured. Saying so rather than quietly reusing the old table.

Standing controls both still bite, which is the only reason the numbers above mean anything: Mut_nojump (this branch without the jump latch) and Mut_nopre (no lookahead, no pre-paint gate) are served in the same runs and come back loud every time.

CI is clean apart from Repo tests (CPU) / stripSearchImageTokens, which is broken on main and reproduces on unrelated branches.

@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: 8423bd57a8

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


/*
* AN UNSET FLAG AND AN UNRECOGNISED ONE DO NOT RESOLVE TO THE SAME MODE.
*

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 Warm visible fences before enabling deferral by default

On a cold mount where a completed fence is already in the viewport, the newly enabled default renders the shell and the pre-paint layout effect only calls setLatched(true). That swaps in <Block>, but its highlighted body starts with the raw fallback and requests tokens from a passive effect—the reason latchNow requires warming and a second synchronous flush—so the first painted frame can still show plain code. Route the initial in-band latch through an equivalent warm/flush path before making defer the shipping default.

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.

Measured, including with a mutant built to isolate exactly the path you are describing, and the specific prediction does not reproduce. Marking not-useful for the defect; the question was a good one and it found a genuinely unmeasured window, so it is worth writing down what is there.

You are right that nothing had looked at the first paint. Every published number here settles the thread for ten seconds and then jumps, so the mount was covered by argument only. I built pf9462_mountprobe.py, which records per animation frame from an init script, so sampling starts before the app mounts, and separates the two ways a fence can be uncoloured because they have different causes: shell (the gate has not latched) and fallback (the block is mounted and rendering streamdown's unhighlighted body, which is the state your item predicts).

Cold mount is a fresh context where no grammar has ever loaded; warm is an in-app navigation with grammars in hand. Three repetitions each:

                cold: shell / fallback      warm: shell / fallback
M_base            0,0,0 / 0,0,0               0,0,0 / 0,0,0
H_on              0,0,0 / 0,0,0               0,0,0 / 0,0,0
Mut_noscroll      3,3,3 / 0,0,0               2,2,2 / 0,0,0
Mut_nojump        3,3,3 / 0,0,0               2,2,2 / 0,0,0

Two things fall out.

The fallback column is empty everywhere. That is the frame your item predicts, on every arm, cold and warm, twelve mounts. The bare setLatched(true) in the pre-paint gate does not leave a raw-fallback frame on screen here.

The pre-paint gate really is not sufficient on its own, and something else is already covering it. Mut_noscroll is this branch with the scroll listener never attached, so an on-screen fence is left to the pre-paint gate and the asynchronous observer alone. It shows 3 plain frames on a cold mount where the shipped build shows 0, so the coverage is real and load-bearing rather than the fixture being too easy. But the frames it shows are SHELLS, not fallbacks: the cause is a fence that was not in band when the layout effect ran, because the thread scrolls to its newest message after mount, and the observer then delivers a frame or two late.

That scroll is what already routes the mount through the path you are asking for. The jump pass treats the first scroll event on a scroller it has not seen as a jump, deliberately, so an unseen scroller gets one full latchNow — warm, then the nested flush — rather than an assumption that the movement was small. So the initial in-band latch does go through an equivalent warm/flush path; it arrives by the scroll pass rather than by the layout effect.

I have not added warming to the pre-paint gate itself. It would be a change whose effect I cannot measure: the frame it would remove is the fallback frame, and that column is zero on every arm including the mutant that isolates the gate. I would rather leave it out than ship a claim I cannot support.

Mut_noscroll is now a standing control on the mount probe, so this cannot silently regress.

One correction to something in the thread: the bundle is byte-identical (906f13ac50935c1d) before and after the comment-reduction commit, so every measurement above and in the earlier rounds is against the shipped bytes of this branch.

Compress the prose in and around the defer-by-default change without
losing any of the measurements it records: the IntersectionObserver
percentage-versus-height discrepancy and its per-engine rows, the
print latch scoping and its span and element counts, the
engine-invariant code-character figures, and the stated limitations.
@chatgpt-codex-connector

Copy link
Copy Markdown

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

Reviewed commit: a835f505e8

ℹ️ 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 Aug 23, 2026
@danielhanchen
danielhanchen merged commit c5808de into main Aug 23, 2026
38 checks passed
@danielhanchen
danielhanchen deleted the studio-defer-fence-default branch August 23, 2026 16:33
pull Bot pushed a commit to pirica/unsloth that referenced this pull request Sep 23, 2026
…nslothai#11741)

* studiobench: compare a code fence one arm scrolled past on its text

The UI parity gate failed on backend-only pull requests (unslothai#11724, unslothai#11727,
and others on 2026-09-23) with differences like
msg15(assistant):1847269->2150610c on model_change, reasoning_toggle,
select_all_copy, settings and image_upload at r100K.

Those are not rendering differences. code-fence-defer.tsx (unslothai#9462, the
default since unslothai#9567) renders a fence as a plain shell until it first comes
within a viewport of the reader, then highlights it for the rest of the
mount. After reasoning_toggle the r100K film leaves the viewport either
near the tail (scrollTop ~50,740) or about 20,000px higher, at random per
cell on one build (78 of 172 cells across 43 recorded payloads), and the higher landing
latches the fences of msg11/13/15 until thread_reopen remounts them. A null
control whose cells all landed low measured those actions stable, so the
result's latch noise was scored as a regression. The same noise also made
a null that did see it excuse settings and model_change outright, which
hid real changes there.

scene/parity.js now reads, in the same walk that produces the unchanged
per-message digest, each fence's latch state, full digest and text digest
(whitespace dropped, since streamdown emits one span per line and the
shell one text node), plus the message with every fence replaced by a
marker. analysis/parity.fence_latch_residue treats a message as differing
only by latch when everything outside its fences matches, every fence
latched on both arms or neither matches in full, and every fence latched
on one arm only matches on its text. Nothing is excused when one arm
latched no fence anywhere, which is what a build whose fences never
upgrade looks like. A latch-only pair is a MATCH, counted and printed, so
it costs no coverage; payloads recorded before this carry no fence fields
and score exactly as before.

The selftest replays both failing runs from their recorded CI payloads,
shows they fail as recorded and pass once the latch is recorded, and
injects genuine differences (a message with no fences, a change outside a
latched message's fences, a highlighting change on a fence both arms
latched, fences that never upgrade) that must still fail.

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* studiobench: keep a fence's spacing and language in the latch comparison

The one-sided fence comparison dropped every whitespace character, so
`x = 1` and `x=1`, an indentation change or a space inside a string
read as the same fence, and it never looked at the language, so a fence
that changed language but kept its body read as latch-only too. Drop line
breaks only, the one thing that differs between the shell and the
highlighted form, keep the rest of the text as it is, and record and
compare each fence's data-language.

* studiobench: read a fence's text as lines, not a run of characters

Dropping every newline made a line break moved within the code, `a\nbc`
against `ab\nc`, read as the same fence. Read both forms as lines: the
shell's text split on newlines, and the highlighted fence one line per
element directly inside its <code>, a blank line's lone newline dropped.
Join them with one newline and drop trailing blank lines, which the shell
trims.

* studiobench: compare a fence's text as written, without prose placeholders

The time and id placeholders are there for UI prose. Applied to a one-sided
fence's source they made `"295ms"` against `"310ms"`, or two different
timestamp or id literals, read as the same code.

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
shaojun pushed a commit to shaojun/unsloth that referenced this pull request Sep 29, 2026
…nslothai#11741)

* studiobench: compare a code fence one arm scrolled past on its text

The UI parity gate failed on backend-only pull requests (unslothai#11724, unslothai#11727,
and others on 2026-09-23) with differences like
msg15(assistant):1847269->2150610c on model_change, reasoning_toggle,
select_all_copy, settings and image_upload at r100K.

Those are not rendering differences. code-fence-defer.tsx (unslothai#9462, the
default since unslothai#9567) renders a fence as a plain shell until it first comes
within a viewport of the reader, then highlights it for the rest of the
mount. After reasoning_toggle the r100K film leaves the viewport either
near the tail (scrollTop ~50,740) or about 20,000px higher, at random per
cell on one build (78 of 172 cells across 43 recorded payloads), and the higher landing
latches the fences of msg11/13/15 until thread_reopen remounts them. A null
control whose cells all landed low measured those actions stable, so the
result's latch noise was scored as a regression. The same noise also made
a null that did see it excuse settings and model_change outright, which
hid real changes there.

scene/parity.js now reads, in the same walk that produces the unchanged
per-message digest, each fence's latch state, full digest and text digest
(whitespace dropped, since streamdown emits one span per line and the
shell one text node), plus the message with every fence replaced by a
marker. analysis/parity.fence_latch_residue treats a message as differing
only by latch when everything outside its fences matches, every fence
latched on both arms or neither matches in full, and every fence latched
on one arm only matches on its text. Nothing is excused when one arm
latched no fence anywhere, which is what a build whose fences never
upgrade looks like. A latch-only pair is a MATCH, counted and printed, so
it costs no coverage; payloads recorded before this carry no fence fields
and score exactly as before.

The selftest replays both failing runs from their recorded CI payloads,
shows they fail as recorded and pass once the latch is recorded, and
injects genuine differences (a message with no fences, a change outside a
latched message's fences, a highlighting change on a fence both arms
latched, fences that never upgrade) that must still fail.

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* studiobench: keep a fence's spacing and language in the latch comparison

The one-sided fence comparison dropped every whitespace character, so
`x = 1` and `x=1`, an indentation change or a space inside a string
read as the same fence, and it never looked at the language, so a fence
that changed language but kept its body read as latch-only too. Drop line
breaks only, the one thing that differs between the shell and the
highlighted form, keep the rest of the text as it is, and record and
compare each fence's data-language.

* studiobench: read a fence's text as lines, not a run of characters

Dropping every newline made a line break moved within the code, `a\nbc`
against `ab\nc`, read as the same fence. Read both forms as lines: the
shell's text split on newlines, and the highlighted fence one line per
element directly inside its <code>, a blank line's lone newline dropped.
Join them with one newline and drop trailing blank lines, which the shell
trims.

* studiobench: compare a fence's text as written, without prose placeholders

The time and id placeholders are there for UI prose. Applied to a one-sided
fence's source they made `"295ms"` against `"310ms"`, or two different
timestamp or id literals, read as the same code.

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
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