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: report a model reply that finished with nothing in it (#11185)
Michael Han489c3b2253cc
diff --git a/studio/frontend/src/features/chat/api/chat-adapter.ts b/studio/frontend/src/features/chat/api/chat-adapter.tsindex 348affcdc4c..e5b024f3b8c 100644--- a/studio/frontend/src/features/chat/api/chat-adapter.ts+++ b/studio/frontend/src/features/chat/api/chat-adapter.ts@@ -285,6 +285,7 @@ import {budgetImpliesTruncation,CONTINUE_INSTRUCTION,createContinuationMerger,+ hasRenderableContent,incompleteLabel,type IncompleteReason,readIncompleteInfo,@@ -7843,16 +7844,18 @@ export function createOpenAIStreamAdapter();reasoningDurationTracker.finishGroup();- const finalIncompleteReason = resolveIncompleteReason(- incompleteReason,- contextWindowExceeded,- );+ const finalContent = [+ ...buildAssistantContent(mergeContinuation(cumulativeText, { final: true })),+ ...sourceParts,+ ...documentCitationParts,+ ];+ const finalIncompleteReason =+ resolveIncompleteReason(incompleteReason, contextWindowExceeded) ??+ // A run can stop cleanly on its first token and leave nothing behind.+ // Saved as complete that is a blank bubble with no way out.+ (hasRenderableContent(finalContent) ? null : "empty");yield {- content: [- ...buildAssistantContent(mergeContinuation(cumulativeText, { final: true })),- ...sourceParts,- ...documentCitationParts,- ],+ content: finalContent,metadata: {timing: finalTiming,custom: {diff --git a/studio/frontend/src/features/chat/utils/continuation.ts b/studio/frontend/src/features/chat/utils/continuation.tsindex 10ea4956077..8550bcafcab 100644--- a/studio/frontend/src/features/chat/utils/continuation.ts+++ b/studio/frontend/src/features/chat/utils/continuation.ts@@ -6,23 +6,37 @@* and the new text is appended to the partial. *//** Why a turn ended before the model was done. `context_window` is a `length` cut the same- * request can never fit into, hence its own reason. */+ * request can never fit into, hence its own reason. `empty` is a clean finish that produced+ * nothing, which is a failure to report rather than an answer. */export type IncompleteReason =| "length"| "cancelled"| "interrupted"- | "context_window";+ | "context_window"+ | "empty";/** Metadata stamped on an assistant message that stopped early. */export type IncompleteInfo = {reason: IncompleteReason;};+/** Whether a finished turn left anything on screen, which is what separates `empty` from a+ * real answer. Non-text parts (tool calls, images, sources) always count; text has to be+ * more than whitespace. */+export function hasRenderableContent(+ content: readonly { type: string; text?: string }[],+): boolean {+ return content.some(+ (part) => part.type !== "text" || (part.text ?? "").trim().length > 0,+ );+}+const INCOMPLETE_REASONS: readonly IncompleteReason[] = ["length","cancelled","interrupted","context_window",+ "empty",];/** Below this a shared boundary is likely coincidence, and trimming would eat output. */@@ -78,6 +92,10 @@ const STATUS_REASON: Record<length: "length",interrupted: "error",context_window: "length",+ // Not `cancelled`: the bar reads that status as a real Stop and drops the stamped+ // reason, losing the explanation on reload. `context_window` maps here for the same+ // reason. Not `error` either, which would paint a red box over the bar.+ empty: "length",};/** Restore assistant-ui's status without losing the product-specific stop reason. */@@ -96,6 +114,7 @@ const INCOMPLETE_LABELS: Record<IncompleteReason, string> = {cancelled: "Response stopped",interrupted: "Response interrupted",context_window: "Response filled the model's context window",+ empty: "The model returned an empty response",};/** The user-facing explanation of why a turn stopped. */@@ -107,6 +126,8 @@ export function incompleteLabel(reason: IncompleteReason): string {* levers are a shorter conversation or a new one. */const INCOMPLETE_REMEDIES: Partial<Record<IncompleteReason, string>> = {context_window: "Start a new chat, or shorten this one, to keep going",+ // There is no partial to resume from, so the way out is another attempt.+ empty: "Try again, or pick a different model",};/** What to do about a turn that stopped early, or `null` when resuming is the answer. */diff --git a/studio/frontend/tests/chat-continuation.test.ts b/studio/frontend/tests/chat-continuation.test.tsindex 717a64f790d..810c952ccf0 100644--- a/studio/frontend/tests/chat-continuation.test.ts+++ b/studio/frontend/tests/chat-continuation.test.ts@@ -23,6 +23,7 @@ const {createAutoContinueLeaseKeeper,createAutoContinueTab,budgetImpliesTruncation,+ hasRenderableContent,incompleteLabel,incompleteRemedy,isContinuableContent,@@ -191,6 +192,70 @@ test("every stop reason has a label", () => {incompleteLabel("context_window"),"Response filled the model's context window",);+ assert.equal(+ incompleteLabel("empty"),+ "The model returned an empty response",+ );+});++test("only text has to carry weight for a turn to count as rendered", () => {+ assert.equal(hasRenderableContent([]), false);+ assert.equal(hasRenderableContent([{ type: "text", text: "" }]), false);+ assert.equal(hasRenderableContent([{ type: "text", text: " \n\t" }]), false);+ assert.equal(hasRenderableContent([{ type: "text", text: "hi" }]), true);+ // A turn that only called a tool or drew an image still answered.+ assert.equal(hasRenderableContent([{ type: "tool-call" }]), true);+ assert.equal(hasRenderableContent([{ type: "image" }]), true);+ assert.equal(+ hasRenderableContent([{ type: "text", text: "" }, { type: "source" }]),+ true,+ );+});++test("an empty turn is reported, and offers a retry rather than a resume", () => {+ // No partial means the bar's Resume button would resume nothing, so the remedy+ // replaces it. Every other reason resumes, bar the one that cannot fit.+ assert.equal(incompleteRemedy("empty"), "Try again, or pick a different model");+ assert.equal(incompleteRemedy("cancelled"), null);+ assert.equal(incompleteRemedy("length"), null);+ assert.deepEqual(+ readIncompleteInfo({ custom: { incomplete: { reason: "empty" } } }),+ { reason: "empty" },+ );+});++test("a reloaded empty turn keeps its reason instead of reading as a Stop", () => {+ // The bar drops the stamped reason whenever the status says cancelled, so mapping+ // `empty` there would restore as a bare "Cancelled": no label, no way out, and no+ // partial to make it resumable either.+ const metadata = { custom: { incomplete: { reason: "empty" as const } } };+ const status = restoredAssistantStatus(metadata);+ const stamped = readIncompleteInfo(metadata);+ assert.notEqual(status.type === "incomplete" && status.reason, "cancelled");++ // The bar's own precedence, run over the restored pair.+ const cancelled = status.type === "incomplete" && status.reason === "cancelled";+ const reason =+ cancelled && !isProviderReportedReason(stamped?.reason)+ ? "cancelled"+ : stamped?.reason;+ assert.equal(reason, "empty");+ assert.notEqual(incompleteRemedy(reason!), null);++ // A Stop during an empty run is still a Stop: the abort stamps its own reason first.+ assert.equal(resolveIncompleteReason("cancelled", false), "cancelled");+});++test("the adapter marks a finish that rendered nothing", () => {+ // The run can stop on its first token with nothing to show. Saved as complete that is a+ // blank bubble, and a queue dispatching behind it moves straight on.+ const ending = CHAT_ADAPTER.slice(+ CHAT_ADAPTER.indexOf("const finalContent = ["),+ );+ const reason = ending.slice(0, ending.indexOf("yield {"));+ assert.match(reason, /hasRenderableContent\(finalContent\) \? null : "empty"/);+ // Read off the parts that are actually yielded, not the raw stream text.+ assert.match(ending, /yield \{\s*content: finalContent,/);});test("the provider's own reason outranks every reason the client infers", () => {@@ -261,7 +326,7 @@ test("the adapter latches the backend window-exhaustion event", () => {);assert.match(adapter,- /resolveIncompleteReason\(\s*incompleteReason,\s*contextWindowExceeded,\s*\)/,+ /resolveIncompleteReason\(\s*incompleteReason,\s*contextWindowExceeded,?\s*\)/,"the latched signal no longer reaches the stamped reason",);assert.match(