Skip to content

Local UI to run and train LLMs and diffusion models. Supports GGUF, MLX, Qwen3.8, DeepSeek-V4.1, MiniMax-H3, Gemma 4, FLUX and more.

Studio: bound a live Thinking block to its newest lines (#13086)

Daniel Han7d6354a421f7
diff --git a/studio/frontend/src/components/assistant-ui/reasoning-transcript.tsx b/studio/frontend/src/components/assistant-ui/reasoning-transcript.tsx
index e8be0d8e773..6a65a868309 100644
--- a/studio/frontend/src/components/assistant-ui/reasoning-transcript.tsx
+++ b/studio/frontend/src/components/assistant-ui/reasoning-transcript.tsx
@@ -44,12 +44,17 @@ import {
} from "./use-intent-aware-autoscroll";
import { cn } from "@/lib/utils";
+// Twice the live box's tallest cap (18rem in reasoning.tsx).
+const BOUNDED_TAIL_PX = 576;
+
type Props = {
initialAnchor?: ReasoningReadingAnchor;
documents: readonly string[];
messageId: string;
messageHasRenderableRenderHtmlTool: boolean;
streaming: boolean;
+ /** In the live tail box: rows grow upward in a fixed box, so no thread correction applies. */
+ bounded?: boolean;
};
const CodeFragment = memo(
@@ -329,6 +334,7 @@ export function ReasoningTranscript({
messageId,
messageHasRenderableRenderHtmlTool,
streaming,
+ bounded = false,
}: Props) {
const root = useRef<HTMLDivElement>(null);
// Over a screen away, a transcript stops listening to the shared viewport's scroll (#12025).
@@ -443,6 +449,18 @@ export function ReasoningTranscript({
fragments.forEach((fragment, i) => {
if (protectedKeys.has(fragment.key)) mounted.add(i);
});
+ if (bounded) {
+ // The box shows the end of the trace; the measured offset lags a fast-growing one.
+ let height = 0;
+ for (
+ let i = fragments.length - 1;
+ i >= 0 && height < BOUNDED_TAIL_PX;
+ i -= 1
+ ) {
+ mounted.add(i);
+ height += virtualizer.measurementsCache[i]?.size ?? 0;
+ }
+ }
return [...mounted].sort((a, b) => a - b);
},
// TanStack reports measurement corrections; the thread controller owns all scroll writes.
@@ -457,6 +475,7 @@ export function ReasoningTranscript({
// Ref measurements run before the virtualizer observes the shared viewport.
// Its offset is still zero then: applying that correction would send a reader
// back to the beginning when a live trace first crosses the threshold.
+ if (bounded) return false;
if (
virtualizer.scrollElement === null ||
item.end >= (viewport()?.scrollTop ?? 0)
@@ -498,7 +517,7 @@ export function ReasoningTranscript({
if (width && width !== rect.width) {
// Capture before reflow: a long user message above us may push the whole
// transcript offscreen at the new width before ResizeObserver runs.
- if (readingAnchor) {
+ if (readingAnchor && !bounded) {
setAnchor(readingAnchor);
setAnchoring(true);
}
@@ -587,7 +606,8 @@ export function ReasoningTranscript({
scroll.removeEventListener("scroll", schedule);
cancelAnimationFrame(frame);
};
- }, [viewport, virtualizer]);
+ // Lifting the cap moves the root without resizing it: re-measure its offset.
+ }, [viewport, virtualizer, bounded]);
useLayoutEffect(() => {
if (!anchoring || !anchor) return;
@@ -597,12 +617,12 @@ export function ReasoningTranscript({
const row = root.current?.querySelector(`[data-index="${anchor.index}"]`);
const passage =
row && reasoningTextRange(row, anchor.text, anchor.occurrence);
- if (passage)
+ if (passage && !bounded)
adjustAbove(passage.getBoundingClientRect().top - anchor.top);
setAnchoring(false);
});
return () => cancelAnimationFrame(frame);
- }, [anchor, anchoring, adjustAbove]);
+ }, [anchor, anchoring, adjustAbove, bounded]);
useEffect(() => {
const element = root.current;
diff --git a/studio/frontend/src/components/assistant-ui/reasoning.tsx b/studio/frontend/src/components/assistant-ui/reasoning.tsx
index db0bcd31879..6c26c288fee 100644
--- a/studio/frontend/src/components/assistant-ui/reasoning.tsx
+++ b/studio/frontend/src/components/assistant-ui/reasoning.tsx
@@ -30,6 +30,7 @@ import {
import {
clearReasoningRound,
foldIsActive,
+ reasoningTailCapped,
resolveReasoningGroupDuration,
resolveReasoningOpen,
setReasoningRoundOpen,
@@ -482,6 +483,7 @@ function ReasoningBody({
messageId,
messageHasRenderableRenderHtmlTool,
isStreaming,
+ bounded = false,
textClassName,
children,
}: {
@@ -489,6 +491,7 @@ function ReasoningBody({
messageId: string;
messageHasRenderableRenderHtmlTool: boolean;
isStreaming: boolean;
+ bounded?: boolean;
textClassName?: string;
children: ReactNode;
}) {
@@ -508,6 +511,7 @@ function ReasoningBody({
messageHasRenderableRenderHtmlTool
}
streaming={isStreaming}
+ bounded={bounded}
/>
) : (
children
@@ -516,6 +520,81 @@ function ReasoningBody({
);
}
+// The newest lines of a live trace in a fixed box (#11703), clipped at the top rather than an inner
+// scroller, which split the reading anchor across two containers and wrote its own scroll (#11704).
+function ReasoningTail({
+ capped,
+ onShowFull,
+ children,
+}: {
+ capped: boolean;
+ onShowFull: () => void;
+ children: ReactNode;
+}) {
+ const boxRef = useRef<HTMLDivElement>(null);
+ const [overflowing, setOverflowing] = useState(false);
+ useLayoutEffect(() => {
+ const box = boxRef.current;
+ const content = box?.firstElementChild as HTMLElement | null | undefined;
+ if (!capped || !box || !content) {
+ setOverflowing(false);
+ return;
+ }
+ const check = () => setOverflowing(content.offsetHeight > box.clientHeight);
+ const observer = new ResizeObserver(check);
+ observer.observe(content);
+ observer.observe(box);
+ check();
+ return () => observer.disconnect();
+ }, [capped]);
+ const clipped = capped && overflowing;
+ return (
+ <>
+ <div
+ ref={boxRef}
+ data-slot="reasoning-tail"
+ data-capped={capped ? "" : undefined}
+ data-overflowing={clipped ? "" : undefined}
+ onFocus={(event) => {
+ // Clipped lines cannot scroll into view: a link focused up there shows the full trace.
+ if (
+ clipped &&
+ event.target.getBoundingClientRect().top <
+ event.currentTarget.getBoundingClientRect().top
+ )
+ onShowFull();
+ }}
+ className={cn(
+ capped &&
+ "flex max-h-[min(18rem,40vh)] flex-col justify-end overflow-hidden [&>*]:shrink-0",
+ clipped &&
+ "[mask-image:linear-gradient(to_bottom,transparent,black_3rem)]",
+ )}
+ >
+ {children}
+ </div>
+ {clipped && (
+ <button
+ type="button"
+ data-slot="reasoning-show-full"
+ onClick={(event) => {
+ // The button unmounts with the cap: keep keyboard focus on this block's header.
+ if (event.currentTarget === document.activeElement)
+ boxRef.current
+ ?.closest('[data-slot="reasoning-root"]')
+ ?.querySelector<HTMLElement>('[data-slot="reasoning-trigger"]')
+ ?.focus({ preventScroll: true });
+ onShowFull();
+ }}
+ className="mt-2 cursor-pointer font-medium text-muted-foreground text-xs transition-colors hover:text-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring"
+ >
+ Show full thinking
+ </button>
+ )}
+ </>
+ );
+}
+
// With the fold preference on, the first Thinking block of a turn heads everything before the
// answer. Later reasoning groups in that span render as plain rounds inside it, following its
// open state, and the tool groups between them do the same (see tool-group.tsx).
@@ -745,6 +824,15 @@ const ReasoningGroupBlock = ({
override,
});
+ // Fold mode keeps its rounds inline: the lead's box could not hold the rounds folded after it.
+ // A closing block keeps the cap it had while open: a hand close must not re-cap a full trace.
+ const cappedNow = !foldLead && reasoningTailCapped({ visibility, override });
+ const [closingCapped, setClosingCapped] = useState(cappedNow);
+ if (isOpen && closingCapped !== cappedNow) {
+ setClosingCapped(cappedNow);
+ }
+ const capped = isOpen ? cappedNow : closingCapped;
+
// Publish the lead's open state for everything folded under it, and count the tool calls for
// its header. A layout effect, so the folded parts settle before the frame the user sees.
const roundKey = reasoningRoundKey(messageId, endIndex);
@@ -818,16 +906,22 @@ const ReasoningGroupBlock = ({
streaming={isReasoningStreaming}
ref={reasoningContentRef}
>
- <ReasoningBody
- transcript={transcript}
- messageId={messageId}
- messageHasRenderableRenderHtmlTool={
- messageHasRenderableRenderHtmlTool
- }
- isStreaming={isReasoningStreaming}
+ <ReasoningTail
+ capped={capped}
+ onShowFull={() => handleOpenChange(true)}
>
- {children}
- </ReasoningBody>
+ <ReasoningBody
+ transcript={transcript}
+ messageId={messageId}
+ messageHasRenderableRenderHtmlTool={
+ messageHasRenderableRenderHtmlTool
+ }
+ isStreaming={isReasoningStreaming}
+ bounded={capped}
+ >
+ {children}
+ </ReasoningBody>
+ </ReasoningTail>
{closesTrace && <ReasoningEndRule />}
</ReasoningContent>
</ReasoningRoot>
diff --git a/studio/frontend/src/features/chat/index.ts b/studio/frontend/src/features/chat/index.ts
index fa6f0d1cdfa..5e37c19b706 100644
--- a/studio/frontend/src/features/chat/index.ts
+++ b/studio/frontend/src/features/chat/index.ts
@@ -436,6 +436,7 @@ export { forkCountFor, subscribeForkCounts } from "./utils/fork-count-store";
export { resolveReasoningGroupDuration } from "./utils/reasoning-duration";
export {
reasoningFollowsPreference,
+ reasoningTailCapped,
resolveReasoningOpen,
startsNewReasoningRound,
} from "./utils/reasoning-visibility";
diff --git a/studio/frontend/src/features/chat/utils/reasoning-visibility.ts b/studio/frontend/src/features/chat/utils/reasoning-visibility.ts
index 33d4f708011..cbfe8eb458d 100644
--- a/studio/frontend/src/features/chat/utils/reasoning-visibility.ts
+++ b/studio/frontend/src/features/chat/utils/reasoning-visibility.ts
@@ -27,6 +27,15 @@ export function resolveReasoningOpen({
return resolveOpen(visibility, isStreaming, override);
}
+/** `auto` opens a block only for its stream, so it shows the newest lines in a bounded box
+ * instead of growing the thread (#11703). Opening it by hand, or `expanded`, shows it all. */
+export function reasoningTailCapped({
+ visibility,
+ override,
+}: Omit<ReasoningOpenStateInput, "isStreaming">): boolean {
+ return visibility === "auto" && override !== true;
+}
+
/** Whether the block sits where the setting alone would put it. */
export function reasoningFollowsPreference(
open: boolean,
diff --git a/studio/frontend/tests/reasoning-live-tail.test.ts b/studio/frontend/tests/reasoning-live-tail.test.ts
new file mode 100644
index 00000000000..3683140fb0a
--- /dev/null
+++ b/studio/frontend/tests/reasoning-live-tail.test.ts
@@ -0,0 +1,111 @@
+// SPDX-License-Identifier: AGPL-3.0-only
+// Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
+
+// The live Thinking box (#11703): bounded only while the `auto` setting holds a block open for
+// its stream, lifted by a hand open, and never an inner scroller (#11704 review).
+
+import assert from "node:assert/strict";
+import test from "node:test";
+
+import { readSrc, registerBundlerResolver } from "./helpers/kit.ts";
+
+registerBundlerResolver();
+
+const { DISPLAY_VISIBILITIES } = await import(
+ "../src/features/chat/utils/display-visibility.ts"
+);
+const { reasoningTailCapped, resolveReasoningOpen } = await import(
+ "../src/features/chat/utils/reasoning-visibility.ts"
+);
+
+const reasoning = readSrc("components/assistant-ui/reasoning.tsx");
+const transcript = readSrc("components/assistant-ui/reasoning-transcript.tsx");
+
+test("only a block the auto setting opened for its stream is bounded", () => {
+ for (const visibility of DISPLAY_VISIBILITIES) {
+ for (const override of [null, false, true]) {
+ for (const isStreaming of [false, true]) {
+ const open = resolveReasoningOpen({
+ isStreaming,
+ visibility,
+ override,
+ });
+ const capped = reasoningTailCapped({ visibility, override });
+ const shown = open && capped;
+ assert.equal(
+ shown,
+ visibility === "auto" && override === null && isStreaming,
+ `${visibility} override=${override} streaming=${isStreaming}`,
+ );
+ }
+ }
+ }
+});
+
+test("the box clips at the top instead of scrolling, and Show full is a hand open", () => {
+ const tail = reasoning.slice(
+ reasoning.indexOf("function ReasoningTail("),
+ reasoning.indexOf("// With the fold preference on"),
+ );
+ assert.match(
+ tail,
+ /flex max-h-\[[^\]]+\] flex-col justify-end overflow-hidden/,
+ );
+ assert.doesNotMatch(tail, /overflow-(y-)?(auto|scroll)|scrollTop|scrollTo\(/);
+ assert.match(
+ reasoning,
+ /const cappedNow = !foldLead && reasoningTailCapped\(\{ visibility, override \}\);/,
+ );
+ assert.match(
+ reasoning,
+ /<ReasoningTail\s+capped=\{capped\}\s+onShowFull=\{\(\) => handleOpenChange\(true\)\}/,
+ );
+ assert.match(reasoning, /bounded=\{capped\}/);
+});
+
+test("Show full hands keyboard focus to the block header before its button unmounts", () => {
+ const tail = reasoning.slice(
+ reasoning.indexOf("function ReasoningTail("),
+ reasoning.indexOf("// With the fold preference on"),
+ );
+ assert.match(
+ tail,
+ /event\.currentTarget === document\.activeElement\)[\s\S]*?closest\('\[data-slot="reasoning-root"\]'\)[\s\S]*?querySelector<HTMLElement>\('\[data-slot="reasoning-trigger"\]'\)[\s\S]*?\.focus\(\{ preventScroll: true \}\);\s*onShowFull\(\);/,
+ );
+ assert.match(tail, /focus-visible:ring-1 focus-visible:ring-ring/);
+});
+
+test("focus landing in the clipped lines lifts the cap instead of staying invisible", () => {
+ const tail = reasoning.slice(
+ reasoning.indexOf("function ReasoningTail("),
+ reasoning.indexOf("// With the fold preference on"),
+ );
+ assert.match(
+ tail,
+ /onFocus=\{\(event\) => \{[\s\S]*?clipped &&[\s\S]*?event\.target\.getBoundingClientRect\(\)\.top <\s*event\.currentTarget\.getBoundingClientRect\(\)\.top[\s\S]*?onShowFull\(\);/,
+ );
+});
+
+test("a bounded transcript corrects nothing through the thread and mounts the tail", () => {
+ assert.match(
+ transcript,
+ /shouldAdjustScrollPositionOnItemSizeChange = \(item, delta\) => \{\n(?:[ \t]*\/\/[^\n]*\n)*[ \t]*if \(bounded\) return false;/,
+ );
+ assert.match(transcript, /if \(passage && !bounded\)\s*adjustAbove/);
+ assert.match(transcript, /if \(readingAnchor && !bounded\)/);
+ assert.match(
+ transcript,
+ /if \(bounded\) \{[\s\S]*?fragments\.length - 1[\s\S]*?BOUNDED_TAIL_PX[\s\S]*?mounted\.add\(i\)/,
+ );
+ assert.match(transcript, /\}, \[viewport, virtualizer, bounded\]\);/);
+});
+
+test("a closing block keeps the cap it had while open", () => {
+ // Hand-closing a full trace re-capped it mid-collapse and skipped the transcript's corrections.
+ assert.match(
+ reasoning,
+ /if \(isOpen && closingCapped !== cappedNow\) \{\s*setClosingCapped\(cappedNow\);\s*\}\s*const capped = isOpen \? cappedNow : closingCapped;/,
+ );
+ const open = reasoning.indexOf("const isOpen = resolveReasoningOpen(");
+ assert.ok(open !== -1 && open < reasoning.indexOf("const cappedNow ="));
+});