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
Studio: do not re-send the image generate POST after a dropped connection (#13790)
Younes Beriane0737d7dc4f6b
diff --git a/studio/frontend/src/features/images/api.ts b/studio/frontend/src/features/images/api.tsindex a2b1fecf9a8..db38e6ecdb1 100644--- a/studio/frontend/src/features/images/api.ts+++ b/studio/frontend/src/features/images/api.ts@@ -435,11 +435,16 @@ export async function generateDiffusionImage(): Promise<DiffusionGenerateResponse> {let response: Response;try {- response = await authFetch("/api/inference/images/generate", {- method: "POST",- headers: { "Content-Type": "application/json" },- body: JSON.stringify(body),- });+ // No network retry: a re-sent POST re-runs the whole generation; a dropped reply surfaces below as lost.+ response = await authFetch(+ "/api/inference/images/generate",+ {+ method: "POST",+ headers: { "Content-Type": "application/json" },+ body: JSON.stringify(body),+ },+ { retryNetworkErrors: false },+ );} catch (err) {// fetch itself rejected: the connection dropped, not a backend refusal.throw new GenerateResponseLostError(diff --git a/studio/frontend/tests/image-generate-no-resend.test.ts b/studio/frontend/tests/image-generate-no-resend.test.tsnew file mode 100644index 00000000000..361e6531074--- /dev/null+++ b/studio/frontend/tests/image-generate-no-resend.test.ts@@ -0,0 +1,64 @@+// 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 AuthApi = { authFetch: (...args: unknown[]) => Promise<Response> };+type ImagesApi = {+ generateDiffusionImage: (body: unknown) => Promise<unknown>;+ GenerateResponseLostError: new (message: string) => Error;+};++function loadApis(): ImagesApi {+ const auth = loadWithStubs<AuthApi>(+ new URL("../src/features/auth/api.ts", import.meta.url),+ {+ "@/lib/api-base": {+ apiUrl: (path: string) => path,+ getApiPort: () => 1,+ isTauri: true,+ },+ "@/lib/account-transition": { accountTransitionPending: () => false },+ "./session": {+ clearAuthTokens: () => {},+ getAuthToken: () => "access-token",+ getRefreshToken: () => null,+ mustChangePassword: () => false,+ setMustChangePassword: () => {},+ storeAuthTokens: () => {},+ },+ "@tauri-apps/api/core": { invoke: async () => false },+ },+ );+ return loadWithStubs<ImagesApi>(+ new URL("../src/features/images/api.ts", import.meta.url),+ {+ "@/lib/model-lifecycle-events": { withBackgroundLoadNotice: (f: unknown) => f },+ "@/features/auth": { authFetch: auth.authFetch },+ "@/lib/format-fastapi-error": { readFastApiError: async () => "" },+ },+ { relativePassthrough: true },+ );+}++test("a dropped generate reply is surfaced as lost, not re-sent", async () => {+ const api = loadApis();+ const originalFetch = globalThis.fetch;+ let posts = 0;+ globalThis.fetch = (async () => {+ posts += 1;+ throw new TypeError("Load failed");+ }) as typeof fetch;+ try {+ await assert.rejects(+ api.generateDiffusionImage({ prompt: "x" }),+ (err: Error) => err instanceof api.GenerateResponseLostError,+ );+ assert.equal(posts, 1);+ } finally {+ globalThis.fetch = originalFetch;+ }+});