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: keep Hub Run settings open on a first Chat visit (#13524)

oobabooga8d450cb8cbd4
diff --git a/studio/frontend/src/components/assistant-ui/thread.tsx b/studio/frontend/src/components/assistant-ui/thread.tsx
index 8b44451ea11..01c0302eb3d 100644
--- a/studio/frontend/src/components/assistant-ui/thread.tsx
+++ b/studio/frontend/src/components/assistant-ui/thread.tsx
@@ -113,6 +113,7 @@ import {
notifyStudioDictationUnavailable,
YoutubeTranscriptPrompt,
stripSearchImageTokens,
+ ChatComposerFocusableContext,
useChatActive,
useChatAudioUpload,
useInComparePane,
@@ -3768,6 +3769,18 @@ const Composer: FC<{
const composerIdentity = threadListItemId ?? "";
composerIdentityRef.current = composerIdentity;
const chatActive = useChatActive();
+ const composerFocusable = useContext(ChatComposerFocusableContext);
+ // While a Run handoff owns the model picker the input ignores focus(), so its autofocus cannot
+ // dismiss the picker. Gating autoFocus would focus it when the gate lifts; inert would also block
+ // a press and read as Chat being covered.
+ useLayoutEffect(() => {
+ const input = inputRef.current;
+ if (composerFocusable || !input) return;
+ input.focus = () => {};
+ return () => {
+ Reflect.deleteProperty(input, "focus");
+ };
+ }, [composerFocusable, isDictating]);
const readAudioUploadDraft = useCallback(
() => aui.composer().getState().text,
[aui],
diff --git a/studio/frontend/src/features/chat/chat-page.tsx b/studio/frontend/src/features/chat/chat-page.tsx
index 53e4a6ffd6e..594fafef3ae 100644
--- a/studio/frontend/src/features/chat/chat-page.tsx
+++ b/studio/frontend/src/features/chat/chat-page.tsx
@@ -233,6 +233,7 @@ import {
} from "@/features/settings";
import {
ChatActiveContext,
+ ChatComposerFocusableContext,
ChatRuntimeProvider,
useChatActive,
} from "./runtime-provider";
@@ -2765,8 +2766,12 @@ export function ChatPage({
projectId: search.project,
}),
);
+ // A composer that mounts while a handoff's run settings are open, as on a first Chat visit, would
+ // take focus and dismiss them.
+ const [handoffOwnsPicker, setHandoffOwnsPicker] = useState(false);
const handleModelConfigRequestAdopted = useCallback(
(requestId: string) => {
+ setHandoffOwnsPicker(true);
setSettingsOpen(false);
setModelSelectorLocked(false);
setModelSelectorOpen(true);
@@ -2774,6 +2779,8 @@ export function ChatPage({
},
[setSettingsOpen],
);
+ // During render, so the composer is focusable again in the commit that closes the picker.
+ if (handoffOwnsPicker && !modelSelectorOpen) setHandoffOwnsPicker(false);
const viewBeforeCompareRef = useRef<ChatSearch | null>(null);
// Latest non-compare view, so exiting compare can restore it even when compare was opened from a
// path that does not set viewBeforeCompareRef.
@@ -4625,6 +4632,10 @@ export function ChatPage({
// Provides `active` to ChatRuntimeProvider (drops the message views while off-route, keeping the
// runtime alive) and to the compare chrome.
<ChatActiveContext.Provider value={active}>
+ {/* Before adoption sets handoffOwnsPicker, the pending request is what holds the picker open. */}
+ <ChatComposerFocusableContext.Provider
+ value={modelConfigRequest === null && !handoffOwnsPicker}
+ >
<div className="flex min-h-0 min-w-0 flex-1 basis-0 overflow-hidden bg-background">
{/* Portaled surfaces render to document.body, escaping the parent's hidden wrapper, so gate them
on `active` to keep them off other tabs. */}
@@ -5026,6 +5037,7 @@ export function ChatPage({
externalProviderType={activeExternalProviderType}
/>
</div>
+ </ChatComposerFocusableContext.Provider>
</ChatActiveContext.Provider>
);
}
diff --git a/studio/frontend/src/features/chat/index.ts b/studio/frontend/src/features/chat/index.ts
index 36367cf0b5e..701dfb19f89 100644
--- a/studio/frontend/src/features/chat/index.ts
+++ b/studio/frontend/src/features/chat/index.ts
@@ -67,6 +67,7 @@ export {
saveModelDisclaimerPreference,
} from "./sync-model-disclaimer-preference";
export {
+ ChatComposerFocusableContext,
pythonToolRunsInStudio,
useChatActive,
useInComparePane,
diff --git a/studio/frontend/src/features/chat/runtime-provider.tsx b/studio/frontend/src/features/chat/runtime-provider.tsx
index bb4746f6c70..6c15b527a36 100644
--- a/studio/frontend/src/features/chat/runtime-provider.tsx
+++ b/studio/frontend/src/features/chat/runtime-provider.tsx
@@ -4181,6 +4181,10 @@ function ThreadBackendAutosave({
// alive, so the stream survives) but its views unmount, so no portaled surface bleeds through.
export const ChatActiveContext = createContext(true);
+// False while a Run handoff (Hub, Library, shared link) owns the chat model picker, so the composer
+// cannot take focus from it.
+export const ChatComposerFocusableContext = createContext(true);
+
export function useChatActive(): boolean {
return useContext(ChatActiveContext);
}
diff --git a/studio/frontend/tests/hub-runtime-boundary.test.ts b/studio/frontend/tests/hub-runtime-boundary.test.ts
index 0f55d7b2f52..d074ea59537 100644
--- a/studio/frontend/tests/hub-runtime-boundary.test.ts
+++ b/studio/frontend/tests/hub-runtime-boundary.test.ts
@@ -329,12 +329,39 @@ test("the Run handoff opens configuration immediately and remains nonce-scoped",
);
assert.match(
chatPage,
- /setSettingsOpen\(false\);\s*setModelSelectorLocked\(false\);\s*setModelSelectorOpen\(true\);\s*clearModelConfigHandoff\(requestId\)/,
+ /setHandoffOwnsPicker\(true\);\s*setSettingsOpen\(false\);\s*setModelSelectorLocked\(false\);\s*setModelSelectorOpen\(true\);\s*clearModelConfigHandoff\(requestId\)/,
);
assert.match(
chatPage,
/open=\{active && modelConfigRequest === null && settingsOpen\}/,
);
+ // On a first Chat mount the new composer's autofocus would dismiss the handed-off settings.
+ const thread = readFileSync(
+ path.join(FRONTEND_ROOT, "src/components/assistant-ui/thread.tsx"),
+ "utf8",
+ );
+ assert.match(
+ chatPage,
+ /<ChatComposerFocusableContext\.Provider\s*value=\{modelConfigRequest === null && !handoffOwnsPicker\}/,
+ );
+ // Released when the picker closes, or the composer would never autofocus again.
+ assert.match(
+ chatPage,
+ /if \(handoffOwnsPicker && !modelSelectorOpen\)\s*\{?\s*setHandoffOwnsPicker\(false\)/,
+ );
+ assert.match(
+ thread,
+ /const composerFocusable = useContext\(\s*ChatComposerFocusableContext,?\s*\);/,
+ );
+ assert.match(
+ thread,
+ // A layout effect, so the override is in place before the input's own autofocus effect.
+ /useLayoutEffect\(\(\) => \{\s*const input = inputRef\.current;\s*if \(composerFocusable \|\| !input\)\s*\{?\s*return;\s*\}?\s*input\.focus = \(\) => \{\};\s*return \(\) => \{\s*Reflect\.deleteProperty\(input, "focus"\);\s*\};\s*\}, \[composerFocusable, isDictating\]\);/,
+ );
+ // Neither gated autoFocus, which focuses the composer when the picker closes, nor inert, which
+ // blocks a press on it and reads as Chat being covered.
+ assert.match(thread, /autoFocus=\{!disabled\}/);
+ assert.doesNotMatch(thread, /inert=\{!composerFocusable\}/);
});
test("the shared model row menu no longer offers Hub model settings", () => {
diff --git a/tests/studio/playwright_model_config.py b/tests/studio/playwright_model_config.py
index a9a7eff9bec..2df7ae220eb 100644
--- a/tests/studio/playwright_model_config.py
+++ b/tests/studio/playwright_model_config.py
@@ -1495,6 +1495,55 @@ with sync_playwright() as p:
except Exception as e:
soft_fail(f"migration idempotency check errored: {e}")
+ # ─────────────────────────────────────────────────────
+ # 6. Hub Run keeps its run settings on a page loaded at /hub (HARD).
+ # Run mounts Chat there, and the new composer's autofocus used to dismiss them.
+ # ─────────────────────────────────────────────────────
+ step("Hub Run opens run settings on a page loaded at /hub")
+ try:
+ page.goto(f"{BASE}/hub?tab=downloaded", wait_until = "domcontentloaded", timeout = 60_000)
+ # The row's own button; "More options for <repo>" also names the model.
+ row = page.get_by_role("button", name = re.compile(rf"^\S*{re.escape(MODEL_HINT)}\S*$", re.I))
+ heading = page.get_by_role("heading", name = re.compile(re.escape(MODEL_HINT), re.I))
+ row.first.wait_for(state = "visible", timeout = 60_000)
+
+ # The Hub selects its first row once the list lands, which can replace an early click.
+ def model_selected() -> bool:
+ if _count(heading):
+ return True
+ row.first.click()
+ return False
+
+ wait_until(
+ model_selected, timeout_s = 60, what = "Hub selecting the model", interval_s = 2, page = page
+ )
+ page.locator("button").filter(has_text = re.compile(r"^\s*Run\s*$")).last.click()
+ page.wait_for_url(re.compile(r"/chat(\?|$)"), timeout = 30_000)
+ settings = page.get_by_role("button", name = "Back to model list", exact = True)
+ # Sampled for a while: settings that open and are then dismissed must not pass on one sight.
+ seen = []
+ for _ in range(5):
+ page.wait_for_timeout(1000)
+ seen.append(_count(settings) > 0 and settings.first.is_visible())
+ shoot("11-hub-run-settings")
+ if all(seen):
+ info("OK Hub Run kept run settings open on a page loaded at /hub")
+ # The composer ignores focus() while the settings are open, and must stop once they close.
+ page.keyboard.press("Escape")
+ settings.first.wait_for(state = "hidden", timeout = 10_000)
+ composer = page.locator('textarea[aria-label="Message input"]').first
+ composer.evaluate("el => el.focus()")
+ if composer.evaluate("el => el === document.activeElement"):
+ info("OK composer takes focus again after the run settings close")
+ else:
+ fail("composer could not be focused after the Hub Run settings closed")
+ else:
+ fail(
+ f"Hub Run lost its run settings on a page loaded at /hub (visible per second: {seen})"
+ )
+ except Exception as e:
+ fail(f"Hub Run check errored: {e}")
+
# ─────────────────────────────────────────────────────
if page_errors:
fail(f"page errors during run: {page_errors[:3]!r}")