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: Fix model pickers opening an empty On Device tab (#14985)

Nilaycc448f96527e
diff --git a/studio/frontend/src/components/resource-picker/picker-tab-policy.ts b/studio/frontend/src/components/resource-picker/picker-tab-policy.ts
index 78c529759f7..a1a3a39b56b 100644
--- a/studio/frontend/src/components/resource-picker/picker-tab-policy.ts
+++ b/studio/frontend/src/components/resource-picker/picker-tab-policy.ts
@@ -52,6 +52,7 @@ export function resolvePickerDeviceListState({
export interface PickerTabResolutionInput extends PickerDeviceInventoryState {
hasExplicitTabPreference: boolean;
+ hasCurrentTabChoice?: boolean;
lockedInferredTab: PickerTab | null;
online: boolean;
selectedTab: PickerTab;
@@ -60,12 +61,16 @@ export interface PickerTabResolutionInput extends PickerDeviceInventoryState {
export function resolvePickerTab({
hasDeviceItems,
hasExplicitTabPreference,
+ hasCurrentTabChoice = false,
isDeviceInventorySettled,
lockedInferredTab,
online,
selectedTab,
}: PickerTabResolutionInput): PickerTab {
const shouldUseHubTab = online && isDeviceInventorySettled && !hasDeviceItems;
+ if (shouldUseHubTab && !hasCurrentTabChoice) {
+ return PICKER_TAB.hub;
+ }
const inferredTab = hasExplicitTabPreference
? selectedTab
: isDeviceInventorySettled
diff --git a/studio/frontend/src/components/resource-picker/use-picker-state.ts b/studio/frontend/src/components/resource-picker/use-picker-state.ts
index 66bdfe869bf..8a12c8221a6 100644
--- a/studio/frontend/src/components/resource-picker/use-picker-state.ts
+++ b/studio/frontend/src/components/resource-picker/use-picker-state.ts
@@ -43,6 +43,7 @@ export function usePickerState({
const [lockedInferredTab, setLockedInferredTab] = useState<PickerTab | null>(
null,
);
+ const [hasCurrentTabChoice, setHasCurrentTabChoice] = useState(false);
const [hubQuery, setHubQuery] = useState("");
const [deviceQuery, setDeviceQuery] = useState("");
const [hasExplicitTabPreference, setHasExplicitTabPreference] = useState(
@@ -54,6 +55,7 @@ export function usePickerState({
const handleTabChange = useCallback(
(next: PickerTab) => {
+ setHasCurrentTabChoice(true);
setLockedInferredTab(null);
setHasExplicitTabPreference(true);
setTabState(next);
@@ -64,6 +66,7 @@ export function usePickerState({
const closePicker = useCallback(() => {
setOpen(false);
+ setHasCurrentTabChoice(false);
setLockedInferredTab(null);
}, []);
@@ -74,6 +77,7 @@ export function usePickerState({
}: PickerViewInput): PickerViewState => {
const tab = resolvePickerTab({
hasDeviceItems,
+ hasCurrentTabChoice,
hasExplicitTabPreference,
isDeviceInventorySettled,
lockedInferredTab,
@@ -115,6 +119,7 @@ export function usePickerState({
deviceQuery,
closePicker,
hasExplicitTabPreference,
+ hasCurrentTabChoice,
hubQuery,
lockedInferredTab,
online,
diff --git a/studio/frontend/src/features/model-picker/components/model-selector.tsx b/studio/frontend/src/features/model-picker/components/model-selector.tsx
index 08f61cd1ceb..9ab2b6950dc 100644
--- a/studio/frontend/src/features/model-picker/components/model-selector.tsx
+++ b/studio/frontend/src/features/model-picker/components/model-selector.tsx
@@ -67,6 +67,10 @@ import {
hasDownloadedModels,
type ModelPickerRowFilter,
} from "./model-selector/pickers";
+import {
+ type HubSection,
+ resolveHubSection,
+} from "./model-selector/hub-section";
import { PillTabs } from "./model-selector/pill-tabs";
import { loraOptionLabel } from "./model-selector/row-meta";
import { isFineTunedSource } from "./model-selector/source-tabs";
@@ -323,8 +327,6 @@ function ModelSelectorTrigger({
);
}
-type HubSection = "downloaded" | "recommended" | "connected";
-
// The user's most recently clicked Hub section, restored on every open.
const HUB_SECTION_KEY = "unsloth_model_selector_section";
// Last tab the user actually clicked, or null. Only On Device / Recommended persist.
@@ -344,7 +346,7 @@ function saveLastHubSection(section: HubSection): void {
// Ignore unavailable storage.
}
}
-// Default the Hub section: the last tab clicked; first time, On Device with downloads else Recommended.
+// Preserve saved choices until the task-scoped inventory settles.
function defaultHubSection(hasAdditionalOnDeviceModels = false): HubSection {
return (
loadLastHubSection() ??
@@ -481,9 +483,16 @@ function ModelSelectorContent({
? "connected"
: defaultHubSection(hasAdditionalOnDeviceModels),
);
- // Connected is only valid while external providers exist; fall back otherwise.
- const effectiveHubSection: HubSection =
- hubSection === "connected" && !hasExternal ? "recommended" : hubSection;
+ const [sectionChosenThisOpen, setSectionChosenThisOpen] = useState(false);
+ const [hasDeviceModels, setHasDeviceModels] = useState<boolean | null>(null);
+ // Inventory is scoped to this picker's task. A remembered On Device tab must not
+ // open empty just because another page has downloaded models.
+ const effectiveHubSection = resolveHubSection({
+ section: hubSection,
+ hasExternal,
+ hasDeviceModels,
+ sectionChosenThisOpen,
+ });
const [configTarget, setConfigTarget] = useState<ModelPickTarget | null>(
null,
@@ -499,6 +508,7 @@ function ModelSelectorContent({
if (renderedOpen !== open) {
setRenderedOpen(open);
if (!open) {
+ setSectionChosenThisOpen(false);
setConfigTarget(null);
setConfigFocus(null);
setConfigStandalone(false);
@@ -742,6 +752,7 @@ function ModelSelectorContent({
rowFilter={rowFilter}
moreModels={moreModels}
npu={npu}
+ onDeviceInventoryChange={setHasDeviceModels}
section={effectiveHubSection}
sectionToggle={
<PillTabs
@@ -753,6 +764,7 @@ function ModelSelectorContent({
value={effectiveHubSection}
onValueChange={(next) => {
const section = next as HubSection;
+ setSectionChosenThisOpen(true);
setHubSection(section);
saveLastHubSection(section);
}}
diff --git a/studio/frontend/src/features/model-picker/components/model-selector/hub-section.ts b/studio/frontend/src/features/model-picker/components/model-selector/hub-section.ts
new file mode 100644
index 00000000000..41675e712be
--- /dev/null
+++ b/studio/frontend/src/features/model-picker/components/model-selector/hub-section.ts
@@ -0,0 +1,26 @@
+// SPDX-License-Identifier: AGPL-3.0-only
+// Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
+
+export type HubSection = "downloaded" | "recommended" | "connected";
+
+export function resolveHubSection({
+ section,
+ hasExternal,
+ hasDeviceModels,
+ sectionChosenThisOpen,
+}: {
+ section: HubSection;
+ hasExternal: boolean;
+ hasDeviceModels: boolean | null;
+ sectionChosenThisOpen: boolean;
+}): HubSection {
+ if (section === "connected" && !hasExternal) return "recommended";
+ if (
+ section === "downloaded" &&
+ hasDeviceModels === false &&
+ !sectionChosenThisOpen
+ ) {
+ return "recommended";
+ }
+ return section;
+}
diff --git a/studio/frontend/src/features/model-picker/components/model-selector/pickers.tsx b/studio/frontend/src/features/model-picker/components/model-selector/pickers.tsx
index 3a9223682f8..edc4626b389 100644
--- a/studio/frontend/src/features/model-picker/components/model-selector/pickers.tsx
+++ b/studio/frontend/src/features/model-picker/components/model-selector/pickers.tsx
@@ -3136,6 +3136,7 @@ export function HubModelPicker({
deleteDisabled = false,
section = "downloaded",
sectionToggle,
+ onDeviceInventoryChange,
onEject,
onEjectAll,
task,
@@ -3173,6 +3174,7 @@ export function HubModelPicker({
/** Section shown when not searching. Search spans all sections. */
section?: "downloaded" | "recommended" | "connected";
sectionToggle?: ReactNode;
+ onDeviceInventoryChange?: (hasModels: boolean) => void;
onEject?: (modelId?: string) => void;
onEjectAll?: () => void;
/** Restrict results to a pipeline task; undefined = all tasks (the chat default). */
@@ -6246,6 +6248,28 @@ export function HubModelPicker({
// Fine-tuned models are on-device too: do not show the empty state above a non-empty Fine-tuned section.
unpinnedFineTunedRows.length === 0;
+ // Resolve against this picker's task/workflow after inventory arrives, never against a
+ // search miss or a format filter. Custom folders and fine-tuned models count too.
+ const deviceInventoryEmpty =
+ downloadedEmpty && sortedCustomFolderModels.length === 0;
+ useEffect(() => {
+ if (
+ cachedReady &&
+ !query.trim() &&
+ !debouncedQuery.trim() &&
+ formatFilter === "all"
+ ) {
+ onDeviceInventoryChange?.(!deviceInventoryEmpty);
+ }
+ }, [
+ cachedReady,
+ deviceInventoryEmpty,
+ query,
+ debouncedQuery,
+ formatFilter,
+ onDeviceInventoryChange,
+ ]);
+
// Sort dropdown inline right of the section toggle; options depend on the tab and stay visible
// while searching. Fixed width matches the Search Hub button.
const sortTriggerClassName =
diff --git a/studio/frontend/tests/model-picker-empty-device-tab.test.ts b/studio/frontend/tests/model-picker-empty-device-tab.test.ts
new file mode 100644
index 00000000000..124e0c142a3
--- /dev/null
+++ b/studio/frontend/tests/model-picker-empty-device-tab.test.ts
@@ -0,0 +1,55 @@
+// 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 { stripTypeScriptTypes } from "node:module";
+import { resolveHubSection } from "../src/features/model-picker/components/model-selector/hub-section.ts";
+import { readSrc } from "./helpers/kit.ts";
+
+const selector = readSrc("features/model-picker/components/model-selector.tsx");
+const defaultSectionSource = selector.slice(
+ selector.indexOf("function defaultHubSection("),
+ selector.indexOf("const HUB_SECTION_TABS"),
+);
+const defaultSection = new Function(
+ "loadLastHubSection",
+ "hasDownloadedModels",
+ stripTypeScriptTypes(defaultSectionSource) + "\nreturn defaultHubSection;",
+);
+
+const savedDevice = {
+ section: "downloaded" as const,
+ hasExternal: false,
+ hasDeviceModels: null,
+ sectionChosenThisOpen: false,
+};
+
+test("saved Device survives cold caches until scoped inventory settles", () => {
+ const initialSection = defaultSection(() => "downloaded", () => false)();
+ for (const hasDeviceModels of [null, true, false]) {
+ assert.equal(
+ resolveHubSection({ ...savedDevice, section: initialSection, hasDeviceModels }),
+ hasDeviceModels === false ? "recommended" : "downloaded",
+ );
+ }
+});
+
+test("a saved Device tab falls back when this task's inventory is empty", () => {
+ assert.equal(resolveHubSection(savedDevice), "downloaded");
+ assert.equal(resolveHubSection({ ...savedDevice, hasDeviceModels: false }), "recommended");
+ assert.equal(resolveHubSection({ ...savedDevice, hasDeviceModels: true }), "downloaded");
+});
+
+test("users can deliberately browse empty Device folders until the next open", () => {
+ const empty = { ...savedDevice, hasDeviceModels: false };
+ assert.equal(resolveHubSection({ ...empty, sectionChosenThisOpen: true }), "downloaded");
+ assert.equal(resolveHubSection(empty), "recommended");
+});
+
+test("empty Device inventory preserves Recommended and valid Connected selections", () => {
+ const empty = { ...savedDevice, hasDeviceModels: false };
+ assert.equal(resolveHubSection({ ...empty, section: "recommended" }), "recommended");
+ assert.equal(resolveHubSection({ ...empty, section: "connected", hasExternal: true }), "connected");
+ assert.equal(resolveHubSection({ ...empty, section: "connected" }), "recommended");
+});
diff --git a/studio/frontend/tests/picker-tab-policy.test.ts b/studio/frontend/tests/picker-tab-policy.test.ts
index eca2a354f6b..9572a16d8ae 100644
--- a/studio/frontend/tests/picker-tab-policy.test.ts
+++ b/studio/frontend/tests/picker-tab-policy.test.ts
@@ -165,3 +165,45 @@ test("preserves explicit, locked, and offline tab decisions", () => {
"device",
);
});
+
+test("an empty settled inventory overrides a saved On Device preference", () => {
+ assert.equal(
+ resolvePickerTab({
+ ...inferredBase,
+ hasDeviceItems: false,
+ isDeviceInventorySettled: true,
+ hasExplicitTabPreference: true,
+ selectedTab: "device",
+ lockedInferredTab: null,
+ }),
+ "hub",
+ );
+});
+
+test("an empty inventory replaces a stale inferred Device tab after scanning", () => {
+ assert.equal(
+ resolvePickerTab({
+ ...inferredBase,
+ hasDeviceItems: false,
+ isDeviceInventorySettled: true,
+ lockedInferredTab: "device",
+ }),
+ "hub",
+ );
+});
+
+test("a current visit's deliberate Device choice remains available when empty", () => {
+ const input = {
+ ...inferredBase,
+ hasDeviceItems: false,
+ isDeviceInventorySettled: true,
+ hasExplicitTabPreference: true,
+ hasCurrentTabChoice: true,
+ selectedTab: "device" as const,
+ lockedInferredTab: null,
+ };
+ assert.equal(resolvePickerTab(input), "device");
+ // Closing clears the current choice; reopening defaults to recommendations again.
+ assert.equal(resolvePickerTab({ ...input, hasCurrentTabChoice: false }), "hub");
+ assert.equal(resolvePickerTab({ ...input, hasDeviceItems: true }), "device");
+});