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 export status polling single-flight (#10679)

Ben Younes49fc539d7273
diff --git a/studio/frontend/src/features/export/hooks/use-export-runtime-lifecycle.ts b/studio/frontend/src/features/export/hooks/use-export-runtime-lifecycle.ts
index 565c0b71cb2..786eb13a2e0 100644
--- a/studio/frontend/src/features/export/hooks/use-export-runtime-lifecycle.ts
+++ b/studio/frontend/src/features/export/hooks/use-export-runtime-lifecycle.ts
@@ -36,6 +36,7 @@ export function useExportRuntimeLifecycle(): void {
let reconnectTimer: ReturnType<typeof setTimeout> | null = null;
let logPolling = false;
let logPollTimer: ReturnType<typeof setTimeout> | null = null;
+ let statusPolling = false;
const store = useExportRuntimeStore;
@@ -151,7 +152,8 @@ export function useExportRuntimeLifecycle(): void {
};
const pollStatus = async () => {
- if (!hasAuthToken()) return;
+ if (!hasAuthToken() || statusPolling) return;
+ statusPolling = true;
try {
const status = await getExportStatus();
if (disposed) return;
@@ -162,6 +164,8 @@ export function useExportRuntimeLifecycle(): void {
}
} catch {
// ignore transient status failures
+ } finally {
+ statusPolling = false;
}
};
diff --git a/studio/frontend/tests/export-status-poll-stall-guard.test.ts b/studio/frontend/tests/export-status-poll-stall-guard.test.ts
new file mode 100644
index 00000000000..f50ab4e195f
--- /dev/null
+++ b/studio/frontend/tests/export-status-poll-stall-guard.test.ts
@@ -0,0 +1,86 @@
+// 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 { loadWithStubs } from "./helpers/module-stubs.ts";
+
+type ExportLifecycle = {
+ useExportRuntimeLifecycle: () => void;
+};
+
+const STATUS_POLL_INTERVAL_MS = 5_000;
+
+test("status polling does not stack while the previous request is stalled", async (t) => {
+ t.mock.timers.enable({ apis: ["setInterval"] });
+
+ let cleanup: (() => void) | undefined;
+ let finishStatusRequest: (() => void) | undefined;
+ let statusRequests = 0;
+ const stalledStatusRequest = new Promise<void>((resolve) => {
+ finishStatusRequest = resolve;
+ });
+ const state = {
+ isExporting: false,
+ lastSeq: 0,
+ applyBackendStatus: () => {},
+ setConnected: () => {},
+ appendLogs: () => {},
+ appendLog: () => {},
+ };
+
+ const lifecycle = loadWithStubs<ExportLifecycle>(
+ new URL(
+ "../src/features/export/hooks/use-export-runtime-lifecycle.ts",
+ import.meta.url,
+ ),
+ {
+ react: {
+ useEffect: (effect: () => (() => void) | undefined) => {
+ cleanup = effect();
+ },
+ },
+ "@/features/auth": { hasAuthToken: () => true },
+ "../api/export-api": {
+ fetchExportLogs: async () => ({ entries: [] }),
+ getExportStatus: async () => {
+ statusRequests += 1;
+ await stalledStatusRequest;
+ return {};
+ },
+ streamExportLogs: async () => {},
+ },
+ "../stores/export-runtime-store": {
+ useExportRuntimeStore: {
+ getState: () => state,
+ subscribe: () => () => {},
+ },
+ },
+ },
+ );
+
+ try {
+ lifecycle.useExportRuntimeLifecycle();
+ assert.equal(statusRequests, 1, "mount must start one status request");
+
+ t.mock.timers.tick(STATUS_POLL_INTERVAL_MS * 3);
+ assert.equal(
+ statusRequests,
+ 1,
+ "timer ticks must not start requests behind a stalled poll",
+ );
+
+ finishStatusRequest?.();
+ await new Promise<void>((resolve) => setImmediate(resolve));
+ t.mock.timers.tick(STATUS_POLL_INTERVAL_MS);
+ assert.equal(
+ statusRequests,
+ 2,
+ "polling must resume after the request settles",
+ );
+ } finally {
+ cleanup?.();
+ finishStatusRequest?.();
+ }
+});