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: stop the temporary toggle tagging a saved app-created chat (#9771)
Daniel Hanef4e26acfac0
diff --git a/studio/frontend/src/features/chat/runtime-provider.tsx b/studio/frontend/src/features/chat/runtime-provider.tsxindex 2cdb6e8ddbd..c0e09d1af62 100644--- a/studio/frontend/src/features/chat/runtime-provider.tsx+++ b/studio/frontend/src/features/chat/runtime-provider.tsx@@ -697,6 +697,7 @@ export async function ensureThreadRecord({pairId,projectId,incognito,+ neverSent,modelId,modelGgufVariant,createdAt,@@ -707,6 +708,8 @@ export async function ensureThreadRecord({projectId?: string | null;/** Snapshot from the send this row belongs to, so a retry cannot read a since-flipped toggle. */incognito?: boolean;+ /** True only from initialize(), which runs once for a thread that has never been sent to. */+ neverSent?: boolean;/** Snapshot from the send this row belongs to, so retries cannot adopt a later checkpoint. */modelId?: string;modelGgufVariant?: string | null;@@ -727,9 +730,11 @@ export async function ensureThreadRecord({? modelGgufVariant: runtimeStateAtInit.activeGgufVariant;const createdAtInit = createdAt ?? Date.now();- // Fresh assistant-ui threads are local ids. Temporary chats can skip the- // history list entirely so a storage outage cannot block the first send.- if (incognitoAtInit && isAssistantLocalThreadId(threadId)) {+ // A temporary chat skips the history list so a storage outage cannot block its first send.+ // Gated on the caller knowing the thread is new, not on its id: a `__LOCALID_` id is the+ // permanent key of every chat the app creates, so keying on the prefix tagged SAVED chats+ // incognito whenever a caller passed the open chat's id with the toggle on.+ if (incognitoAtInit && neverSent) {markThreadIncognito(threadId);return;}@@ -738,9 +743,8 @@ export async function ensureThreadRecord({if (existing) {return;}- // For non-local ids, keep the existing check first so an already-persisted- // thread is never tagged -- that's what keeps a real thread saving normally- // even if the toggle flips on while its run is still streaming.+ // After the row check, so an already-persisted thread is never tagged: that is what keeps+ // a real chat saving normally when the toggle flips on mid-stream.if (incognitoAtInit) {markThreadIncognito(threadId);return;@@ -850,6 +854,9 @@ function createStudioDbAdapter(pairId,projectId: projectIdAtInit,incognito: incognitoAtInit,+ // The one caller that can promise this: assistant-ui runs initialize() once, for+ // the id it just minted. Others hand in whatever chat is open.+ neverSent: true,modelId: modelIdAtInit,modelGgufVariant: modelGgufVariantAtInit,createdAt: createdAtInit,diff --git a/studio/frontend/tests/incognito-tagging-invariants.test.ts b/studio/frontend/tests/incognito-tagging-invariants.test.tsnew file mode 100644index 00000000000..5cfd9bfa474--- /dev/null+++ b/studio/frontend/tests/incognito-tagging-invariants.test.ts@@ -0,0 +1,78 @@+// SPDX-License-Identifier: AGPL-3.0-only+// Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0++// ensureThreadRecord's incognito shortcut used to key on a `__LOCALID_` id, which is the+// permanent primary key of every chat the app creates, not a "fresh thread" marker. With the+// toggle on, a caller passing the OPEN chat's id therefore tagged that SAVED chat incognito+// for the session, and a tagged chat stops persisting, loses its settings snapshot and loses+// its fork badge.+//+// Structural, like thread-scoped-pairing-invariants.test.ts: runtime-provider.tsx cannot be+// loaded under stubs, so what is pinned here is the shape of the decision.++import assert from "node:assert/strict";+import { readFileSync } from "node:fs";+import test from "node:test";++const provider = readFileSync(+ new URL("../src/features/chat/runtime-provider.tsx", import.meta.url),+ "utf8",+);++/** ensureThreadRecord's body, code only. */+function ensureThreadRecordBody(): string {+ const start = provider.indexOf("export async function ensureThreadRecord({");+ assert.ok(start > 0, "ensureThreadRecord not found");+ const end = provider.indexOf("const record: ThreadRecord = {", start);+ assert.ok(end > start, "end of ensureThreadRecord's guards not found");+ return provider+ .slice(start, end)+ .replace(/\/\*[\s\S]*?\*\//g, "")+ .replace(/^[ \t]*\/\/.*$/gm, "");+}++test("the incognito shortcut is gated on the thread being new, not on its id", () => {+ const body = ensureThreadRecordBody();++ assert.match(+ body,+ /if \(incognitoAtInit && neverSent\) \{/,+ "the shortcut must ask whether the thread has ever been sent to",+ );+ assert.doesNotMatch(+ body,+ /isAssistantLocalThreadId/,+ "a `__LOCALID_` prefix says nothing about whether a row exists: every chat the app " ++ "creates keeps that id after it is saved",+ );+});++test("only initialize() claims a thread has never been sent to", () => {+ // Every other caller hands in whatever chat is open, which may well be saved.+ const claims = provider.match(/neverSent: true/g) ?? [];+ assert.equal(+ claims.length,+ 1,+ `neverSent: true is claimed ${claims.length} times; only initialize() may claim it`,+ );++ const initialize = provider.slice(+ provider.indexOf("initialize(threadId: string) {"),+ provider.indexOf("adoptDefaultThreadRun"),+ );+ assert.match(initialize, /neverSent: true/);+});++test("a saved chat still reaches the existing-row check before it can be tagged", () => {+ // Without this ordering the tag is unconditional for anything the shortcut misses.+ const body = ensureThreadRecordBody();+ const shortcut = body.indexOf("incognitoAtInit && neverSent");+ const lookup = body.indexOf("await getStoredChatThread(threadId)");+ const lateTag = body.lastIndexOf("if (incognitoAtInit)");++ assert.ok(shortcut > 0 && lookup > shortcut, "the row lookup must follow the shortcut");+ assert.ok(+ lateTag > lookup,+ "every path that did not take the shortcut must consult the stored row first",+ );+});