Repository navigation
studio: collapse the reasoning pane with grid rows instead of a measured height, behind a flag - #9423
Conversation
…ight, behind a flag
The reasoning toggle forces a synchronous full-document layout. The cause is named, not
inferred: Radix's CollapsibleContentImpl runs a useLayoutEffect on every open change that
writes transitionDuration/animationName, reads getBoundingClientRect, and writes the styles
back, to publish --radix-collapsible-content-height for the animate-collapsible-* keyframes.
Blink's layout is O(total layout objects), so that one read is charged the whole thread.
Swapping the keyframes for a grid-template-rows 0fr -> 1fr transition is not on its own
enough, and this was measured rather than assumed. Radix's read is unconditional: it does not
check whether any stylesheet consumes the variable. A CSS-only arm still made two
getBoundingClientRect calls per toggle and its commit window still scaled with document size,
5.00 -> 12.40 ms across 4.2K -> 252K layout objects.
So the flag selects a local collapsible primitive as well. It keeps Radix's contract --
data-state, data-disabled, aria-expanded, aria-controls, the generated content id, hidden when
closed, children unmounted while closed -- and drops the measurement, which grid does not need
because 1fr re-resolves against the content every frame.
On the real reasoning pane, commit window, median of 5, Chromium:
4.2K objs 63K objs 252K objs gBCR per toggle
open flag off 5.70 ms 8.10 ms 14.40 ms 2
open flag on 1.20 ms 1.20 ms 1.60 ms 0
close flag off 4.00 ms 4.60 ms 5.10 ms 1
close flag on 2.00 ms 1.90 ms 2.60 ms 0
Honest limit: this removes the synchronous forced layout, not every layout. The transition
itself still relayouts the document each frame, because a pane expanding in flow moves
everything below it. Total layout time per toggle falls about 2x, it does not collapse.
Scoped to reasoning. tool-group, tool-fallback and the shared collapsible default still animate
height, because app-sidebar keys its scroll fade off animationName === "collapsible-down" |
"collapsible-up", which a transition does not fire.
Flag defaults off. Flag-off renders byte-identical markup; flag-on adds one wrapper element
inside the content, which is the min-height:0 / overflow:hidden child the grid technique
requires, so it needs screenshots as well as the parity digest.
…ation The backstop is armed in the same passive-effect flush that queues setExpanded(false), so it starts counting before React commits the 0fr class and before the browser starts the transition. Armed at exactly closeDurationMs it always beat transitionend and cut the close short, by more when a busy main thread delayed the commit.
…grid path only The height keyframes animate a height captured at toggle time, so releasing max-h-64 mid-animation cannot change what they animate. 1fr resolves against the live content every frame, so the same release grows the row in the middle of the collapse and produces the jump the retention timer exists to prevent. The transition also starts a render after the timer is armed, so an exact ANIMATION_DURATION lands inside it. The default path keeps its exact duration.
…e grid path only The lock is armed in the click handler, a commit before the grid transition starts, so an exact ANIMATION_DURATION releases the scroll container while the row is still shrinking and lets the remaining height change shift the thread. tool-group and tool-fallback share the hook but keep the height keyframes, so they keep the plain duration.
The page documented itself as a harness for scripts/probe-collapse-layout.py, which was never committed, so the experiment could not be reproduced from the repository. The driver follows the tests/studio/playwright_<name>.py convention the other smoke pages use, sweeps the four arms across two document sizes, and separates SCRIPT-FORCED layouts from animation-frame layouts: both are layout-inducing here, so a raw layout count ranks the arms backwards. It sets no budget, because the cost is hardware-dependent and a threshold would be flaky rather than informative.
…oreign tree for the flag createRoot renders concurrently, so a large fillers cell can still be mid-mount two frames into the initial render; the element count taken there reports a far smaller document than the one measured, and that count is the x axis of the experiment. It is now published from an effect after App and its filler tree have committed, and the driver re-reads it when the measurement actually starts. The flag reader also promised None under SMOKE_BASE_URL and never checked it, so a bundle built from another checkout could be labelled with this working tree's flag.
|
Codex Review: Didn't find any major issues. Nice work! 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". |
|
CI note: the red checks on this branch are all pre-existing or environmental, none of them reachable from what this PR changes. Recording the evidence so nobody re-diagnoses them.
Same script, same step, different resolved SDK. It will hit every PR that runs from now on, so it wants a pin or a call-site update in the workflow rather than a fix here.
What is green |
test_reasoning_keeps_streaming_height_cap_through_automatic_collapse pinned the literal 'isReasoningStreaming ? 0 : ANIMATION_DURATION'. The grid path has to outlast a transition that starts a render after this timer is armed, so the delay moved into a closeDelay local that is ANIMATION_DURATION on the height-keyframe path and ANIMATION_DURATION + CLOSE_FALLBACK_MARGIN_MS on the grid path. The contract is unchanged and is asserted directly: zero while streaming, the animation's length once it stops, and the default path keeps its exact duration.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: abe9dab4ce
ℹ️ 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".
|
|
||
| // Read `open` through a ref so the toggle identity does not change every time the pane opens. | ||
| const openRef = React.useRef(open); | ||
| openRef.current = open; |
There was a problem hiding this comment.
Update the toggle ref only after commits
When GRID_COLLAPSE_REASONING_ENABLED is enabled, assigning openRef.current during render can expose an uncommitted controlled state to the still-committed trigger. If React yields or abandons a concurrent render—for example while the reasoning stream changes open—a click on the currently displayed pane can negate that speculative value and call onOpenChange with the opposite of the visible state. Make the toggle callback close over the committed open value, or synchronize the ref in a layout effect, so the event handler and DOM commit cannot tear.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Correct, and confirmed against React's own guidance: refs must not be written during render, because a render can be abandoned or suspended and React does not roll the ref back, while the hook state around it is reset. The react-hooks refs lint flags updating a ref during render for exactly this reason. Fixed in 3bb3797 by closing the toggle over the committed open. Worth noting the ref was not buying what its comment claimed either: context is memoized on open, so it is rebuilt on every open change regardless of the callback's identity, which makes this a straight removal rather than a trade. A test now pins that no openRef comes back.
|
@codex review |
|
Codex Review: Didn't find any major issues. Swish! 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". |
…written in render A render can be abandoned or suspended and React does not roll a ref back when that happens, so a ref assigned in the render body can hold a value that was never committed while the trigger on screen still shows the old one; the click would then toggle away from the visible state. React's own guidance is not to write refs during render, and the react-hooks refs lint flags exactly this. The ref was not buying anything either: the context below is memoized on open, so it is rebuilt on every open change whatever the callback's identity is.
|
@codex review |
1 similar comment
|
@codex review |
|
Codex Review: Didn't find any major issues. More of your lovely PRs please. 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". |
|
Correcting my earlier CI note above, which said the red checks on this branch were all pre-existing or environmental and "none of them reachable from what this PR changes". That claim was right about the causes it named and wrong as a conclusion, and I only found out by testing it instead of resting on it.
That test pins the streaming height cap's delay as a source literal. The fix for the cap release moved the delay into a How it surfaced: rather than wait for the two So the substance of the earlier note stands, the three named causes are genuinely not this PR's, but the sentence a reviewer should trust is the staging result, not the argument. Worth recording plainly: a red shared check is not a neutral background, it is a place your own regressions can hide, and "unrelated" was not verifiable until the shared reds were repaired. |
PR #9423 replaced Radix's measured-height collapsible with a local grid primitive that never measures, and merged behind GRID_COLLAPSE_REASONING_ENABLED defaulting off. The flag has been off ever since, so nobody has been getting the improvement. This turns it on. The flag file said OFF until the A/B has run, and asked for screenshots as well as a parity digest because the change adds one wrapper element. Both have now been done on current main.
Collapsing the reasoning pane currently costs a synchronous full-document layout. This replaces the measured-height animation with a
grid-template-rowstransition, which needs no measurement. Behind a flag, defaulting off.The mechanism
This is not a smoothness change. It removes a forced synchronous layout.
Radix's
CollapsibleContentImplruns this on everyopenchange (react-collapsible 1.1.12,dist/index.mjs):It publishes the result as
--radix-collapsible-content-height, which theanimate-collapsible-down/animate-collapsible-upkeyframes consume.Two facts make that expensive:
dirtyObjects=67againsttotalObjects=195,631. The toggle dirties a handful of nodes and is charged for the whole document.So every reasoning-pane toggle in a long thread forces a full-document relayout. A
grid-template-rowstransition from0frto1franimates without ever asking for a measurement:1frresolves against the content on its own, every frame.Because point 1 means the keyframe swap is not enough on its own, this adds a local collapsible primitive (
unmeasured-collapsible.tsx) that keeps Radix's public shape (data-state,data-disabled,aria-expanded,aria-controls, generated content id,hiddenwhen closed, children unmounted while closed) and drops only the geometry read.Measurement
Confirmed at the 100K rung, standard tier, n=8, against a concurrent in-band null control, scored through the three gates in
tests/studio/studiobench/sweep/floor_table.py.reasoning_toggle.open_msjank_indexNo regressions were scored. The three gates a number has to clear to be quotable: it must exceed the per-metric floor (
max(abs(null delta), null spread)), the paired ratios must agree on sign, and the effect must exceed its own scatter.An earlier n=4 run of the same comparison agreed on both metrics and on direction, at
reasoning_toggle.open_ms-34.8% (floor 2.0%, spread 27.2%) andjank_index-25.0% (floor 12.0%, spread 23.2%). The n=8 run above is the one to quote.One number deliberately not claimed:
reasoning_toggle.close_msread -22.4%, but its paired ratios disagree on sign, so it VOIDs on gate 2 and is not a result.The floor is measured in band, concurrently with the comparison it judges, because session-to-session drift on this metric set is around 8%, which is larger than most real effects.
Scope, and why it is behind a flag
GRID_COLLAPSE_REASONING_ENABLEDinthread-feature-flags.tsdefaults tofalse. Both paths stay wired, so flipping that one constant is the only edit needed to enable it.Off by default because the change alters the rendered DOM: the grid technique needs a wrapper with
min-height: 0(or the automatic minimum size floors the row at the content height and0frnever reaches zero) andoverflow: hidden(or content paints outside the zero-height row). That wrapper is one element more than Radix renders, so this wants screenshots as well as the parity digest before it goes on.Scoped to the reasoning pane only.
tool-group.tsx,tool-fallback.tsxand the sharedcomponents/ui/collapsible.tsxdefault still animate height, for two reasons:app-sidebar.tsxkeys its scroll fade offonAnimationEndwithanimationName === "collapsible-down" | "collapsible-up", which a transition does not fire; and changing three collapsibles at once would make an A/B on the reasoning toggle unattributable.prefers-reduced-motionstill reaches this path:index.cssforcestransition-duration: 0.01ms !importanton every element, and this is a transition.Reproducing the measurement
The studiobench harness is not on
mainyet, so this runs from the harness branch:The treatment build is this branch with
GRID_COLLAPSE_REASONING_ENABLED = true; the base ismain. Both arms are paired within one session and interleaved, and the null control is captured in the same session as the comparison it scores.For the mechanism itself, rather than the end-to-end effect, this PR also commits the probe driver:
It drives
studio/frontend/smoke-collapse-layout.html, whose pane content is identical in every run so that only the surrounding document grows. It sweeps four arms and reports script-forced layouts separately from animation-frame layouts, which matters becauseheightandgrid-template-rowsare both layout-inducing, so a raw layout count ranks the arms backwards. Theradix-gridarm exists to be disproved: it takes the grid transition but keeps Radix's content, and it still forces the full-document layout, which is what shows a keyframe swap alone is not the fix.Tests
studio/frontend/tests/reasoning-grid-collapse.test.tsadds 11 tests, covering that the primitive reads no geometry at all, that the animating child carriesmin-height: 0andoverflow: hidden, that the collapse is a0frto1frtransition, that the accessible contract and unmount-while-closed behavior match Radix, that the close path unmounts ontransitionendfor the right property with a timeout backstop, that the flag is off by default, and that the height keyframes stay in use everywhere else.Frontend green on this branch:
npm run typecheckclean,npm run buildclean,npm test4237 passed / 0 failed.