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 show in folder over settings and open the logs directory (#11667)

Maheswar Kumar875f8f4a0c28
diff --git a/studio/backend/routes/settings.py b/studio/backend/routes/settings.py
index 916020adaa3..d2d551289e8 100644
--- a/studio/backend/routes/settings.py
+++ b/studio/backend/routes/settings.py
@@ -3884,9 +3884,8 @@ class DebugLogSourcesResponse(BaseModel):
file_logging_disabled: bool = False
# Where the logs actually live, so a caller does not have to guess. The
# desktop "Open logs folder" button otherwise falls back to a hard-coded
- # ~/.unsloth/studio, which is wrong whenever UNSLOTH_STUDIO_HOME or
- # STUDIO_HOME is set AND there is no readable log to take a path from.
- # Additive and optional: an older client ignores it.
+ # ~/.unsloth/studio/logs, which is wrong whenever UNSLOTH_STUDIO_HOME or
+ # STUDIO_HOME is set. Additive and optional: an older client ignores it.
log_root: Optional[str] = None
@@ -3923,14 +3922,18 @@ def get_debug_log_sources(
from utils import debug_log_sources
sources = debug_log_sources.list_sources()
- # The first candidate root is the one the walk prefers, so it is the
- # directory a user opening "the log folder" expects to land in.
+ # The first candidate root is the one the walk prefers. File logging may
+ # be disabled before logs/ is created, so reveal the existing home then.
roots = debug_log_sources.candidate_roots()
+ log_root = None
+ if roots:
+ logs_dir = roots[0] / "logs"
+ log_root = str(logs_dir if logs_dir.is_dir() else roots[0])
return DebugLogSourcesResponse(
sources = [DebugLogSourceModel(**vars(source)) for source in sources],
default_source_id = debug_log_sources.default_source_id(),
file_logging_disabled = debug_log_sources.file_logging_disabled(),
- log_root = str(roots[0]) if roots else None,
+ log_root = log_root,
)
diff --git a/studio/backend/tests/test_debug_log_routes.py b/studio/backend/tests/test_debug_log_routes.py
index e375ca95a4e..b20586f890a 100644
--- a/studio/backend/tests/test_debug_log_routes.py
+++ b/studio/backend/tests/test_debug_log_routes.py
@@ -45,6 +45,21 @@ def test_the_sources_list_names_the_running_session(client):
assert body["default_source_id"]
assert any(s["label"] == path.name and s["is_current"] for s in body["sources"])
assert any(s["realpath"] == str(path.resolve()) for s in body["sources"])
+ # the logs directory itself, not the logs/server folder the log sits in
+ assert body["log_root"] == str(path.resolve().parent.parent)
+
+
+def test_sources_open_existing_home_when_file_logging_is_disabled(client, monkeypatch):
+ monkeypatch.setenv("UNSLOTH_STUDIO_NO_FILE_LOG", "1")
+ home = Path(os.environ["UNSLOTH_STUDIO_HOME"]).resolve()
+ assert home.is_dir()
+ assert not (home / "logs").exists()
+
+ response = client.get("/api/settings/debug/logs/sources")
+ assert response.status_code == 200
+ body = response.json()
+ assert body["file_logging_disabled"] is True
+ assert body["log_root"] == str(home)
def test_the_first_read_returns_the_tail_and_a_cursor(client):
diff --git a/studio/frontend/src/components/ui/dialog.tsx b/studio/frontend/src/components/ui/dialog.tsx
index 0feac3591e9..f259d38ab38 100644
--- a/studio/frontend/src/components/ui/dialog.tsx
+++ b/studio/frontend/src/components/ui/dialog.tsx
@@ -76,6 +76,7 @@ function DialogContent({
position = "fixed",
overlayClassName,
overlayPosition,
+ onInteractOutside,
...props
}: React.ComponentProps<typeof DialogPrimitive.Content> & {
showCloseButton?: boolean;
@@ -110,6 +111,13 @@ function DialogContent({
: "absolute",
className,
)}
+ onInteractOutside={(event) => {
+ onInteractOutside?.(event);
+ // toasts render outside every dialog, so using one must not dismiss the dialog under it.
+ if ((event.target as Element | null)?.closest?.("[data-sonner-toaster]")) {
+ event.preventDefault();
+ }
+ }}
{...props}
>
{children}
diff --git a/studio/frontend/src/components/ui/sheet.tsx b/studio/frontend/src/components/ui/sheet.tsx
index a1d37ac52d7..7d66504a0c4 100644
--- a/studio/frontend/src/components/ui/sheet.tsx
+++ b/studio/frontend/src/components/ui/sheet.tsx
@@ -88,6 +88,7 @@ function SheetContent({
position = "fixed",
overlayClassName,
overlayPosition,
+ onInteractOutside,
...props
}: React.ComponentProps<typeof SheetPrimitive.Content> & {
side?: "top" | "right" | "bottom" | "left";
@@ -114,6 +115,12 @@ function SheetContent({
position === "fixed" ? VIEWPORT_TOP_EDGE : CONTAINED_TOP_EDGE,
className,
)}
+ onInteractOutside={(event) => {
+ onInteractOutside?.(event);
+ if ((event.target as Element | null)?.closest?.("[data-sonner-toaster]")) {
+ event.preventDefault();
+ }
+ }}
{...props}
>
<DialogPortalContainerContext.Provider value={contentEl}>
diff --git a/studio/frontend/src/components/ui/sonner.tsx b/studio/frontend/src/components/ui/sonner.tsx
index ca5f81cdd22..44e912434de 100644
--- a/studio/frontend/src/components/ui/sonner.tsx
+++ b/studio/frontend/src/components/ui/sonner.tsx
@@ -98,7 +98,8 @@ const Toaster = ({ ...props }: ToasterProps) => {
swipeDirections={[]}
toastOptions={{
classNames: {
- toast: "cn-toast",
+ // an open modal dialog sets pointer-events:none on body, which toasts would otherwise inherit.
+ toast: "cn-toast pointer-events-auto",
description: "!text-muted-foreground",
},
}}
diff --git a/studio/frontend/src/features/settings/api/debug-logs.ts b/studio/frontend/src/features/settings/api/debug-logs.ts
index 6d02b5d5c30..7902732fd88 100644
--- a/studio/frontend/src/features/settings/api/debug-logs.ts
+++ b/studio/frontend/src/features/settings/api/debug-logs.ts
@@ -254,27 +254,23 @@ export async function exportAllLogs(): Promise<string | null> {
}
/**
- * Reveal the directory the log picker actually reads from. Desktop only: in a
- * browser the folder is on the server, not the user's machine, and the button
- * is not rendered.
+ * Reveal the logs directory, or the Studio home before logs exist.
+ * On an older backend without `log_root`,
+ * fall back to the selected log's directory. Desktop only: in a browser the
+ * folder is on the server, not the user's machine, and the button is not rendered.
*
- * `realpath` comes from the picker, which resolves UNSLOTH_STUDIO_HOME and
- * STUDIO_HOME. `open_logs_dir` cannot: it hard-codes ~/.unsloth/studio, so on a
- * custom home it opens an unrelated directory or errors on a missing one. It
- * stays as the fallback for when no source is selected yet.
+ * `logRoot` comes from the backend, which resolves UNSLOTH_STUDIO_HOME and
+ * STUDIO_HOME. `open_logs_dir` cannot: it hard-codes ~/.unsloth/studio/logs, so
+ * on a custom home it opens an unrelated directory or errors on a missing one.
+ * It stays as the fallback for when neither path has loaded.
*/
export async function openLogsFolder(
- realpath?: string | null,
logRoot?: string | null,
+ selectedRealpath?: string | null,
): Promise<void> {
if (!isTauri) return;
const { invoke } = await import("@tauri-apps/api/core");
- // The selected log's own directory first, then the root the backend reported.
- // `open_logs_dir` is last because it hard-codes ~/.unsloth/studio and is
- // simply wrong under a custom home -- which is also the case where there may
- // be no readable log to take a path from, so neither of the first two can be
- // dropped in favour of the other.
- const directory = (realpath ? parentDirectory(realpath) : null) ?? logRoot ?? null;
+ const directory = logRoot || (selectedRealpath && parentDirectory(selectedRealpath));
if (directory) {
await invoke("open_models_dir", { path: directory });
return;
@@ -299,7 +295,7 @@ function parentDirectory(path: string): string | null {
/**
* Reveal the folder the archive was saved into. Not `openLogsFolder`, which
- * opens ~/.unsloth/studio where the logs came FROM: naming one path and opening
+ * opens the logs directory they came FROM: naming one path and opening
* another is the bug this avoids. `open_models_dir` is the app's generic "open
* this directory" command (`open_existing_dir`), misnamed rather than misused.
*/
diff --git a/studio/frontend/src/features/settings/tabs/debugging-tab.tsx b/studio/frontend/src/features/settings/tabs/debugging-tab.tsx
index dc7d1ca1e7a..43e50195f93 100644
--- a/studio/frontend/src/features/settings/tabs/debugging-tab.tsx
+++ b/studio/frontend/src/features/settings/tabs/debugging-tab.tsx
@@ -141,8 +141,7 @@ export function DebuggingTab() {
const [mode, setMode] = useState<RefreshMode>(readStoredMode);
const [buffer, setBuffer] = useState<LogBufferState>(EMPTY_BUFFER);
const [realpath, setRealpath] = useState<string | null>(null);
- // Where the backend says the logs live, for the folder button when no source
- // is selected yet, which is exactly the custom-home case that has no log.
+ // the logs directory the backend resolved, opened by the folder button
const [logRoot, setLogRoot] = useState<string | null>(null);
const [notice, setNotice] = useState<string | null>(null);
const [dropped, setDropped] = useState(false);
@@ -396,10 +395,7 @@ export function DebuggingTab() {
const revealLogsFolder = useCallback(async () => {
setRevealing(true);
try {
- // The selected log's own path, else the root the backend reported. Either
- // resolves a custom UNSLOTH_STUDIO_HOME; open_logs_dir hard-codes
- // ~/.unsloth/studio and cannot.
- await openLogsFolder(realpath, logRoot);
+ await openLogsFolder(logRoot, realpath);
} catch (error) {
toast.error(t("settings.debugging.openLogsFolderFailed"), {
description: (error as Error).message,
@@ -407,7 +403,7 @@ export function DebuggingTab() {
} finally {
setRevealing(false);
}
- }, [t, realpath, logRoot]);
+ }, [t, logRoot, realpath]);
const downloadAllLogs = useCallback(async () => {
setExporting(true);
diff --git a/studio/frontend/tests/debug-log-export.test.ts b/studio/frontend/tests/debug-log-export.test.ts
index 0266c841cf5..7ca2f0629fc 100644
--- a/studio/frontend/tests/debug-log-export.test.ts
+++ b/studio/frontend/tests/debug-log-export.test.ts
@@ -280,7 +280,7 @@ test("the browser export fetches the route and never reaches for Tauri", async (
assert.equal(world.tauriImports(), 0);
});
-test("openLogsFolder falls back to open_logs_dir when nothing is selected", async () => {
+test("openLogsFolder falls back to open_logs_dir when no logs root is reported", async () => {
const world = makeWorld({ isTauri: true });
await world.api.openLogsFolder();
@@ -289,6 +289,20 @@ test("openLogsFolder falls back to open_logs_dir when nothing is selected", asyn
]);
});
+test("openLogsFolder preserves the selected path with an older backend", async () => {
+ const unix = makeWorld({ isTauri: true });
+ await unix.api.openLogsFolder(null, "/srv/studio-home/logs/server/current.log");
+ assert.deepEqual(unix.invokes, [
+ { command: "open_models_dir", args: { path: "/srv/studio-home/logs/server" } },
+ ]);
+
+ const windows = makeWorld({ isTauri: true });
+ await windows.api.openLogsFolder(null, "C:\\studio-home\\logs\\server\\current.log");
+ assert.deepEqual(windows.invokes, [
+ { command: "open_models_dir", args: { path: "C:\\studio-home\\logs\\server" } },
+ ]);
+});
+
test("an export that works does not touch the session", async () => {
// refreshSession clears both stored tokens on ANY non-2xx, so refreshing
// before every export would let a transient 500 on /api/auth/refresh sign the
@@ -356,45 +370,13 @@ test("a failure that is not a 401 never reaches for the refresh token", async ()
assert.equal(world.invokes.length, 1);
});
-test("openLogsFolder uses the reported root when no source is selected", async () => {
- // The custom-home case with nothing readable in it: realpath stays null and
- // open_logs_dir would send the user to a hard-coded ~/.unsloth/studio.
- const world = makeWorld({ isTauri: true });
-
- await world.api.openLogsFolder(null, "/srv/studio-home");
- assert.deepEqual(world.invokes, [
- { command: "open_models_dir", args: { path: "/srv/studio-home" } },
- ]);
-});
-
-test("a selected log still beats the reported root", async () => {
- const world = makeWorld({ isTauri: true });
-
- await world.api.openLogsFolder("/srv/other/logs/server/s.log", "/srv/studio-home");
- assert.deepEqual(world.invokes, [
- { command: "open_models_dir", args: { path: "/srv/other/logs/server" } },
- ]);
-});
-
-test("openLogsFolder opens the CONFIGURED home, not the hard-coded one", async () => {
- // `open_logs_dir` resolves ~/.unsloth/studio and nothing else, while the
- // picker honours UNSLOTH_STUDIO_HOME and STUDIO_HOME. On a custom home the
- // button would open an unrelated directory, or error on one that does not
- // exist. The selected log's own realpath is what makes them agree.
- const world = makeWorld({ isTauri: true });
-
- await world.api.openLogsFolder("/srv/studio-home/logs/server/server-1.log");
- assert.deepEqual(world.invokes, [
- { command: "open_models_dir", args: { path: "/srv/studio-home/logs/server" } },
- ]);
-});
-
-test("openLogsFolder handles a Windows realpath", async () => {
+test("openLogsFolder opens the reported logs root", async () => {
+ // the backend resolves a custom studio home, which open_logs_dir cannot
const world = makeWorld({ isTauri: true });
- await world.api.openLogsFolder("C:\\studio\\logs\\server\\server-1.log");
+ await world.api.openLogsFolder("/srv/studio-home/logs", "/other/logs/server/current.log");
assert.deepEqual(world.invokes, [
- { command: "open_models_dir", args: { path: "C:\\studio\\logs\\server" } },
+ { command: "open_models_dir", args: { path: "/srv/studio-home/logs" } },
]);
});
diff --git a/studio/frontend/tests/dialog-toast-outside.test.ts b/studio/frontend/tests/dialog-toast-outside.test.ts
new file mode 100644
index 00000000000..63ac4aed972
--- /dev/null
+++ b/studio/frontend/tests/dialog-toast-outside.test.ts
@@ -0,0 +1,132 @@
+// SPDX-License-Identifier: AGPL-3.0-only
+// Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
+
+// radix reports a toast click as outside the dialog, so a modal dialog closed under its action.
+
+import assert from "node:assert/strict";
+import test from "node:test";
+import {
+ type StubElement,
+ loadWithStubs,
+ stubJsxRuntime,
+} from "./helpers/module-stubs.ts";
+
+type OutsideEvent = {
+ target: { closest: (selector: string) => unknown };
+ defaultPrevented: boolean;
+ preventDefault: () => void;
+};
+
+// depth-first search for the first element whose stub type matches
+function findByType(node: unknown, type: string): StubElement | null {
+ if (Array.isArray(node)) {
+ for (const child of node) {
+ const hit = findByType(child, type);
+ if (hit) return hit;
+ }
+ return null;
+ }
+ if (!node || typeof node !== "object") return null;
+ const element = node as StubElement;
+ if (element.type === type) return element;
+ return findByType((element.props ?? {}).children, type);
+}
+
+function outsideEvent(insideToaster: boolean): OutsideEvent {
+ return {
+ target: {
+ closest: (selector) =>
+ insideToaster && selector === "[data-sonner-toaster]" ? {} : null,
+ },
+ defaultPrevented: false,
+ preventDefault() {
+ this.defaultPrevented = true;
+ },
+ };
+}
+
+test("an interaction on a toast does not dismiss the dialog under it", () => {
+ const { DialogContent } = loadWithStubs<{
+ DialogContent: (props: {
+ onInteractOutside: (event: OutsideEvent) => void;
+ }) => StubElement;
+ }>(new URL("../src/components/ui/dialog.tsx", import.meta.url), {
+ "react/jsx-runtime": stubJsxRuntime(),
+ react: {
+ createContext: () => ({ Provider: "Provider" }),
+ useContext: () => null,
+ },
+ "radix-ui": {
+ Dialog: new Proxy({}, { get: (_, part) => `Dialog.${String(part)}` }),
+ },
+ "@/components/app-readiness": { AppPortalGate: "AppPortalGate" },
+ "@/components/ui/button": { Button: "Button" },
+ "@/lib/utils": { cn: (...classes: unknown[]) => classes.join(" ") },
+ "@hugeicons/core-free-icons": { Cancel01Icon: {} },
+ "@hugeicons/react": { HugeiconsIcon: "HugeiconsIcon" },
+ });
+
+ const seen: OutsideEvent[] = [];
+ const content = findByType(
+ DialogContent({ onInteractOutside: (event) => seen.push(event) }),
+ "Dialog.Content",
+ );
+ assert.ok(content);
+ const onInteractOutside = content.props.onInteractOutside as (
+ event: OutsideEvent,
+ ) => void;
+
+ const onToast = outsideEvent(true);
+ const elsewhere = outsideEvent(false);
+ onInteractOutside(onToast);
+ onInteractOutside(elsewhere);
+
+ assert.equal(onToast.defaultPrevented, true, "a toast click closed the dialog");
+ assert.equal(elsewhere.defaultPrevented, false, "a real outside click must still dismiss");
+ assert.deepEqual(seen, [onToast, elsewhere], "the caller's handler was dropped");
+});
+
+test("an interaction on a toast does not dismiss the sheet under it", () => {
+ const { SheetContent } = loadWithStubs<{
+ SheetContent: (props: {
+ onInteractOutside: (event: OutsideEvent) => void;
+ showCloseButton: boolean;
+ }) => StubElement;
+ }>(new URL("../src/components/ui/sheet.tsx", import.meta.url), {
+ "react/jsx-runtime": stubJsxRuntime(),
+ react: { useState: () => [null, () => {}] },
+ "radix-ui": {
+ Dialog: new Proxy({}, { get: (_, part) => `Dialog.${String(part)}` }),
+ },
+ "@/components/app-readiness": { AppPortalGate: "AppPortalGate" },
+ "@/components/ui/button": { Button: "Button" },
+ "@/components/ui/dialog": {
+ DialogPortalContainerContext: { Provider: "Provider" },
+ },
+ "@/lib/utils": { cn: (...classes: unknown[]) => classes.join(" ") },
+ "@hugeicons/core-free-icons": { Cancel01Icon: {} },
+ "@hugeicons/react": { HugeiconsIcon: "HugeiconsIcon" },
+ });
+
+ const seen: OutsideEvent[] = [];
+ const content = findByType(
+ SheetContent({
+ onInteractOutside: (event) => seen.push(event),
+ showCloseButton: false,
+ }),
+ "Dialog.Content",
+ );
+ assert.ok(content);
+ const onInteractOutside = content.props.onInteractOutside as (
+ event: OutsideEvent,
+ ) => void;
+
+ const onToast = outsideEvent(true);
+ const elsewhere = outsideEvent(false);
+ onInteractOutside(onToast);
+ onInteractOutside(elsewhere);
+
+ assert.equal(onToast.defaultPrevented, true, "a toast click closed the sheet");
+ assert.equal(elsewhere.defaultPrevented, false, "a real outside click must still dismiss");
+ assert.deepEqual(seen, [onToast, elsewhere], "the caller's handler was dropped");
+});
diff --git a/studio/src-tauri/src/commands.rs b/studio/src-tauri/src/commands.rs
index a7d853a4d24..4f597f73654 100644
--- a/studio/src-tauri/src/commands.rs
+++ b/studio/src-tauri/src/commands.rs
@@ -862,12 +862,11 @@ fn open_existing_dir(dir: &std::path::Path) -> Result<(), String> {
open_existing_dir_with(dir, |path| crate::process::open_detached(path))
}
-/// Open the Unsloth directory in the system file manager.
+/// Open the Unsloth logs directory in the system file manager.
#[tauri::command]
pub fn open_logs_dir(window: tauri::WebviewWindow) -> Result<(), String> {
crate::native_intents::ensure_main_window(&window)?;
- let home = dirs::home_dir().ok_or("Could not determine home directory")?;
- open_existing_dir(&home.join(".unsloth").join("studio"))
+ open_existing_dir(&diagnostics::logs_dir())
}
/// Open a models directory (resolved by the backend, e.g. the HF cache) in the