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.
Python agentaichatgptdeepseekfine-tuninggemmaimage-generationllamallmllmsopenaipythonqwenreinforcement-learningself-hostedstable-diffusiontext-to-speechttsuiunsloth
Chat: the composer dock stops searching the whole thread on every com… (#14585)
Eyera8920e38819b2
diff --git a/studio/frontend/src/components/assistant-ui/thread.tsx b/studio/frontend/src/components/assistant-ui/thread.tsxindex 04fe15fcefe..9a8c85fb439 100644--- a/studio/frontend/src/components/assistant-ui/thread.tsx+++ b/studio/frontend/src/components/assistant-ui/thread.tsx@@ -2564,6 +2564,23 @@ const GeneratedImageViewportOverlay: FC<{);};+// From the end: the footer follows every message row, and a forward walk costs O(rows) where Chromium's `:scope >` is O(1).+const childWithClass = (+ parent: Element | null | undefined,+ className: string,+): HTMLElement | null => {+ for (+ let child = parent?.lastElementChild ?? null;+ child;+ child = child.previousElementSibling+ ) {+ if (child instanceof HTMLElement && child.classList.contains(className)) {+ return child;+ }+ }+ return null;+};+const ThreadComposerDock: FC<{disabled?: boolean;threadId?: string | null;@@ -2622,17 +2639,13 @@ const ThreadComposerDock: FC<{useLayoutEffect(() => {const dock = dockRef.current;const inner = dockInnerRef.current;- const viewport = dock?.parentElement?.querySelector<HTMLElement>(- ":scope > .aui-thread-viewport",- );+ const viewport = childWithClass(dock?.parentElement, "aui-thread-viewport");if (!dock || !inner || !viewport) return;const resizeObserver = new ResizeObserver(() => apply());let observedFooter: Element | null = null;const apply = () => {// The footer is the real column box: WebKit's both-edges gutter reserves 2x the scrollbar on the right, clientWidth 1x.- const footer = viewport.querySelector(- ":scope > .aui-thread-viewport-footer",- );+ const footer = childWithClass(viewport, "aui-thread-viewport-footer");if (footer && footer !== observedFooter) {if (observedFooter) resizeObserver.unobserve(observedFooter);resizeObserver.observe(footer);diff --git a/studio/frontend/tests/composer-dock-column-lookup.test.ts b/studio/frontend/tests/composer-dock-column-lookup.test.tsnew file mode 100644index 00000000000..ecb45e6a2ef--- /dev/null+++ b/studio/frontend/tests/composer-dock-column-lookup.test.ts@@ -0,0 +1,105 @@+// SPDX-License-Identifier: AGPL-3.0-only+// Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0++import assert from "node:assert/strict";+import test from "node:test";+import { runInNewContext } from "node:vm";++import ts from "@typescript/typescript6";++import { readSrc } from "./helpers/kit.ts";++const THREAD = readSrc("components/assistant-ui/thread.tsx");++const declaration = (name: string): string => {+ const parsed = ts.createSourceFile("thread.tsx", THREAD, ts.ScriptTarget.Latest, true, ts.ScriptKind.TSX);+ for (const statement of parsed.statements) {+ if (!ts.isVariableStatement(statement)) continue;+ const found = statement.declarationList.declarations+ .find((node) => ts.isIdentifier(node.name) && node.name.text === name);+ if (found) return `const ${found.getText(parsed)};`;+ }+ throw new Error(`${name} is not declared at module scope`);+};++let classChecks = 0;++class FakeElement {+ readonly classList: { contains: (name: string) => boolean };+ lastElementChild: FakeElement | null = null;+ previousElementSibling: FakeElement | null = null;+ constructor(classes: string[], children: FakeElement[] = []) {+ this.classList = { contains: (name) => (classChecks++, classes.includes(name)) };+ children.forEach((child, i) => { child.previousElementSibling = children[i - 1] ?? null; });+ this.lastElementChild = children.at(-1) ?? null;+ }+}++const load = () => {+ const { outputText } = ts.transpileModule(+ `${declaration("childWithClass")} exports.childWithClass = childWithClass;`,+ { compilerOptions: { target: ts.ScriptTarget.ES2022 } },+ );+ const context = { exports: {} as { childWithClass: (parent: unknown, name: string) => unknown }, HTMLElement: FakeElement };+ runInNewContext(outputText, context);+ return context.exports.childWithClass;+};++test("the lookup returns the last direct child carrying the class and ignores descendants", () => {+ const childWithClass = load();+ const nested = new FakeElement(["aui-thread-viewport-footer"]);+ const earlier = new FakeElement(["aui-thread-viewport-footer"]);+ const footer = new FakeElement(["aui-thread-viewport-footer", "x"]);+ const viewport = new FakeElement(["aui-thread-viewport"], [+ new FakeElement(["row"], [nested]),+ earlier,+ footer,+ ]);+ assert.equal(childWithClass(viewport, "aui-thread-viewport-footer"), footer);+ assert.equal(childWithClass(viewport, "missing"), null);+ assert.equal(childWithClass(null, "aui-thread-viewport"), null);+ assert.equal(childWithClass(undefined, "aui-thread-viewport"), null);+});++test("a child that is not an HTML element is skipped even when it carries the class", () => {+ const childWithClass = load();+ class FakeSvgElement {+ previousElementSibling: FakeElement | null = null;+ readonly classList = { contains: (name: string) => name === "aui-thread-viewport-footer" };+ }+ const footer = new FakeElement(["aui-thread-viewport-footer"]);+ const svg = new FakeSvgElement() as unknown as FakeElement;+ svg.previousElementSibling = footer;+ const viewport = new FakeElement(["aui-thread-viewport"], [footer]);+ viewport.lastElementChild = svg;+ assert.equal(childWithClass(viewport, "aui-thread-viewport-footer"), footer);+});++test("a nested match is not mistaken for the column box", () => {+ const childWithClass = load();+ const viewport = new FakeElement(["aui-thread-viewport"], [+ new FakeElement(["row"], [new FakeElement(["aui-thread-viewport-footer"])]),+ ]);+ assert.equal(childWithClass(viewport, "aui-thread-viewport-footer"), null);+});++test("finding the footer after a long thread checks one child, not every row", () => {+ const childWithClass = load();+ const rows = Array.from({ length: 500 }, () => new FakeElement(["row"]));+ const footer = new FakeElement(["aui-thread-viewport-footer"]);+ const viewport = new FakeElement(["aui-thread-viewport"], [...rows, new FakeElement(["shrink-0"]), footer]);+ classChecks = 0;+ assert.equal(childWithClass(viewport, "aui-thread-viewport-footer"), footer);+ assert.equal(classChecks, 1);+});++test("the composer dock finds its column boxes by walking children, not by a selector over the thread", () => {+ const dock = THREAD.slice(THREAD.indexOf("const ThreadComposerDock: FC<"), THREAD.indexOf("const ThreadWelcome"));+ assert.ok(dock.includes(`childWithClass(dock?.parentElement, "aui-thread-viewport")`));+ assert.ok(dock.includes(`childWithClass(viewport, "aui-thread-viewport-footer")`));+ assert.equal(+ dock.includes(":scope >"),+ false,+ "the dock's resize observer runs on every composer height change; a :scope child selector there visits every element of the thread",+ );+});diff --git a/tests/studio/test_permission_browser_auth_wipe.py b/tests/studio/test_permission_browser_auth_wipe.pyindex 4c7f761a0d3..3ac345f8803 100644--- a/tests/studio/test_permission_browser_auth_wipe.py+++ b/tests/studio/test_permission_browser_auth_wipe.py@@ -38,7 +38,11 @@ def _wipe_auth() -> str:return match.group(0)-def _run(tmp_path: Path, busy_calls: int, tries: int = 30) -> tuple[subprocess.CompletedProcess, int]:+def _run(+ tmp_path: Path,+ busy_calls: int,+ tries: int = 30,+) -> tuple[subprocess.CompletedProcess, int]:"""Runs the script's wipe_auth with an rm that reports a busy file for its first calls."""assert BASH, "bash is required to run the wrapper's own code"shims = tmp_path / "bin"@@ -63,9 +67,7 @@ def _run(tmp_path: Path, busy_calls: int, tries: int = 30) -> tuple[subprocess.Cbody = f'set -euo pipefail\nstudio_home="{home}"\n{_wipe_auth()}wipe_auth\necho wiped\n'env = dict(os.environ, PATH = f"{shims}{os.pathsep}{os.environ['PATH']}")env["STUDIO_AUTH_WIPE_TRIES"] = str(tries)- result = subprocess.run(- [BASH, "-c", body], env = env, capture_output = True, text = True, timeout = 60- )+ result = subprocess.run([BASH, "-c", body], env = env, capture_output = True, text = True, timeout = 60)return result, int(calls.read_text())@@ -98,9 +100,9 @@ def test_the_wrapper_wipes_only_through_the_retry_before_booting():code = _code(_source())helper = _code(_wipe_auth())outside = code.replace(helper, "")- assert not re.search(r"rm -rf \"\$studio_home/auth\"", outside), (- "a bare rm of $studio_home/auth fails the lane while the previous server still holds auth.db"- )+ assert not re.search(+ r"rm -rf \"\$studio_home/auth\"", outside+ ), "a bare rm of $studio_home/auth fails the lane while the previous server still holds auth.db"calls = [m.start() for m in re.finditer(r"^wipe_auth\s*$", code, re.M)]boot = code.index("unsloth studio -H")assert calls and calls[0] < boot, "the auth dir must be wiped before the server boots"