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: title refresh follows the connection that answered the chat (#13274)

Daniel Han2a9f621fe960
diff --git a/studio/frontend/src/features/chat/components/chat-row-menu.ts b/studio/frontend/src/features/chat/components/chat-row-menu.ts
index 17e42ef15c6..27c03d7c2a9 100644
--- a/studio/frontend/src/features/chat/components/chat-row-menu.ts
+++ b/studio/frontend/src/features/chat/components/chat-row-menu.ts
@@ -41,8 +41,10 @@ import {
import { savedBranchHead } from "../utils/branch-head";
import { orderByParentChain } from "../utils/message-order";
import {
+ answeringCheckpoint,
buildTitleRefreshRequest,
heuristicChatTitle,
+ titleCheckpoint,
titleFromStream,
titleRefreshExcerpt,
} from "../utils/chat-title";
@@ -174,8 +176,10 @@ async function titleModelServing(checkpoint: string): Promise<boolean> {
}
}
-/** Uses the selected model, never the one that answered, and only while it is serving; else the
- * messages. A comparison's panes share user turns, so one is read. */
+/** Asks the connection that answered when it is external; a locally answered chat asks the selected
+ * local model, and only while it is serving, so its messages never reach a provider they were not
+ * sent to. Else the title is picked from the messages. A comparison's panes share user turns, so one
+ * is read. */
export async function regenerateChatTitle(
item: SidebarItem,
): Promise<RegenerateTitleOutcome> {
@@ -185,11 +189,10 @@ export async function regenerateChatTitle(
const threadId = getSidebarItemThreadIds(item)[0];
const liveBranch = liveThreadBranch(threadId);
const { params, modelLoading } = useChatRuntimeStore.getState();
- const checkpoint = !modelLoading ? params.checkpoint : "";
- const [startTitle, raw, serving] = await Promise.all([
+ const selected = !modelLoading ? params.checkpoint : "";
+ const [startTitle, raw] = await Promise.all([
getStoredChatThread(threadId).then((thread) => thread?.title),
listStoredChatMessages(threadId),
- checkpoint ? titleModelServing(checkpoint) : false,
]);
// The branch on screen, else the one reopening the chat shows, as the exports read it.
const storedIds = new Set(raw.map((m) => m.id));
@@ -201,6 +204,14 @@ export async function regenerateChatTitle(
: raw;
const excerpt = titleRefreshExcerpt(branch);
if (!excerpt) return "empty";
+ // Only a branch that ends in a stamped answer names a recipient: an unstamped one (stopped,
+ // interrupted) or a trailing user turn (its answer deleted) must not fall back to an older
+ // answer's provider, which never saw the later turns.
+ const lastMessage = branch.at(-1);
+ const answeredWith =
+ lastMessage?.role === "assistant" ? answeringCheckpoint(lastMessage.metadata?.custom) : "";
+ const checkpoint = titleCheckpoint(answeredWith, selected);
+ const serving = checkpoint ? await titleModelServing(checkpoint) : false;
const title =
(serving ? await titleFromModel(checkpoint, excerpt) : null) ?? heuristicChatTitle(branch);
if (!title) return "empty";
diff --git a/studio/frontend/tests/chat-title-refresh.test.ts b/studio/frontend/tests/chat-title-refresh.test.ts
index d18982e13d9..b7131ef8e83 100644
--- a/studio/frontend/tests/chat-title-refresh.test.ts
+++ b/studio/frontend/tests/chat-title-refresh.test.ts
@@ -20,8 +20,10 @@ const {
buildTitleRefreshRequest,
buildTitleRequest,
heuristicChatTitle,
+ titleCheckpoint,
titleRefreshExcerpt,
} = await import("../src/features/chat/utils/chat-title.ts");
+const { buildExternalModelId, parseExternalModelId } = await import("../src/features/chat/external-providers.ts");
type MessageRecord = import("../src/features/chat/types.ts").MessageRecord;
const LOCAL = "unsloth/gemma-4-E2B-it-GGUF";
@@ -115,7 +117,7 @@ test("a refresh is as cheap as the automatic title, with its own prompt", async
);
});
-test("a refresh asks the selected model only while it is serving, and writes the title guarded", () => {
+test("a refresh follows the connection that answered, and asks a local model only while it is serving", () => {
const source = readFileSync(
new URL("../src/features/chat/components/chat-row-menu.ts", import.meta.url),
"utf8",
@@ -131,13 +133,31 @@ test("a refresh asks the selected model only while it is serving, and writes the
source.indexOf("export async function regenerateChatTitle"),
source.indexOf("/** The sandbox"),
);
- assert.match(body, /const checkpoint = !modelLoading \? params\.checkpoint : "";/);
+ assert.match(body, /const selected = !modelLoading \? params\.checkpoint : "";/);
+ // The latest answer on the branch names the connection; never the live selection alone.
+ assert.match(body, /const lastMessage = branch\.at\(-1\);/);
+ assert.match(
+ body,
+ /lastMessage\?\.role === "assistant" \? answeringCheckpoint\(lastMessage\.metadata\?\.custom\) : "";/,
+ );
+ assert.match(body, /const checkpoint = titleCheckpoint\(answeredWith, selected\);/);
assert.match(
body,
/\(serving \? await titleFromModel\(checkpoint, excerpt\) : null\) \?\? heuristicChatTitle\(branch\)/,
);
assert.match(body, /updateChatThread\(id, \{ title \}, startTitle === undefined \? \{\} : \{ expectedTitle: startTitle \}\)/);
- assert.doesNotMatch(body, /answeringCheckpoint|titleCheckpoint/);
+});
+
+test("a locally answered chat is never sent to a selected external provider", () => {
+ const external = buildExternalModelId("prov-1", "gpt-x");
+ assert.notEqual(parseExternalModelId(external), null);
+ // Local answer, external selected: no model asked, the messages pick the title.
+ assert.equal(titleCheckpoint(LOCAL, external), "");
+ assert.equal(titleCheckpoint("", external), "");
+ // Local answer, local selected: unchanged.
+ assert.equal(titleCheckpoint(LOCAL, LOCAL), LOCAL);
+ // External answer: the connection that already has these messages.
+ assert.equal(titleCheckpoint(external, LOCAL), external);
});
const DRIFTED: MessageRecord[] = [